Question

In: Computer Science

Rock-Paper-Scissors Implement Rock-Paper-Scissors such that the user can play the computer in a best-of series! The...

Rock-Paper-Scissors

Implement Rock-Paper-Scissors such that the user can play the computer in a best-of series! The user inputs the number of rounds which should be positive and odd. This is a free form assignment but structure your code similar to the test cases provided. USING MATLAB ONLY!!!

Program Inputs
• How many rounds would you like to play (odd rounds only)?: XXX

– XXX should be positive and odd. Restart the game if the input is not positive or odd.

Program Outputs
• XXX wins this round

– Replace XXX with either User or Computer depending on who wins the round • Game Over!

– After the Game is over display the times User and Computer won after the total number of rounds. Finally display who wins the entire game.

Sample Outputs:

Test Case 1:

Welcome to Rock-Paper-Scissors! Play if you dare!
How many rounds would you like to play (odd rounds only)? 3
You choose to do best out of 3 rounds
*********************************************************
Round 1
*********************************************************
Rock     (0)...
Paper    (1)...
Scissors (2)...
Shoot:    1
The computer chooses Rock and you picked Paper
User wins this round!
*********************************************************
*********************************************************
Round 2
*********************************************************
Rock     (0)...
Paper    (1)...
Scissors (2)...
Shoot:    2
The computer chooses Rock and you picked Scissors
Computer wins this round!
*********************************************************
*********************************************************
Round 3
*********************************************************
Rock     (0)...
Paper    (1)...
Scissors (2)...
Shoot:    1
The computer chooses Scissors and you picked Paper
Computer wins this round!
*********************************************************
*********************************************************
Game over!
User won 1 out of 3 rounds
Computer won 2 out of 3 rounds
Computer wins! Did you expect anything else?
*********************************************************

Test Case 2:

Welcome to Rock-Paper-Scissors! Play if you dare!
How many rounds would you like to play (odd rounds only)? 3
You choose to do best out of 3 rounds
*********************************************************
Round 1
*********************************************************
Rock     (0)...
Paper    (1)...
Scissors (2)...
Shoot:    5
How dare you cheat at rock paper scissors!
You lose this round! You muggle!
*********************************************************
*********************************************************
Round 2
*********************************************************
Rock     (0)...
Paper    (1)...
Scissors (2)...
Shoot:    7
How dare you cheat at rock paper scissors!
You lose this round! You muggle!
*********************************************************
*********************************************************
Game over!
User won 0 out of 3 rounds
Computer won 2 out of 3 rounds
Computer wins! Did you expect anything else?
*********************************************************

Test Case 3:

Welcome to Rock-Paper-Scissors! Play if you dare!
How many rounds would you like to play (odd rounds only)? 1
You choose to do best out of 1 rounds
*********************************************************
Round 1
*********************************************************
Rock     (0)...
Paper    (1)...
Scissors (2)...
Shoot:    5
How dare you cheat at rock paper scissors!
You lose this round! You muggle!
*********************************************************
*********************************************************
Game over!
User won 0 out of 1 rounds
Computer won 1 out of 1 rounds
Computer wins! Did you expect anything else?
*********************************************************

Test Case 4:

Welcome to Rock-Paper-Scissors! Play if you dare!
How many rounds would you like to play (odd rounds only)? 2
2 is not a valid number of rounds... Try again!
*********************************************************
How many rounds would you like to play (odd rounds only)? 1
You choose to do best out of 1 rounds
*********************************************************
Round 1
*********************************************************
Rock     (0)...
Paper    (1)...
Scissors (2)...
Shoot:    1
The computer chooses Paper and you picked Paper
This round is a tie! Replaying this round...
*********************************************************
*********************************************************
Round 1
*********************************************************
Rock     (0)...
Paper    (1)...
Scissors (2)...
Shoot:    1
The computer chooses Scissors and you picked Paper
Computer wins this round!
*********************************************************
*********************************************************
Game over!
User won 0 out of 1 rounds
Computer won 1 out of 1 rounds
Computer wins! Did you expect anything else?
*********************************************************

Solutions

