Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Language is C++ Problem description You will write a program that implements the following version of the game of Nim. Nim is a mathematical strategy
Language is C++
Problem description You will write a program that implements the following version of the game of Nim. Nim is a mathematical strategy game, which dates back to 16th century China. There are many variations on this game, but the version we'll be playing starts with a row of 11 sticks: On their turn a player may remove 1, 2, or 3 sticks from the pile. Players alternate taking turns, and the play removing the last stick wins. Your game should feature two players alternating turns. First, your program should print out a welcome statement and brief instructions. Then, you should display the current game state and prompt player 1 for the number of sticks they should remove: Welcome to Nimi The player removing Players will take turns removing 1, 2, or 3 sticks from the initial 11. the last stick wins! Player 1, it's your turnl The game currently looks like this: How many sticks would you like to remove? (1, 2, or 3) After making sure they entered a valid response, you should remove the appropriate number of sticks. If there are now zero sticks remaining, you should declare that player the winner and end the program. Otherwise, the other player should take a turn. Sample Game: Welcome to Nimi Players will take tums removing 1, 2, or 3 sticks from the initial 11. The player removing the last stick wins! Player 1, it's your turn! The game currently looks like this: How many sticks would you like to remove? (1, 2, or 3) 3 Player 2, it's your turn! The game currently looks like this: How many sticks would you like to remove? (1, 2, or 3) 1 Player 1, it's your turnl The game currently looks like this: How many sticks would you like to remove? (1, 2, or 3) 4 That choice is invalid. How many sticks would you like to remove? (1, 2 or 3) 3 Player 2, it's your turn! The game currently looks like this: How many sticks would you like to remove? (1, 2, or 3) 1 Player 1, it's your turn! The game currently looks like this: How many sticks would you like to remove? (1, 2, or 3) 3 Congratulations Player 1, you win! Program Design Before starting, think about what information you'll need to keep track of during the game The game will use multiple loops. Think about where repetition is needed, and what loop will be most appropriate for each instance of repetition. You should show the current number of sticks using a loop. Note that when there are only a few sticks remaining, the range of valid inputs may go down (you can't take more sticks than there are left). For a little extra fun; trying to implement a computer player or a version with more than one row of sticks. Nim Evaluation (Y/N) Criteria for Nim Does the program compile and run without warnings or errors? Does the program properly display the current board, using a loop? Does the program take turns between the two players? For each player, does it check that the player is removing 1, 2, or 3 markers? When there are less than 3 markers left, does it check for a proper choice? Does the program terminate and declare a winner when the last marker is removed
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started