Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
40
Task/Nim-game/MiniScript/nim-game.mini
Normal file
40
Task/Nim-game/MiniScript/nim-game.mini
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
tokens = 12
|
||||
|
||||
print "Nim Game"
|
||||
print "Starting with " + tokens + " tokens."
|
||||
print
|
||||
|
||||
printRemaining = function()
|
||||
print tokens + " tokens remaining."
|
||||
print
|
||||
end function
|
||||
|
||||
playerTurn = function(take)
|
||||
take = floor(val(take))
|
||||
if take < 1 or take > 3 then
|
||||
print "Take must be between 1 and 3."
|
||||
return false
|
||||
end if
|
||||
|
||||
globals.tokens = tokens - take
|
||||
|
||||
print "Player takes " + take + " tokens."
|
||||
printRemaining
|
||||
return true
|
||||
end function
|
||||
|
||||
computerTurn = function()
|
||||
take = tokens % 4
|
||||
globals.tokens = tokens - take
|
||||
|
||||
print "Computer takes " + take + " tokens."
|
||||
printRemaining
|
||||
end function
|
||||
|
||||
while tokens > 0
|
||||
if playerTurn(input("How many tokens would you like to take? ")) then
|
||||
computerTurn
|
||||
end if
|
||||
end while
|
||||
|
||||
print "Computer wins."
|
||||
Loading…
Add table
Add a link
Reference in a new issue