RosettaCodeData/Task/21-game/11l/21-game.11l
2023-07-01 13:44:08 -04:00

62 lines
1.7 KiB
Text
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

F select_count(game_count)
selects a random number if the game_count is less than 18. otherwise chooses the winning number
Int t
I game_count < 18
t = random:(1..3)
E
t = 21 - game_count
print(The computer chooses #..format(t))
R t
F request_count()
request user input between 1,2 and 3. It will continue till either quit(q) or one of those numbers is requested.
V t =
L
X.try
t = input(Your choice 1 to 3 :)
I Int(t) C [1, 2, 3]
R Int(t)
E
print(Out of range, try again)
X.catch
I t == q
R 0
E
print(Invalid Entry, try again)
F start()
V game_count = 0
print("Enter q to quit at any time.\nThe computer will choose first.\nRunning total is now #.".format(game_count))
V roundno = 1
L
print("\nROUND #.: \n".format(roundno))
V t = select_count(game_count)
game_count = game_count + t
print("Running total is now #.\n".format(game_count))
I game_count >= 21
print(So, commiserations, the computer has won!)
R 0
t = request_count()
I t == 0
print(OK,quitting the game)
R -1
game_count = game_count + t
print("Running total is now #.\n".format(game_count))
I game_count >= 21
print(So, congratulations, you've won!)
R 1
roundno++
V c = 0
V m = 0
L
V o = start()
I o == -1
L.break
E
c += I o == 0 {1} E 0
m += I o == 1 {1} E 0
print(Computer wins #. game, human wins #. games.format(c, m))
V t = input(Another game?(press y to continue):)
I t != y
L.break