Nim game

You are encouraged to solve this task according to the task description, using any language you may know.
Nim is a simple game where the second player ─── if they know the trick ─── will always win.



The game has only 3 rules:

   start with   12   tokens
   each player takes   1,  2,  or  3   tokens in turn
  the player who takes the last token wins.


To win every time,   the second player simply takes 4 minus the number the first player took.   So if the first player takes 1,   the second takes 3 ─── if the first player takes 2,   the second should take 2 ─── and if the first player takes 3,   the second player will take 1.



Task

Design a simple Nim game where the human player goes first, and the computer always wins. The game should enforce the rules.




 
$constant maxtokens = 12
$constant machine = 0
$constant human = 1
$constant false = 0
$constant true = 0FFFFH
 
procedure welcome
  print "Welcome to the Game of Nim."
  print "We begin with";maxtokens;" tokens. On each turn, a player"
  print "may take between 1 and 3 tokens. The player who takes the"
  print "last token wins."
  print
end
 
procedure show(n = integer)
  var i = integer
  print "Available tokens:";n;"  ";
  rem - provide a visual display
  for i =  1 to n
    print "o ";    
  next i
  print
end
 
function getnum(lowlim, toplim = integer) = integer
  var ok, n = integer
  repeat
    begin
      input "You take:";n
      if n < lowlim or n > toplim then
        begin
          print "Must take between";lowlim;" and";toplim
          print "Try again."
          ok = false
        end
      else
        ok = true
    end
  until ok
end = n
 
function play(player, tokens, taken = integer) = integer
  if player = human then
      taken = getnum(1,3)
  else
      taken = 4 - taken
end = taken
 
procedure report(player = integer)
  if player = human then
    print "You took the last one. You win. Congratulations!"
  else
    print "I took the last one, so I win. Sorry about that."
end
 
var player, tokens, taken  = integer
 
welcome
tokens = maxtokens
taken = 0
player = human
print "You go first."
repeat
  begin
    show tokens
    taken = play(player, tokens, taken)
    tokens = tokens - taken
    if player = machine then print "I took:";taken
    if tokens > 0 then player = 1 - player
  end
until tokens = 0
report player
print "Thanks for playing!"
 
end 