Question

In: Computer Science

Game Description: The popular rock-paper-scissors game is usually played between two people in which each player...

Game Description: The popular rock-paper-scissors game is usually played between two people in which each player simultaneously chooses either a rock or a paper or scissors (usually with an outstretched hand). The rule of the game is simple: rock crushes scissors, scissors cut paper, and paper wraps rock. If both the players choose the same object, then it ends in a tie.

Problem Description: You have to play the rock-paper-scissors game against the computer for 100 times. You receive the following rewards each time you play the game:

You get $5 if you win

You get $2 if there is a tie

You get $-1 if you lose

The computer randomly chooses rock, paper, or scissors in each game. Rather than deciding what to play (rock, paper or scissors) for each individual game, you decide to use the following strategy:  Play (i) scissors – (ii) rock – (iii) paper sequentially and repeatedly, over and over

Example: 

Round 1: Play scissors 

Round 2: Play rock 

Round 3: Play paper 

Round 4: Play scissors …

Write a program to play the rock-paper-scissors game against the computer for 100 times using the above strategy. You are required to calculate the total reward that you accumulate after playing the game 100 times.

Hint: Use loops to simulate the game 100 times. In each iteration, generate a random integer 1, 2, or 3 representing rock, paper, and scissors, respectively and use that number to know what computer has played (i.e. 1 is for rock, 2 is for paper, 3 is for scissors). Using your strategy described above, figure out whether you win, lose or tie the game in each iteration. Maintain a variable to keep track of the amount that you have won and keep updating that amount in each iteration depending on the result of the game. You can generate a random integer 1, 2, or 3 as follows: int randomNum = 1 + (int)(3*Math.random( ));

Deliverables:

The total reward that you receive (after playing the game 100 times) as a comment on top of your Java code.

1. Properly define the loop (2 points)

2. Correctly define sequential (i) scissors-(ii) rock-(iii) paper strategy for yourself (1.5 points)

3. Correctly define how computer randomly chooses rock, paper, or scissors (1.5 points)

4. Calculate how many points you gain for each outcome (4 points) 5. Proper display of output and comments where necessary (1 point)

5. Proper display of output and comments where necessary (1 point)

Solutions

Expert Solution

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________

// RockPaperScissors.java

import java.util.Random;

public class RockPaperScissors {
   // Creating a random Class object
   static Random r = new Random();

   public static void main(String[] args) {
       //Declaring variables
       int tot = 0, comp, user = 0;

       //Playing the game for 100 times
       for (int i = 1; i <= 100; i++) {
           //getting the computer selection
           comp = getComputerSelection();
           if (i % 3 == 1) {
               user = 3;
           } else if (i % 3 == 2) {
               user = 1;
           } else if (i % 3 == 0) {
               user = 2;
           }

           if (comp == 1 && user == 1) {
               tot += 2;
           } else if (comp == 1 && user == 2) {
               tot += 5;
           } else if (comp == 2 && user == 1) {
               tot -= 1;
           } else if (comp == 2 && user == 2) {
               tot += 2;
           } else if (comp == 2 && user == 3) {
               tot += 5;
           } else if (comp == 3 && user == 2) {
               tot -= 1;
           } else if (comp == 1 && user == 3) {
               tot -= 1;
           } else if (comp == 3 && user == 1) {
               tot += 5;
           } else if (comp == 3 && user == 3) {
               tot += 2;
           }

          

       }
       System.out.println("Total amount won : $" + tot);

   }

   //Getting the computer choice
   private static int getComputerSelection() {
       return r.nextInt(3) + 1;
   }

}

_________________________

Output:

Total amount won : $194

_______________Could you plz rate me well.Thank You


Related Solutions

