0

Can someone write a code for GAME 23 in cpp. It will be highly appreciated.

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 C++ Function for 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 withdraw 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

12th Oct 2019, 5:33 AM
M Abdur Rafey Ahmed
M Abdur Rafey Ahmed - avatar
2 ответов
+ 2
So, first turn, human takes 1 to 3 sticks, and the computer is free to do the same, and only from the second turn the computer is forced to take 4 minus the number of stick the human took in the first turn? Still, as long as the computer isn't free to choose, but forced to pick like you said, there is no strategy for the computer to win, unless the human lets it, or makes a mistake. Am I missing something? Btw, the C++ program should be simple, I may write it today if I get to a computer, I'm on a phone now.
12th Oct 2019, 9:09 AM
Selin Genkur
+ 1
This looks like you are trying to get someone to do your homework / assignment. Please produce your code attempt first. People here like to see initiative first even if your code has errors. You will then receive assistance with errors. You truly can never learn if someone does the code and you hand it in without understanding it or looking at it. Best of luck.
12th Oct 2019, 8:41 AM
Xyenia 🦉
Xyenia 🦉 - avatar