Problem

The game of “23” is a two-player game that begins with a pile of 23 toothpicks. Players ta...

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 die last toothpick loses die 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 die following rules:

•If there are more than 4 toothpicks left, then the computer should withdraw 4 - X toothpicks, where X is the number of toothpicks the human withdrew on the previous turn.

•If there are 2 to 4 toothpicks left, then the computer should withdraw enough toothpicks to leave 1.

•If there is 1 toothpick left, then the computer has to take it and loses.

When the human player enters die 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.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 3
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT