subject

This question involves a simulation of a two-player game. In the game, two simulated players each start out with an equal number of coins. In each round, each player chooses to spend either 1, 2, or 3 coins. Coins are then awarded to each player according to the following rules. Same rule: If both players spend the same number of coins, player 2 gains 1 coin.
Off-by-one rule: If the players do not spend the same number of coins and the positive difference between the number of coins spent by the two players is 1, player 2 is awarded 1 coin.
Off-by-two rule: If the players do not spend the same number of coins and the positive difference between the number of coins spent by the two players is 2, player 1 is awarded 2 coins.

The game ends when the specified number of rounds have been played or when a player’s coin count is less than 3 at the end of a round.

The CoinGame class is shown below. You will write two methods in the CoinGame class.

public class CoinGame

{

private int startingCoins; // starting number of coins

private int maxRounds; // maximum number of rounds played

public CoinGame(int s, int r)

{

startingCoins = s;

maxRounds = r;

}

/** Returns the number of coins (1, 2, or 3) that player 1 will spend.

*/

public int getPlayer1Move()

{

/* implementation not shown. */

}

/** Returns the number of coins (1, 2, or 3) that player 2 will spend, as described in part (a).

*/

public int getPlayer2Move(int round)

{

/* to be implemented in part (a) */

}

/** Plays a simulated game between two players, as described in part (b).

*/

public void playGame()

{

/* to be implemented in part (b) */

}

}

In the simulation, player 2 will always play according to the same strategy. The number of coins player 2 spends is based on what round it is, as described below.

(a) You will write method getPlayer2Move, which returns the number of coins that player 2 will spend in a given round of the game. In the first round of the game, the parameter round has the value 1, in the second round of the game, it has the value 2, and so on. The method returns 1, 2, or 3 based on the following rules.

If round is divisible by 3, then return 3.
If round is not divisible by 3 but is divisible by 2, then return 2.
If round is not divisible by 3 and is not divisible by 2, then return 1.
Complete method getPlayer2Move below by assigning the correct value to result to be returned.

/** Returns the number of coins (1, 2, or 3) that player 2 will spend, as described in part (a).

*/

public int getPlayer2Move(int round)

{

int result;

return result;

}

Write the method playGame, which simulates a game between player 1 and player 2, based on the rules and example shown at the beginning of the question. Both player 1 and player 2 start the game with startingCoins coins. Computer player 1 spends 1, 2, or 3 coins based on the value returned by the method getPlayer1Move(). Computer player 2 spends 1, 2, or 3 coins based on the value returned by the method getPlayer2Move().

The game ends when maxRounds rounds have been played or when a player’s coin count is less than 3 at the end of a round.

At the end of the game, the winner is determined according to the following rules.

If both players have the same number of coins at the end of the game, the method prints "tie game".
If player 1 has more coins than player 2, the method prints "player 1 wins".
If player 2 has more coins than player 1, the method prints "player 2 wins".
(b) Assume that getPlayer2Move works as specified, regardless of what you wrote in part (a) . You must use getPlayer1Move and getPlayer2Move appropriately to receive full credit.

Complete method playGame below.

/** Plays a simulated game between two players, as described in part (b).

*/

public void playGame()

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 06:00
Pthe price of tickets in a group when a purchased in bulk can be found with the equation c=px+24 were c is the cost, p is the number of people,and x is the price per ticket. what is price of of each ticket if it costs $189 to buy tickets for 15 people ? a $8 b $24c $9d $11 show work
Answers: 1
question
Computers and Technology, 24.06.2019 06:30
Adrawing that places all lines parallel to the z axis at an angle from the horizon is 99 ! a. an oblique drawing b. a perspective drawing c. an auxiliary view d. a one-point perspective drawing
Answers: 2
question
Computers and Technology, 24.06.2019 07:50
Write a defining table and then a program that determines if you can sleep in or not. your program should get all its input from your computer’s clock. on all weekdays (monday through friday) that are not holidays, your program should output “get up! ” on all other days (weekends and holidays), your program should output “sleep in.” the three holidays that your program must check for are january 1 (new year’s day), july 4 (u.s. independence day), and december 25 (christmas). you don’t need to include other holidays in your program because most other holidays do not occur on a fixed day each year.
Answers: 1
question
Computers and Technology, 24.06.2019 10:20
Multiple choice project create a program with two multiple choice questions. 1. users have two attempts only, show attempt number each time. hint: while loop with break control. (20%) 2. only one correct answer for each question, use switch case for each question. (20%) 3. show total score after the two questions are answered. hint: . (20%) 4. user have options to answer the two questions again if first attempt score is not 100%. hint: if statment. (20%) 5. use string method .toupper() to allow users to enter with lowercase or uppercase letters. (20%) 1. where is the capital of the state of florida? a. orlando b. tallahassee c. miami d. tampa b 2. where is walt disney world park located in florida? a. orlando b. tallahassee c. miami d. tampa a
Answers: 1
You know the right answer?
This question involves a simulation of a two-player game. In the game, two simulated players each st...
Questions
question
English, 07.06.2021 14:00
question
Mathematics, 07.06.2021 14:00
question
History, 07.06.2021 14:00
question
Mathematics, 07.06.2021 14:00
question
Mathematics, 07.06.2021 14:00
Questions on the website: 13722367