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
What causes the moon to be illuminated? PLEASE HELP MEH ILL GIVE YOU BRAINLEIST!!
Likurg_2 [28]

Answer:

D Reflection

Explanation:

It reflects the light from the sun. Then when the earth gets in the way, it casts a shadow causing crescent moons.

7 0
2 years ago
What is the missing number in the pattern below?<br> 0, 1, 2, 3, 6, 11, 20, _?_, 68
lbvjy [14]

Answer:

0, 1, 2, 3, 6, 11, 20, 37, 68

Explanation:

Each number in the series, starting with 3, is the total of the three numbers before it. The following number is the total of the preceding three numbers, according to the pattern. The pattern's next number is 125.

3 0
2 years ago
Ammonia is one of the chemical constituents of industrial waste that must be removed in a treatment plant before the waste can s
Yanka [14]

Answer:

Following is attached the solution or the question given.

I hope it will help you a lot!

Explanation:

5 0
3 years ago
If a system of pulleys results in a force of 25% of the load, how far will the rope need to move to pull the load a distance of
GaryK [48]

Answer:

  40 ft

Explanation:

Assuming no loss of energy in the system of pulleys, the work done is the same whether you move the load directly or through the pulleys.

  W = Fd . . . . . . . . work is the product of force and distance

  F(10 ft) = (0.25F)(d) . . . . . where d is the distance we want to find

  d = 10F/(0.25F) = 40

The rope will need to move 40 feet.

8 0
2 years ago
If the total length of a measurement is 10 1/2" what is half of this length?
Aneli [31]

Answer:

13.335 CM (1 ft, 1.335 cm)

I am 80% sure this is the answer, but i am not too keen on math so if i am wrong let me know and i will try my best to fix it!

I hope this helped! Have a good day :]

5 0
2 years ago
Other questions:
  • An air conditioner using refrigerant R-134a as the working fluid and operating on the ideal vapor-compression refrigeration cycl
    12·1 answer
  • How are project deliverables determined?
    14·2 answers
  • When should u check ur review mirror
    5·1 answer
  • Given asphalt content test data:
    8·1 answer
  • A specimen of some metal having a rectangular cross section 10.4 mm × 12.8 mm is pulled in tension with a force of 15900 N, whic
    6·1 answer
  • Need Answers Quick!!!! What is the purpose of structural components such as frames, bearings, and mounts? A.) Connect two rotati
    9·1 answer
  • In a device to produce drinking water, humid air at 320C, 90% relative humidity and 1 atm is cooled to 50C at constant pressure.
    14·1 answer
  • What is the purpose for this experiment
    9·1 answer
  • List five pieces of personal safety equipment which must be in everyday use in the workshop​
    15·1 answer
  • The project's criteria.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!