In: Computer Science
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.
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("-----------------------------")