1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
eduard
3 years ago
15

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 t

he 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 following is an example of a game played with a starting value of 10 coins and a game length of 5 rounds
Engineering
1 answer:
Galina-37 [17]3 years ago
3 0

Answer:

Check the explanation

Explanation:

1 -

public int getPlayer2Move(int round)

{

  int result = 0;

 

  //If round is divided by 3

  if(round%3 == 0) {

      result= 3;

  }

  //if round is not divided by 3 and is divided by 2

  else if(round%3 != 0 && round%2 == 0) {

      result = 2;

  }

  //if round is not divided by 3 or 2

  else {

      result = 1;

  }

 

  return result;

}

2-

public void playGame()

{

 

  //Initializing player 1 coins

  int player1Coins = startingCoins;

 

  //Initializing player 2 coins

  int player2Coins = startingCoins;

 

 

  for ( int round = 1 ; round <= maxRounds ; round++) {

     

      //if the player 1 or player 2 coins are less than 3

      if(player1Coins < 3 || player2Coins < 3) {

          break;

      }

     

      //The number of coins player 1 spends

      int player1Spends = getPlayer1Move();

     

      //The number of coins player 2 spends

      int player2Spends = getPlayer2Move(round);

     

      //Remaining coins of player 1

      player1Coins -= player1Spends;

     

      //Remaining coins of player 2

      player2Coins -= player2Spends;

     

      //If player 2 spends the same number of coins as player 2 spends

      if ( player1Spends == player2Spends) {

          player2Coins += 1;

          continue;

      }

     

      //positive difference between the number of coins spent by the two players

      int difference = Math.abs(player1Spends - player2Spends) ;

     

      //if difference is 1

      if( difference == 1) {

          player2Coins += 1;

          continue;

      }

     

      //If difference is 2

      if(difference == 2) {

          player1Coins += 2;

          continue;

      }

     

     

  }

 

  // At the end of the game

  //If player 1 coins is equal to player two coins

  if(player1Coins == player2Coins) {

      System.out.println("tie game");

  }

  //If player 1 coins are greater than player 2 coins

  else if(player1Coins > player2Coins) {

      System.out.println("player 1 wins");

  }

  //If player 2 coins is grater than player 2 coins

  else if(player1Coins < player2Coins) {

      System.out.println("player 2 wins");

  }

}

You might be interested in
rt this question on a NEW page Give ONE word/tem for each of the following descriptions by choosing a word/term from the list be
Shalnov [3]

Answer:

oh I am sorry I can't understand your question.

6 0
3 years ago
To use wiring diagrams, an understanding of the symbols, abbreviations, and connector coding used in the diagrams
Komok [63]

Answer:

True

Explanation:

6 0
3 years ago
Which of these materials are insulators? Select the THREE (3) that apply.
lubasha [3.4K]

Answer:

wool, rubber, and plastic

Explanation:

5 0
2 years ago
The largest class of errors in software engineering can be attributed to _______.
Ilya [14]

Answer:

improper imput validation

Explanation:

6 0
1 year ago
Which option identifies the next step Kristin should take to test the design in the following scenario?
Nadusha1986 [10]
The 2d sketch should be right
4 0
3 years ago
Other questions:
  • Air is contained in a vertical piston–cylinder assembly such that the piston is in static equilibrium. The atmosphere exerts a p
    9·1 answer
  • Consider a Carnot heat pump cycle executed in a steady-flow system in the saturated mixture region using R-134a flowing at a rat
    5·1 answer
  • What is the purpose of O-ring and valve seals in a cylinder head?
    15·1 answer
  • How would I get this python code to run correctly? it's not working.​
    7·1 answer
  • Compared with space operations specialists, intelligence officers are which of the following?
    7·1 answer
  • Describe in detail the process of making a collapsable bowl.​
    11·1 answer
  • Another name for your computer, running the web browser program is: Web user The client The mainframe Browsing agent
    11·1 answer
  • A spherical metal ball of radius r_0 is heated in an oven to a temperature of T_1 throughout and is then taken out of the oven a
    6·1 answer
  • You have a Switch LED Lightbulb with the following information: It is equivalent to a 40 Watt incandescent lightbulb. It uses 8
    5·1 answer
  • What is the objective of phasing out an INDUCTION MOTOR before putting the machine into commission?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!