In Progress

java program:Game of NIM

Draw a flowchart for the algorithm and write a program that plays the ancient Chinese game of

NIM. Actually, this is a simplified version of the game. Each game starts with a user-specified

number of stones in a pile. The user and the computer take turns removing either one or two

stones from the pile. The player who takes the last stone loses. Your program should have the

computer use the optimal playing strategy. The optimal strategy is as follows:

Divide the remaining number of stones by three. If the remainder is zero, then two stones

are removed, or else one stone is removed. For example, if the remaining number of

stones is nine or fifteen, then two stones are removed; if the remaining number of stones

is eight or ten, then one stone is removed.

Your algorithm and program should allow the user to play additional games of NIM as long as

he/she enters a “y” or “yes” (lowercase or uppercase) in response to a “Do you want to

play again?” prompt. Keep the tally of wins and announce the winner at the end of the

program. The tally will include for the player and the computer the number of wins by each and

the total number of games played. The “player” with more wins is the winner. In the case where

both the player and the computer have the same number of wins, then it is a draw. See the

sample output.

In addition, your will need to add input validation to your NIM algorithm and program. More

specifically, 2

1) ask the user to re-enter the number of starting stones if he/she doesn’t enter an

appropriate number,

2) ask the user to re-enter the number of stones to be removed if he/she doesn’t enter an

appropriate number, and

3) ask the user to re-enter a “yes/no” response if he/she doesn’t enter an appropriate

string.

Your game (algorithm and program) is to be well designed – future users and maintainers of this

solution would like to have a programmer-friendly, carefully planned design.

Sample Output

A sample run of the program is shown below. (Note: Bold texts are user input.) :

T H E G A M E O F N I M

Enter number of starting stones: 7

Would you like to go first? (y/n): yEs

How many would you like to remove (1 or 2)? 1

The number of stones left is 6.

The computer removes 2 stones.

The number of stones left is 4.

How many would you like to remove (1 or 2)? 2

The number of stones left is 2.

The computer removes 1 stone.

The number of stones left is 1.

How many would you like to remove (1 or 2)? 1

The number of stones left is 0.

The computer wins!

Do you want to play again? (y/n): Y

Enter the number of starting stones: 4

Would you like to go first? (y/n): n

The computer removes 1 stone.

The number of stones left is 3.

How many would you like to remove (1 or 2)? 2

The number of stones left is 1.

The computer removes 1 stone.

The number of stones left is 0.

You win!

Do you want to play again? (y/n): n

Results:

Computer Wins – 1

Player Wins - 1

Total Games - 2

It is a DRAW!

Thank you, good bye!

Skills: Java

See more: want play, nim stone remove game java, game nim java, java nim game, nim java, game nim flowchart, nim java program, java nim, nim game java, win nim, who is the first computer programmer, the nim game, the game of nim, the game of games, the game nim, same game java, program algorithm example, program algorithm, play nim game, o 1 algorithm, nim number, nim how to win, nim game strategy, nim game solution, nim games

About the Employer:
( 26 reviews ) Lincoln, United States

Project ID: #5457232

Awarded to:

andrewscm

I can create this simple NIM game for you in Java following the instructions you posted. This is a rather simple program, and I can even do it tonight if you'd like. These are the kind of assignments I got in middle sc More

$25 USD in 1 day
(3 Reviews)
3.4

4 freelancers are bidding on average $88 for this job

kawsar92

I am a experienced java developer. I did lots of work on java. I can build this for you. Contact for further details. Thank you.

$23 USD in 1 day
(17 Reviews)
3.3
Ortiga

I can do it in a few hours (you can see my reviews), I'm ready to start now.........................

$25 USD in 1 day
(4 Reviews)
2.2
vickkey7

I am ready to start this project, please once consider me to start this project.......... thanks with regards

$277 USD in 8 days
(0 Reviews)
0.0