Need Help ?

Home / Expert Answers / Other / c-program-of-the-game-of-nimprogram-requirements-asks-the-human-player-to-choose-between-an-easy-mod

(Answered): C++ program of the game of nimPROGRAM REQUIREMENTS:- asks the human player to choose between an easy ...



C++ program of the game of nim

PROGRAM REQUIREMENTS:

- asks the human player to choose between an easy mode and ahard mode.

- The number of the stones in the pile should be a random numberbetween 10 and 21,

-The program chooses a player randomly to start the game ( thecomputer and the human player should each have an equal chance oftaking the first move)

- When it is the humans turn, the human player should be allowedto remove 1, 2, or 3 stones but never more than the number ofstones left.

-When it is the computer’s turn, the behavior of the computerdepends on the mode:

A) Easy mode: The computer will pick a random number of stones(1, 2, or 3) to remove while never allowing the number of stonesleft to be negative.

B) Hard Mode: The computer will always try to win when possible.i. If the number of stones is a multiple of four plus 1 (e.g. 1, 5,9, etc.), the computer will simply remove one stone. ii. Otherwise,the computer will take enough stones to leave a multiple of fourplus one. The computer can always win in this case. For example, ifthe number of stones in the pile is 8, the computer will take 3stones to leave a pile of 5 stones (5 is 1 * 4 + 1); regardless ofthe human player’s next move, the computer can always remove anumber of stones to leave exactly one stone for the following turnby the human player.

- The program should continue as long as the game is not over (agame is over when there is no more stones left)

******** THE GAME OF NIM ***** Rules of the game: * Each player can remove 1, 2, or 3 stones from the pile. * The player who

******** THE GAME OF NIM ***** Rules of the game: * Each player can remove 1, 2, or 3 stones from the pile. * The player who makes the last move loses. Choose mode : Easy Mode (e) or Hard Mode (h): H You have chosen the hard mode. The initial number of stones is 11 Now a roll of the die to determine who plays first... You play first. It is your turn. Enter the number of stones you would like to remove: 1 You removed 1 stone from the pile The pile now has 10 stone stones left. The computer is choosing a move... The computer taking enough stones to leave a multiple of four plus one removed 1 stone from the pile The pile now has 9 stone stones left. It is your turn. Enter the number of stones you would like to remove: 2 You removed 2 stones from the pile The pile now has 7 stones stones left. The computer is choosing a move... The computer taking enough stones to leave a multiple of four plus one removed 2 stones from the pile The pile now has 5 stones stones left. It is your turn. Enter the number of stones you would like to remove: 3 You removed 3 stones from the pile The pile now has 2 stones stones left. The computer is choosing a move... The computer taking enough stones to leave a multiple of four plus one removed 1 stone from the pile The pile now has 1 stone stones left. It is your turn. Enter the number of stones you would like to remove: 3 3 is not a valid move. Enter either 1, 2, or 3 for the number of stones: -1 -1 is not a valid move. _Enter either 1, 2, or 3 for the number of stones: 0 is not a valid move. Enter either 1, 2, or 3 for the number of stones: 5 5 is not a valid move. Enter either 1, 2, or 3 for the number of stones: 1 You removed 1 stone from the pile The pile now has stone stones left. Sorry, you lost the game :( ************** Thank you for playing **** Press any key to continue


We have an Answer from Expert

View Expert Answer

Expert Answer


Answer to C++ program of the game of nim PROGRAM REQUIREMENTS: - asks the human player to choose between an easy mode and a hard m...
We have an Answer from Expert

Buy This Answer $4

Place Order