Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help building a program. The game of 23 is a two-player game that begins with a pile of 23 toothpicks. Players take turns, withdrawing

Need help building a program. 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 computers 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. 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.

Please notice that the following requirements:

1. If the user picks illegal number of sticks, the program will prompt the user to repick.

2. At the end of each game, the program will prompt user to choose if the user wants another game.

Should look like image attachedimage text in transcribed

Let's play a game of 23 Enter the number of sticks you wish to pick: 2 You picked 2 stick 21 lef Computer picked 2 sticks 19 left Your turn. Enter the number of sticks you wish to pick: 3 You picked 3 stick 16 lef 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 ef Your turn. Enter the number of sticks you wish to pick: 2 You picked 2 stick 5 lef 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 ef Your turn. Enter the number of sticks you wish to pick: 1 You picked 1 stick 0 lef You picked the last stick. Sorry, the computer beat you! Do you want to play another game?

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

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions