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.




To run:
Start up.
Play the game of Nim.
Write "The computer wins! Press esc to exit." on the console.
Wait for the escape key.
Shut down.
 
A piece is a number.
 
To play the game of Nim:
Put 12 into a piece count.
Loop.
If the piece count is 0, exit.
Write "There are " then the piece count then " pieces remaining." on the console.
Ask the player to take some pieces.
Subtract the pieces from the piece count.
Ask the computer to take some other pieces given the pieces.
Subtract the other pieces from the piece count.
Repeat.
 
To ask the player to take some pieces:
Write "Would you like to take 1, 2, or 3 pieces? " on the console without advancing.
Read a count from the console.
If the count is not between 1 and 3, repeat.
Format the count and "piece" or "pieces" into a string.
Write "You took " then the string then "." on the console.
Put the count into the pieces.
 
To ask the computer to take some pieces given some other pieces:
Put 4 minus the other pieces into a count.
Format the count and "piece" or "pieces" into a string.
Write "The computer took " then the string then "." on the console.
Put the count into the pieces.