Nim Game

Run some MiniScript code right in your browser!

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."

Help & Information