Question

In: Computer Science

Rock, Paper, Scissors is a two-player game in which each player chooses one of three items....

Rock, Paper, Scissors is a two-player game in which each player chooses one of three items. If both players choose the same item, the game is tied. Otherwise, the rules that determine the winner are: (a) Rock always beats Scissors (Rock crushes Scissors) (b) Scissors always beats Paper (Scissors cut Paper) (c) Paper always beats Rock (Paper covers Rock) Implement function rps() that takes the choice ('R', 'P', or 'S') of player 1 and the choice of player 2, and returns −1 if player 1 wins, 1 if player 2 wins, or 0 if there is a tie. 1

>>> rps('R', 'P') 1

>>> rps('R', 'S') -1

>>> rps('S', 'S') 0

Solutions

Expert Solution

def rps(choice_1, choice_2):
    
    #if both player enter same choice then its a tie and return 0
    if(choice_1  ==  choice_2 ):
        return 0
        
    #if player 1 choose rock and player 2 choose paper then player 2 is winner and return 1
    #if player 1 choose rock and player 2 choose scissor then player 1 is winner and return -1
    elif(choice_1 == 'R'):
        if(choice_2 == 'P'):
            return 1
        elif(choice_2 == 'S'):
            return -1
            
    #if player 1 choose scissor and player 2 choose rock then player 2 is winner and return 1
    #if player 1 choose scissor and player 2 choose paper then player 1 is winner and return -1            
    elif(choice_1 == 'S'):
        if(choice_2 == 'R'):
            return 1
        elif(choice_2 == 'P'):
            return -1
            
    #if player 1 choose paper and player 2 choose scissor then player 2 is winner and return 1 
    #if player 1 choose paper and player 2 choose rock then player 1 is winner and return -1
    elif(choice_1 == 'P'):
        if(choice_2 == 'S'):
            return 1
        elif(choice_2 == 'R'):
            return -1
        
#print the output    
print("rps('R','R'): ", rps('R','R'))
print("rps('R','P'): ",rps('R','P'))
print("rps('R','S'): ",rps('R','S'))

print("rps('P','R'): ",rps('P','R'))    
print("rps('P','P'): ",rps('P','P'))
print("rps('P','S'): ",rps('P','S'))

print("rps('S','R'): ",rps('S','R'))
print("rps('S','P'): ",rps('S','P'))
print("rps('S','S'): ",rps('S','S'))

OUTPUT:


Related Solutions

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...
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...
JAVA Remember the childhood game “Rock, Paper, Scissors”? It is a two-players game in which each...
JAVA Remember the childhood game “Rock, Paper, Scissors”? It is a two-players game in which each person simultaneously chooses either rock, paper, or scissors. Rock beats scissors but loses to paper, paper beats rock but loses to scissors, and scissors beats paper but loses to rock. Your program must prompt the player 1 and player 2 to each enter a string for their choice: rock, paper, or scissors. Then appropriately reports if “Player 1 wins”, “Player 2 wins”, or “It...
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.
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.
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...
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...
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...
write a python script for rock scissors paper game
write a python script for rock scissors paper game
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT