Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Objective: Create a Java game using Interfaces Instructions: Thank you Nim is an ancient game with severalvariations. Here' s one: Two plavers take turns removinq

Objective: Create a Java game using Interfaces

Instructions:

image text in transcribed

image text in transcribed

Thank you

Nim is an ancient game with severalvariations. Here' s one: Two plavers take turns removinq marbles from a pile. On each turn the player must remove at least one but no more than half of the remaining marbles. The player who is forced to remove the last marble loses. write a ava program to simulate the game o Nim between two players. Either or both of the players may bea Human, a SmartComputer, or a BowAverageComputer. Begin each game by asklng the user who will be playing and which player should go Iirst -- The BelowAverageComputer removes a random number of marbles between 1 and n/2 each turn. -- The SmartComputer removes exactly enough marblesto make the remaining pile size a power of two minus one (i.e. 1, 3, 7, 15, 31, or 63) The SmartComputer cannot be beaten if it has the first move, unless the initial pile size happens to be 15, 31, or 63 winning strategy is also invincible Naturally, a Human who plays first and knows the -- The Human enters the number of marbles to be removed interactively Begin each game with a pile of between 10 and 100 marbles, inclusive, where the size is set randomly After each turn marbles taken, and the nnber of marbles rema1n1n rint out the player name, number of When each game ends the winner should be announced and the user asked whether she wants to play another game. If so, the user will enter the plavers and piay order again. 1. TO receive credit for this assignment, You mustcreate a Java interface called Player, and 3 classes that implement (or, "realize") it- one class for each of the 3 types of players 2 Your interface will declare a move method and a method that returns the player's name.In the case of Human player(S), the name (s) wili be entered interactively (at the keyboard) . Use whatever names you like for the computers 3. Implement another class called Nim with a play) method that conducts the game (as shown in class). To receive credit, your play method must call the move method for each player polymorphically 4. Your play method will return the winner' s name when the game ends 5 Design the move method of the Human class so that the human is not allowed to "cheat" (i.e. remove an illegal number of marbles). You know how those humans are! 6. Implement another class called Pile to create and maintain a pile of marbles. 7. The main method of your test class will get the game parameters from the user (who's playing, who goes first, name (s) if Human), create the Player objects, the Nim object, call the play) method, and print the winner returned. After each game, ask whether the user wants to lay again Your Nim class must depend only on the Player interface and Pile class, and not on any of the classes that implement Playe If vou do this correctl modi fied at a our Nim class should not have to ayers are inventea in ir any new Kindas o e future This 1S exaCtly why interfaces were znvente The individual player classes and the Pile class must not depend on one another or on the Nim class

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_2

Step: 3

blur-text-image_3

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

More Books

Students also viewed these Databases questions

Question

Describe the biopsychosocial approach to individual development.

Answered: 1 week ago