Expert Solution

Following code snippet can be used

numberOfTrials = 30; % Whatever you want...
for k = 1 : numberOfTrials
  choices = {'Rock', 'Paper', 'Scissors', 'Quit'};
  userChoice = menu('Which choice?: ', choices)
  if userChoice == 4
    break;
  end
  computerChoice =randi([1,3])
  message = sprintf('You chose %s and computer chose %s', ...
    choices{userChoice}, choices{computerChoice})
  switch userChoice
    case 1
      switch computerChoice
        case 1
          message = sprintf('%s\nTie', message);
        case 2
          message = sprintf('%s\nComputer wins.', message);
        case 3
          message = sprintf('%s\nYou win', message);
      end
    case 2
      switch computerChoice
        case 1
          message = sprintf('%s\nYou win!', message);
        case 2
          message = sprintf('%s\nTie', message);
        case 3
          message = sprintf('%s\nComputer wins', message);
      end
    case 3
      switch computerChoice
        case 1
          message = sprintf('%s\nComputer wins.', message);
        case 2
          message = sprintf('%s\nYou win!', message);
        case 3
          message = sprintf('%s\nTie', message);
      end
    case 4
      break;
  end
  uiwait(helpdlg(message));

Related Solutions

Rock, Paper, Scissors Game Write a Python program rps.py that lets the user play the game...
Rock, Paper, Scissors Game Write a Python program rps.py that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows: You can set these constant global variables at the top outside of your main function definition: COMPUTER_WINS = 1 PLAYER_WINS = 2 TIE = 0 INVALID = 3 ROCK = 1 PAPER = 2 SCISSORS = 3 For this program 1 represents rock, 2 represents paper, and 3 represents scissors. In...
Using Java, write a program that allows the user to play the Rock-Paper-Scissors game against the...
Using Java, write a program that allows the user to play the Rock-Paper-Scissors game against the computer through a user interface. The user will choose to throw Rock, Paper or Scissors and the computer will randomly select between the two. In the game, Rock beats Scissors, Scissors beats Paper, and Paper beats Rock. The program should then reveal the computer's choice and print a statement indicating if the user won, the computer won, or if it was a tie. Allow...
JAVA : Design and implement an application that plays the Rock-Paper-Scissors game against the computer. When...
JAVA : Design and implement an 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 prompt for the user’s selection. At that point, the program...
Please use Python 21. Rock, Paper, Scissors Game Write a program that let's the user play...
Please use Python 21. Rock, Paper, Scissors Game Write a program that let's the user play the game of rock, paper, scissors against the computer. The program should work as follows: 1. When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is 2, then the computer has chosen paper. If the number is 3, then the computer has chosen...
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...
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...
Suppose you play rock paper scissors against a computer: *you gain $1 for each win *you...
Suppose you play rock paper scissors against a computer: *you gain $1 for each win *you lose $1 for each lost if it is a tie, nothing happens you choose rock 50% of the time and the others 25% of the time let x be a random variable that represents the amount of money you earn after one game. (a) find the probability distribution of X (b) what is your average payoff after 20 games? (c) what is the standard...
Problem Description: You have to play the rock-paper-scissors game against the computer for 100 times. You...
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...
ROCK, PAPER, SCISSORS Using C++, you will implement a class called Tool. It should have an...
ROCK, PAPER, SCISSORS Using C++, you will implement a class called Tool. It should have an int field called strength and a char field called type. You may make them either private or protected. The Tool class should also contain the function void setStrength(int), which sets the strength for the Tool. Create 3 more classes called Rock, Paper, and Scissors, which inherit from Tool. Each of these classes will need a default constructor that sets the strength to 1 and...
Create a Java program that allows two players to play Rock, Paper, Scissors. Player 1 will...
Create a Java program that allows two players to play Rock, Paper, Scissors. Player 1 will enter an integer to determine whether they use rock, paper or scissors. Player 2 will also enter an integer to determine whether they use rock, paper or scissors. Use named constants for rock, paper and scissors and set their values as shown below. Use if-else statements to determine the results of the game. Use the named constants to compare with the player 1 and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT