Triple Nim
The game of Nim is played as follows: The game starts with a random number of stones in a
pile from 15 to 30. Two players (one player is the computer) alternate turns and on each turn,
the player has a choice to remove 1, 2, or 3 stones from the pile. The player who removes the
last stone is the loser.
You will write a program that simulates a version of this game with a computer opponent and
three piles instead of just one. It will work as follows – the computer will generate the number
of stones in each pile and then the user will have the first turn. During each turn, the user is
presented with the amount of stones in a pile and is asked how many stones they would like to
remove. This is done for each of the three piles on each turn.
Then the computer player takes a turn and it randomly decides how many (1-3) stones it will
remove from each pile, and it should display how many it removes from each pile. Then it
becomes the user’s turn and continues until one player has won two piles, and is then declared
the winner.
Make sure that you:
Enforce the rules regarding how many stones the user can remove from a pile (at least
1, no more than 3) – ask the user again if they enter an invalid number.
Make sure that neither the computer nor the user can remove more stones than there
are in a pile from that pile.
Be sure that your program does not continue to execute turn based code once the
game is over.