Question: This is C++ programming: The game of 23 is a two-player game that begins with a pile of 23 toothpicks. Players take turns, withdrawing either
This is C++ programming:
The game of "23" is a two-player game that begins with a pile of 23 toothpicks. Players take turns, withdrawing either 1, 2, or 3 toothpicks at a time. The player to withdraw the last toothpick loses the game. Write a human vs. computer program that plays "23". The human should always move first.
When it is the computer's turn, it should play according to the following rules:
1. If there are more than 4 toothpicks left, then the computer should with-draw 4 - X toothpicks, where X is the number of toothpicks the human withdrew on the previous turn.
2. If there are 2 to 4 toothpicks left, then the computer should withdraw enough toothpicks to leave 1.
3. If there is 1 toothpick left, then the computer has to take it and loses.
When the human player enters the number of toothpicks to withdraw, the program should perform input validation. Make sure that the entered number is between 1 and 3 and that the player is not trying to withdraw more toothpicks than exist in the pile.
ADDITIONAL REQUIREMENT:
1. If the user picks illegal number of sticks, the program will prompt the user to pick again.
2. At the end of each game, the program will prompt user to choose if the user wants another game.
SAMPLE RUN:
Let's play a game of "23"!
Enter the number of sticks you wish to pick: 2
You picked 2 stick. 21 left
Computer picked 2 sticks. 19 left
Your turn. Enter the number of sticks you wish to pick: 3
You picked 3 stick. 16 left
Computer picked 1 sticks. 15 left
Your turn. Enter the number of sticks you wish to pick: 4
Wrong number of sticks. Please pick 1, 2, or 3 sticks: 0
Wrong number of sticks. Please pick 1, 2, or 3 sticks: 2
You picked 2 stick. 13 left
Computer picked 2 sticks. 11 left
Your turn. Enter the number of sticks you wish to pick: 3
You picked 3 stick. 8 left
Computer picked 1 sticks. 7 left
Your turn. Enter the number of sticks you wish to pick: 2
You picked 2 stick. 5 left
Computer picked 2 sticks. 3 left
Your turn. Enter the number of sticks you wish to pick: 1
You picked 1 stick. 2 left
Computer picked 1 sticks. 1 left
Your turn. Enter the number of sticks you wish to pick: 1
You picked 1 stick. 0 left
You picked the last stick.
Sorry, the computer beat you!
Do you want to play another game? : y
Lets play a game of "23"!
Enter the number of sticks you wish to pick: 1
.......
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
