Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

If (n + 1)! = 30(n - 1)!, find n.

Answered: 1 week ago