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
A DC generator turns at 2000 rpm and has an output of 200 V. The armature constant is 0.5 V-min/Wb, and the field constant of th
WITCHER [35]

Answer:

b. 10A

Explanation:

Using the formula, E= k × r×I

200= 0.5 ×2000×0.02×I

200=20×I

Dividing with 20

I = 200/20= 10A

4 0
3 years ago
Read 2 more answers
Answer the following either true (T) or false (F) (5 pts)
likoan [24]

Answer:

1. True

2. True

3. False

Explanation:

The office location is where the soil layer is not uniform. The thickness of the soil varies which could lead to doors being jammed. The engineer needs to estimate the differential in clay soil.

The inclined surface can hold less weight than a vertical surface. The capacity to hold the weight is due to the gravitational force which is exerted to the load.

6 0
3 years ago
By adding "-once", one can form the noun form of the word "organize" is that true or false?​
denpristay [2]

Answer:

<h2>False </h2>

Explanation:

The noun form of organize is just adding letter r

7 0
3 years ago
Read 2 more answers
Sk the first 3D printed house
quester [9]
2,000 the answer __________im Shayla_________I like food _________do you________the crunch for me_______km not fat tho______are u no worrys________is u are u still pretty
8 0
3 years ago
technician a uses a current output test to check ac generator output. technician b uses a voltage output test to check output. w
expeople1 [14]

Answer:

both

Explanation:

Both the technician are correct, ac generator output can be tested in both ways. The two ways are  current output test to check ac generator output. and  voltage output test to check output.

7 0
3 years ago
Other questions:
  • if you had 100 B size sheets and you cut them into A size sheets, how many sheets of A size paper would you have
    14·1 answer
  • The development of various technologies led to many historic events. Use information from the Internet to describe one major his
    5·1 answer
  • A coal-fired power plant is burning bituminous coal that has an energy content of 12,000 Btu/lb. The power plant is burning the
    13·1 answer
  • In 2009 an explosive eruption covered the island of Hunga Ha'apai in black volcanic ash. What type of succession is this?
    7·1 answer
  • What should you consider when choosing the type of hearing protection you use?
    15·1 answer
  • Hi im ***ar and im doing sculptural but what should it be about star wars or Marvel
    9·1 answer
  • Why is there an Engineering Process?
    15·2 answers
  • Respond with TRUE if the symbol of the valve shown belows
    5·1 answer
  • Which of the following is not a function of the cooling system
    8·1 answer
  • Can I get an answer to this question please
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!