31 lines
618 B
Text
31 lines
618 B
Text
!YS-v0
|
|
|
|
players =: qw(A B):cycle.drop(rand-int(2))
|
|
|
|
defn main():
|
|
say: |
|
|
--------------------
|
|
Welcome to 21 Game
|
|
--------------------
|
|
|
|
loop turn 0 total 0:
|
|
say: "Running total: $total"
|
|
say: "Player $(players.$turn)'s turn"
|
|
total +=: get-num(total)
|
|
say:
|
|
when total == 21:
|
|
say: |
|
|
Running total is 21. Player $(players.$turn) won!
|
|
exit: 0
|
|
recur: turn.++ total
|
|
|
|
defn get-num(total):
|
|
print: 'Enter a number (1,2,3): '
|
|
val =: read-line()
|
|
condf val:
|
|
nil?: exit()
|
|
\(/[1-3]/):
|
|
if (total + val:N) > 21:
|
|
recur()
|
|
val
|
|
else: recur()
|