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
Thin film deposition is a process where: a)-elemental, alloy, or compound thin films are deposited onto a bulk substrate! b)-Pho
marshall27 [118]

Answer:

(A) elemental, alloy, or compound thin films are deposited on to a bulk substrate

Explanation:

In film deposition there is process of depositing of material in form of thin films whose size varies between the nano meters to micrometers onto a surface. The material can be a single element a alloy or a compound.

This technology is very useful in semiconductor industries, in solar panels in CD drives etc

so from above discussion it is clear that option (a) will be the correct answer

8 0
3 years ago
How much horse power does a Lamborghini have
statuscvo [17]
The Lamborghini SCV12 has 830 horse power.
4 0
2 years ago
Read 2 more answers
Tesla Is the best ELECTRIC car brand, Change my mind
pochemuha

Answer:You are correct, no need to change.

Explanation:

5 0
3 years ago
Read 2 more answers
4. The outer end of a control arm is attached to the steering knuckle through a
arlik [135]
Is attached to the spring
3 0
3 years ago
Read 2 more answers
Provide three examples of things engineers can implement when designing environmentally sustainable projects.
Dafna1 [17]
Water supply.
Food production.
Housing and shelter.
Sanitation and waste management.
Energy development.
Transportation.
6 0
3 years ago
Read 2 more answers
Other questions:
  • The wet density of a sand was found to be 1.9 Mg/m3 and the field water content was 10%. In the laboratory, the density of solid
    9·1 answer
  • A large plate is fabricated from a steel alloy that has a plane strain fracture toughness of 78 MPa (70.98 ksi). If the plate is
    7·1 answer
  • Light energy produces the only voltage in a solar cell. (a)-True(T) (b)- false(F)
    9·1 answer
  • Represent the following sentence by a Boolean expression:
    11·1 answer
  • How much heat (Btu) is prod uced by a 150-W light bulb that is on for 20-hours?
    14·1 answer
  • 5) Initially, the pressure and temperature of steam inside a solid capsule is at 100-pound force per square inch absolute (psia)
    6·1 answer
  • In a certain balanced three phase system each line current is a 5a and each line voltage is 220v . What is the approximate real
    15·1 answer
  • Discuss in detail the manners of interaction with opposite gender
    10·1 answer
  • Which option identifies the concept represented in the following scenario?
    7·1 answer
  • How do you breed a linner?
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!