Question: Has to build and run in Java please!! Game of 23 The game of 23 is a two-player game that begins with a pile of

Has to build and run in Java please!!

Game of 23

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 the Game of 23. The human should always move first. when it is the computer's turn, it should play according to the 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 the number of toothpicks to withdraw, the program should perform input validation (Hint: this would be a good task to process in a method). 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.

Sample Output:

There are 23 toothpicks in a pile.

Please enter the number of toothpicks that you would like to pickup (1, 2, or 3): 5 Incorrect input. Please try again.

Please enter the number of toothpicks that you would like to pickup (1, 2, or 3): 3 You chose to remove 3. There are 20 left. The computer chose to remove 1. There are 19 left. ... The computer chose to remove 3. There is 1 left. Looks like the computer outsmarted you. You lost!.

Rubric

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!