Question

In: Computer Science

Background: In the game “Rock, Paper, and Scissors,” two players simultaneously say (or display a hand...

Background:

In the game “Rock, Paper, and Scissors,” two players simultaneously say (or display a hand symbol representing) either “rock,” “paper,” or “scissors.” The winner is the one whose choice wins over the other. The rules are: paper wins over (wraps) rock, rock wins over (breaks) scissors, and scissors wins over (cuts) paper.

Assignment:

A customer wants you to design and implement a program (RPS.py) for playing the game of “Rock, Paper, Scissors” for a single player against the computer. The player/user is to be prompted to enter a letter representing their turn in the game: R or r for rock, P or p for paper, S or s for scissors, and Q or q for quit.  The computer will take its turn as player 2 to select a choice of rock (1 = R or r), paper (2 = P or p) or scissors (3 = S or s).

So if:

            Player enters R

            Computer randomly chooses the number 3 (aka. Scissors)

Player wins - rock wins over (breaks) scissors,

Once the program ends, it should display/output the Total Attempts, Total Valid Attempts, along with the number of human player wins, losses and ties.

Question:

1)

What would happen if the customer asked you to change the program to be Rock, Paper, Lizard, Scissors, & Spock?

From the popular TV Show The Big Bang Theory, the rules are as the character Sheldon explains, "Scissors cuts paper, paper covers rock, rock crushes lizard, lizard poisons Spock, Spock smashes scissors, scissors decapitates lizard, lizard eats paper, paper disproves Spock, Spock vaporizes rock, and as it always has, rock crushes scissors."

Describe what portion of the code/logic would need to change in the code?  How many combinations does the program need to support now?

2)Test your code and show at least 3 iterations and the final output for the original customer problem.

Solutions

Expert Solution

1) If the game of rock, paper & scissors was changed to Rock, Paper, Lizard, Scissors, & Spock, Given the rules,

"Scissors cuts paper, paper covers rock, rock crushes lizard, lizard poisons Spock, Spock smashes scissors, scissors decapitates lizard, lizard eats paper, paper disproves Spock, Spock vaporizes rock, and as it always has, rock crushes scissors."

Earlier we had one winning and losing condition for every choice rock, paper and scissiors now we have two for all the five choices Rock, Paper, Lizard, Scissors, & Spock.

Condition for tie remains the same.

Now in the code we only need to chage the conditions part to win or lose where for each of the 5 choices we have two winning and two losing conditions and one tie condition ie 5 for each choice.

2) The code and output of the original problem is given below.

import random

attempt = 0
val_attempt = 0
win = 0
lose = 0
tie = 0

while True:
        print("Enter your choice \n R or r for Rock\n P or p for Paper\n S or s for Scissor\n Q or q to Quit game")
        player = input("Player enters ")   #input players choice
        pname = "..."
        if player == 'R' or player == 'r':
                pname = "Rock"
        elif player == 'P' or player == 'p':
                pname = "Paper"
        elif player == 'S' or player == 's':
                pname = "Scissor"
        if player == 'q'  or player == 'Q':     # quit the game if q or Q
                print("Total attempts: ",attempt)
                print("Total valid attempts: ",val_attempt)
                print("Wins: ",win)
                print("Losses: ",lose)
                print("Ties: ",tie)
                break           
        attempt += 1   #count number of attempts
        if player == 'R' or player == 'r' or player == 'P' or player == 'p' or player == 'S' or player == 's':
                val_attempt += 1     
        computer = random.randint(1,3)
        comp_name = "..."          
        if computer == 1:       # Assigning rock paper and scissor for random numbers 1,2 and 3
                comp_name = "Rock"
        elif computer == 2:
                comp_name = "Paper"
        else:
                comp_name = "Scissor"
        print("Computer ranomly chooses the number",computer,"(",comp_name,")")
        if pname == comp_name:       # All conditions for tie
                tie += 1
                print("Its a tie")
        else:       # Winning and losing conditions for rock, paper and scissor
                if pname == "Rock" and comp_name == "Paper":
                        lose += 1
                        print("Player loses: Paper covers Rock")
                elif pname == "Rock" and comp_name == "Scissor":
                        win += 1
                        print("Player wins: Rock breaks Scissor")
                elif pname == "Paper" and comp_name == "Rock":
                        win += 1
                        print("Player wins: Paper covers Rock")
                elif pname == "Paper" and comp_name == "Scissor":
                        lose += 1
                        print("Player loses: Scissor cuts Paper")
                elif pname == "Scissor" and comp_name == "Rock":
                        lose += 1
                        print("Player loses: Rock breaks Scissor")
                elif pname == "Scissor" and comp_name == "Paper":
                        win += 1
                        print("Player wins: Scissor cuts Paper")
        print("-----------------------------")
                        


Related Solutions

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...
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.
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...
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...
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...
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...
Write a Java class that determines the winner of a rock, paper scissors game. Assume the...
Write a Java class that determines the winner of a rock, paper scissors game. Assume the input from the user is always valid (so no need to check), that is it contains either one of `R`, `P`, or `S` as a single character, or has matching parenthesis, like, `(S&P)` or `((R&P)&S)`, and the `&` character. So for example, the user inputs `(P&R)` and the program will output `P` since paper beats rock. Or if the user inputs `((S&R)&(S&S))` the output...
One file java program that will simulate a game of Rock, Paper, Scissors. One of the...
One file java program that will simulate a game of Rock, Paper, Scissors. One of the two players will be the computer. The program will start by asking how many winning rounds are needed to win the game. Each round will consist of you asking the user to pick between rock, paper, and scissors. Internally you will get the computers choice by using a random number generator. Rock beats Scissors, Paper beats Rock, and Scissors beats Paper. You will report...
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT