Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
47
Task/Nim-game/Action-/nim-game.action
Normal file
47
Task/Nim-game/Action-/nim-game.action
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
BYTE FUNC PlayerTurn(BYTE tokens)
|
||||
BYTE t,max
|
||||
|
||||
IF tokens<3 THEN
|
||||
max=tokens
|
||||
ELSE
|
||||
max=3
|
||||
FI
|
||||
|
||||
DO
|
||||
PrintF("How many tokens would you like to take (1-%B)? ",max)
|
||||
t=InputB()
|
||||
UNTIL t>=1 AND t<=max
|
||||
OD
|
||||
PrintF("Player takes %B tokens.%E",t)
|
||||
t=tokens-t
|
||||
IF t=0 THEN
|
||||
PrintE("Player wins.")
|
||||
FI
|
||||
RETURN (t)
|
||||
|
||||
BYTE FUNC ComputerTurn(BYTE tokens)
|
||||
BYTE t
|
||||
|
||||
t=tokens MOD 4
|
||||
PrintF("Computer takes %B tokens.%E",t)
|
||||
t=tokens-t
|
||||
IF t=0 THEN
|
||||
PrintE("Computer wins.")
|
||||
FI
|
||||
RETURN (t)
|
||||
|
||||
PROC Main()
|
||||
BYTE tokens=[12],t
|
||||
BYTE player=[1]
|
||||
|
||||
WHILE tokens>0
|
||||
DO
|
||||
PrintF("Available tokens: %B%E",tokens)
|
||||
IF player THEN
|
||||
tokens=PlayerTurn(tokens)
|
||||
ELSE
|
||||
tokens=ComputerTurn(tokens)
|
||||
FI
|
||||
player=1-player
|
||||
OD
|
||||
RETURN
|
||||
Loading…
Add table
Add a link
Reference in a new issue