Please write a scheme code for the rock paper scissors game between a player and the...
Please write a scheme code for the rock paper scissors game between a player and the computer (AI). In scheme programming language please.
Code the game of Rock, Paper, Scissors between a human player and the computer. You can...
Code the game of Rock, Paper, Scissors between a human player and the computer. You can check out the game on Wikipedia if you are not familiar with it. Create a 4 option menu with the human player choices, plus the option of exiting the game. Randomly determine the computer’s choice (although a great deal of AI research has gone in to determining the best computer move). • Loop the game until the human player exits. • Count the number...
Two players play a rock-paper-scissors game. The losing player will give $1 to the winning player....
Two players play a rock-paper-scissors game. The losing player will give $1 to the winning player. If it is a draw, no payment is made. The payoff to a player is the amount of money (s)he gets. Represent the situation in a matrix form. Find all the Nash equilibria.
Many of you probably played the game “Rock, Paper, Scissors” as a child. Consider the following...
Many of you probably played the game “Rock, Paper, Scissors” as a child. Consider the following variation of that game. Instead of two players, suppose three players play this game, and let us call these players A, B, and C. Each player selects one of these three items—Rock, Paper, or Scissors—independent of each other. Player A will win the game if all three players select the same item, for example, rock. Player B will win the game if exactly two...
Consider now the following two-player simultaneous-move game, called the rock-paper-scissors-lizard game. R stands for rock, P...
Consider now the following two-player simultaneous-move game, called the rock-paper-scissors-lizard game. R stands for rock, P for paper, S for scissors, and L for lizard. R beats S but loses against P and L; P beats R but loses against S and L; S beats P and L but loses against R; L beats R and P but loses against S. The payoffs for winning is 1 and that for losing is -1; when both players choose the same strategy...
In the game Rock Paper Scissors, two players simultaneously choose one of three options: rock, paper,...
In the game Rock Paper Scissors, two players simultaneously choose one of three options: rock, paper, or scissors. If both players choose the same option, then the result is a tie. However, if they choose differently, the winner is determined as follows: • Rock beats scissors, because a rock can break a pair of scissors. • Scissors beats paper, because scissors can cut paper. • Paper beats rock, because a piece of paper can cover a rock. Create a game...
In the game Rock Paper Scissors, two players simultaneously choose one of three options: rock, paper,...
In the game Rock Paper Scissors, two players simultaneously choose one of three options: rock, paper, or scissors. If both players choose the same option, then the result is a tie. However, if they choose differently, the winner is determined as follows: • Rock beats scissors, because a rock can break a pair of scissors. • Scissors beats paper, because scissors can cut paper. • Paper beats rock, because a piece of paper can cover a rock. Create a game...
Design and implement an Android application that plays the Rock-Paper-Scissors game against the computer. When played...
Design and implement an Android application that plays the Rock-Paper-Scissors game against the computer. When played between two people, each person picks one of three options (usually shown by a hand gesture) at the same time, and a winner is determined. In the game, Rock beats Scissors, Scissors beats Paper, and Paper beats Rock. The program should randomly choose one of the three options (without revealing it) and then seek for the user’s selection (using your choice of an object...
1. Have you ever played rock-paper-scissors (or Rochambeau)? It’s considered a “fair game” in that the...
1. Have you ever played rock-paper-scissors (or Rochambeau)? It’s considered a “fair game” in that the two players are equally likely to win (like a coin toss). Both players simultaneously display one of three hand gestures (rock, paper, or scissors), and the objective is to display a gesture that defeats that of your opponent. The main gist is that rocks break scissors, scissors cut paper, and paper covers rock. We investigated some results of the game rock-paper-scissors, where the researchers...
Solve the scissors, paper, rock game. This game is well known in many parts of the...
Solve the scissors, paper, rock game. This game is well known in many parts of the world. Two players simultaneously present a hand in one of three positions: an open hand (paper), a closed fist (rock), or two open fingers (scissors). The payoff is 1 unit according to the rule “Paper covers rock, rock breaks scissors, and scissors cut paper.” If both players present the same form, the payoff is 0. Set up the payoff matrix for the game and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT