32 lines
664 B
Plaintext
32 lines
664 B
Plaintext
PLAYER = 1
|
|
COMP = 0
|
|
|
|
sum = 0
|
|
total = 0
|
|
turn = int(rand + 0.5)
|
|
dim precomp = {1, 1, 3, 2}
|
|
|
|
while sum < 21
|
|
turn = 1 - turn
|
|
print "The sum is "; sum
|
|
if turn = PLAYER then
|
|
print "It is your turn."
|
|
while total < 1 or total > 3 or total + sum > 21
|
|
input "How many would you like to total? ", total
|
|
end while
|
|
else
|
|
print "It is the computer's turn."
|
|
total = precomp[sum mod 4]
|
|
print "The computer totals ", total, "."
|
|
end if
|
|
print
|
|
sum += total
|
|
total = 0
|
|
end while
|
|
|
|
if turn = PLAYER then
|
|
print "Congratulations. You win."
|
|
else
|
|
print "Bad luck. The computer wins."
|
|
end if
|