Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 7. (35 points) The Game of Nim In this part of the assignment, we will start developing a Java Object-Oriented program for the Game

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Problem 7. (35 points) The Game of Nim In this part of the assignment, we will start developing a Java Object-Oriented program for the Game of Nim. We have already seen a simple, text-version of this game at the very first session. Following is a description of the game: There is a pile of some marbles and two players. The number of marbles in the pile can be between 10 and 100. The two players alternatively take marbles from one pile. In cach move, a player must take at least onc and at most half of the marbles. Then, the other player takes a turn. The player who takes the last marble loses the game. We consider two modes in this game. In the first mode, the computer plays against a human player. The computer can be Novice (Stupid), and in its turn just takes a random number of marbles, or it can bc Smart, and in its turn uses a smart strategy to take the best number of marbles trying to win the game at the end. Note that in any case, computer will follow the game rules. In the second mode two human players can play against cach other. Using the above description, your first ask is to figure out and extract all the classes required for this game. Then, for each class, find the list of its properties and methods. For each property of a class, its data type and sible values must be specified. Also, for each method its return type, if any, and parameters along with their types should be determined. After extracting all the above information, create the initial version of each class. In this phase you don't need to write the body of the methods. Instead, inside each method, using a comment clearly explain its task, including the information it receives from the caller, its task, and the possible value it returns to the caller. Note that in the version, we don't create a class to run the game, and we only design the essential parts of the game as one or more Java classes. Java file names: One java file for each class To give you a better idea, you can see a sample running of the game I showed you in class on the next two pages. Welcome to the game of Nim! H) Human-Human C) Computer-Human Name of the player: Alice This is a game between Novice Computer and Alice. Initial number of piles: 77. Current number of piles: 77. It is Novice Computer's turn to play. Novice Computer takes 27 marbles. There are 50 marbles left. Alice, how many marbles do you take? (min=1, max=25) 25 There are 25 marbles left. Novice Computer takes 4 marbles. There are 21 marbles left. Alice, how many marbles do you take? (min=1, max=10)8 There are 13 marbles left. Novice Computer takes 1 marbles. There are 12 marbles left. Alice, how many marbles do you take? (min=1, max=6)5 There are 7 marbles left. Novice Computer takes 3 marbles. There are 4 marbles left. Alice, how many marbles do you take? (min=1, max=2) 1 There are 3 marbles left. Novice Computer takes 1 marbles. There are 2 marbles lett. Alice, how many marbles do you take? (min=1, max=1) 1 There are 1 marbles left. *** Alice is the winner! *** Player Name: Novice Computer, Number of Plays: 1, Score: 0 Player Name: Alice, Number of Plays: 1, Score: 1 play again Quit P) lay again Quit This is a game between Novice Computer and Alice. Initial number of piles: 93. Current number of piles: 93. It is Novice Computer's turn to play. Novice Computer takes 45 marbles. There are 48 marbles left. Alice, how many marbles do you take? (min=1, max=24) 24 There are 24 marbles left. Novice Computer takes 10 marbles. There are 14 marbles left. Alice, how many marbles do you take? (min=1, max=7)6 There are 8 marbles left. Novice Computer takes 1 marbles. There are 7 marbles left. Alice, how many marbles do you take? (min=1, max=3) 3 There are 4 marbles left. Novice Computer takes 1 marbles. There are 3 marbles left. Alice, how many marbles do you take? (min=1, max=1) 1 There are 2 marbles left. Novice Computer takes 1 marbles. There are 1 marbles left. *** Novice Computer is the winner! *** Player Name: Novice Computer, Number of Plays: 2, Score: 1 Player Name: Alice, Number of Plays: 2, Score: 1 Play again Quit New play set Exit Problem 7. (35 points) The Game of Nim In this part of the assignment, we will start developing a Java Object-Oriented program for the Game of Nim. We have already seen a simple, text-version of this game at the very first session. Following is a description of the game: There is a pile of some marbles and two players. The number of marbles in the pile can be between 10 and 100. The two players alternatively take marbles from one pile. In cach move, a player must take at least onc and at most half of the marbles. Then, the other player takes a turn. The player who takes the last marble loses the game. We consider two modes in this game. In the first mode, the computer plays against a human player. The computer can be Novice (Stupid), and in its turn just takes a random number of marbles, or it can bc Smart, and in its turn uses a smart strategy to take the best number of marbles trying to win the game at the end. Note that in any case, computer will follow the game rules. In the second mode two human players can play against cach other. Using the above description, your first ask is to figure out and extract all the classes required for this game. Then, for each class, find the list of its properties and methods. For each property of a class, its data type and sible values must be specified. Also, for each method its return type, if any, and parameters along with their types should be determined. After extracting all the above information, create the initial version of each class. In this phase you don't need to write the body of the methods. Instead, inside each method, using a comment clearly explain its task, including the information it receives from the caller, its task, and the possible value it returns to the caller. Note that in the version, we don't create a class to run the game, and we only design the essential parts of the game as one or more Java classes. Java file names: One java file for each class To give you a better idea, you can see a sample running of the game I showed you in class on the next two pages. Welcome to the game of Nim! H) Human-Human C) Computer-Human Name of the player: Alice This is a game between Novice Computer and Alice. Initial number of piles: 77. Current number of piles: 77. It is Novice Computer's turn to play. Novice Computer takes 27 marbles. There are 50 marbles left. Alice, how many marbles do you take? (min=1, max=25) 25 There are 25 marbles left. Novice Computer takes 4 marbles. There are 21 marbles left. Alice, how many marbles do you take? (min=1, max=10)8 There are 13 marbles left. Novice Computer takes 1 marbles. There are 12 marbles left. Alice, how many marbles do you take? (min=1, max=6)5 There are 7 marbles left. Novice Computer takes 3 marbles. There are 4 marbles left. Alice, how many marbles do you take? (min=1, max=2) 1 There are 3 marbles left. Novice Computer takes 1 marbles. There are 2 marbles lett. Alice, how many marbles do you take? (min=1, max=1) 1 There are 1 marbles left. *** Alice is the winner! *** Player Name: Novice Computer, Number of Plays: 1, Score: 0 Player Name: Alice, Number of Plays: 1, Score: 1 play again Quit P) lay again Quit This is a game between Novice Computer and Alice. Initial number of piles: 93. Current number of piles: 93. It is Novice Computer's turn to play. Novice Computer takes 45 marbles. There are 48 marbles left. Alice, how many marbles do you take? (min=1, max=24) 24 There are 24 marbles left. Novice Computer takes 10 marbles. There are 14 marbles left. Alice, how many marbles do you take? (min=1, max=7)6 There are 8 marbles left. Novice Computer takes 1 marbles. There are 7 marbles left. Alice, how many marbles do you take? (min=1, max=3) 3 There are 4 marbles left. Novice Computer takes 1 marbles. There are 3 marbles left. Alice, how many marbles do you take? (min=1, max=1) 1 There are 2 marbles left. Novice Computer takes 1 marbles. There are 1 marbles left. *** Novice Computer is the winner! *** Player Name: Novice Computer, Number of Plays: 2, Score: 1 Player Name: Alice, Number of Plays: 2, Score: 1 Play again Quit New play set Exit

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

Recommended Textbook for

Secrets Of Analytical Leaders Insights From Information Insiders

Authors: Wayne Eckerson

1st Edition

1935504347, 9781935504344

More Books

Students also viewed these Databases questions

Question

In which ways would you measure training success? Explain.

Answered: 1 week ago

Question

Evaluate Meyers and Browns approach to career development.

Answered: 1 week ago