Question: Dear Chegg, Appreciate your help with the code in python! Thanks! Question 2 'Paper, Scissors, Rock, Lizard, Spock (35 marks) In this Question, you can
Dear Chegg,
Appreciate your help with the code in python!
Thanks!


Question 2 'Paper, Scissors, Rock, Lizard, Spock (35 marks) In this Question, you can import any packages or functions. We all know the game 'paper, scissors, rock', and now we have an extended version of paper, scissors, rock, lizard, Spock'. The following two diagrams illustrate how to play and which' wins 'which'. Basically, for each of the arrows below, the starting point of the arrow wins the end of the arrow. dumps cuts pocker Scissors Scissors decapital lizard eludes er derovestock short circuits Paper Spock blunts wapices ok blocks fongs covers hes bums paper covers Radio Izard Rock por breaks Lizard Recrushes To simplify our implementation, we use the numbers 0 to 4 to represent the above entities. And it sums up in a dictionary given in the skeleton code: psrlsdict = {0:'scissor', 1:'paper', 2: 'rock',3:'lizard', 4: 'Spock'} Notice that our dictionary follows the clockwise order of the above diagrams. Task 4 Be the Judge of the Game (10 marks) Assume that there are two players, namely, Player 1 and Player 2. With the inputs as plmove and p2move that are two numbers that represent the moves, write a function psrisWhoWin (plmove, p2move) to decide who wins. Your function will return the player number, either 1 or 2, if one of them wins. However, if it's a tie, return O instead. You assume the two inputs are always within the range from 0 to 4. Sample output: >>> print (psrlsWhoWin (2,4)) >>> print (psrlsWhoWin (4,0)) 2 >>> print (psrlsWhoWin (2,3)) >>> print (psrlsWhoWin(1,1)) 1 1 Task 5 Play it N times (10 marks) The two players decide to play a match N times. So the moves of each player is given in a list of N numbers. For example: pimoves = p2moves = [1,2,3,0,4,4,0] [2,4, 1,4,3,0,2] Assuming that both players will play according to the order in the sequences. Write a function nPlWins (pimoves, p2moves) that will return the number of wins by Player 1. So this function will return 3 for the above inputs. You will only gain full marks if your answer in the previous Task (Task 4) is correct. Task 6 (Extra hard) Rearranging the Moves of Player 1 (15 marks) After playing Ntimes as the above. Player 1 has this special power that he can go back in time and rearrange his moves. And he can only rearrange the moves instead of changing any moves arbitrarily. If Player 1 changes his moves as: [1,2,3,0,4,4,01 [4,1,0,3,0,2,41 Player 1 can win all 7 times instead of 3 in the previous game!!! Write a function findWinningSeg (plmoves, p2moves) to return a list of lists that includes all the sequences that can maximize the number of wins by Player 1. Here are some sample outputs. pimoves - (3,2,1] >>> p2moves = [1,2,3] >>> print (nPlWins (pimoves, p2moves) ) >>> newplmoves = findWinningsea (pimoves, p2moves) >>> print (newpimoves) [[3, 1, 2]] >>> print (nPlWins (newplmoves (01, p2moves)) 1 3 >>> plmoves 11,2,3,0,4,4,01 >>> p2moves = [2,4, 1,4,3,0,21 >>> print (nPiWins (plmoves, p2moves) ) 3 >>> newplmoves = findWinningSeg (plmoves, p2moves) >>> print (newplmoves) 114, 1, 0, 3, 0, 2, 4], [4, 3, 0, 1, 0, 2, 411 >>> print (nPlWins (newplmoves 101, p2moves) ) 7 Submission for Question 2 You should submit the following three functions: psrisWhoWin (plmove, p2move), nelWins (plmoves, p2moves), findWinningSeo (plmoves, p2moves) Question 2 'Paper, Scissors, Rock, Lizard, Spock (35 marks) In this Question, you can import any packages or functions. We all know the game 'paper, scissors, rock', and now we have an extended version of paper, scissors, rock, lizard, Spock'. The following two diagrams illustrate how to play and which' wins 'which'. Basically, for each of the arrows below, the starting point of the arrow wins the end of the arrow. dumps cuts pocker Scissors Scissors decapital lizard eludes er derovestock short circuits Paper Spock blunts wapices ok blocks fongs covers hes bums paper covers Radio Izard Rock por breaks Lizard Recrushes To simplify our implementation, we use the numbers 0 to 4 to represent the above entities. And it sums up in a dictionary given in the skeleton code: psrlsdict = {0:'scissor', 1:'paper', 2: 'rock',3:'lizard', 4: 'Spock'} Notice that our dictionary follows the clockwise order of the above diagrams. Task 4 Be the Judge of the Game (10 marks) Assume that there are two players, namely, Player 1 and Player 2. With the inputs as plmove and p2move that are two numbers that represent the moves, write a function psrisWhoWin (plmove, p2move) to decide who wins. Your function will return the player number, either 1 or 2, if one of them wins. However, if it's a tie, return O instead. You assume the two inputs are always within the range from 0 to 4. Sample output: >>> print (psrlsWhoWin (2,4)) >>> print (psrlsWhoWin (4,0)) 2 >>> print (psrlsWhoWin (2,3)) >>> print (psrlsWhoWin(1,1)) 1 1 Task 5 Play it N times (10 marks) The two players decide to play a match N times. So the moves of each player is given in a list of N numbers. For example: pimoves = p2moves = [1,2,3,0,4,4,0] [2,4, 1,4,3,0,2] Assuming that both players will play according to the order in the sequences. Write a function nPlWins (pimoves, p2moves) that will return the number of wins by Player 1. So this function will return 3 for the above inputs. You will only gain full marks if your answer in the previous Task (Task 4) is correct. Task 6 (Extra hard) Rearranging the Moves of Player 1 (15 marks) After playing Ntimes as the above. Player 1 has this special power that he can go back in time and rearrange his moves. And he can only rearrange the moves instead of changing any moves arbitrarily. If Player 1 changes his moves as: [1,2,3,0,4,4,01 [4,1,0,3,0,2,41 Player 1 can win all 7 times instead of 3 in the previous game!!! Write a function findWinningSeg (plmoves, p2moves) to return a list of lists that includes all the sequences that can maximize the number of wins by Player 1. Here are some sample outputs. pimoves - (3,2,1] >>> p2moves = [1,2,3] >>> print (nPlWins (pimoves, p2moves) ) >>> newplmoves = findWinningsea (pimoves, p2moves) >>> print (newpimoves) [[3, 1, 2]] >>> print (nPlWins (newplmoves (01, p2moves)) 1 3 >>> plmoves 11,2,3,0,4,4,01 >>> p2moves = [2,4, 1,4,3,0,21 >>> print (nPiWins (plmoves, p2moves) ) 3 >>> newplmoves = findWinningSeg (plmoves, p2moves) >>> print (newplmoves) 114, 1, 0, 3, 0, 2, 4], [4, 3, 0, 1, 0, 2, 411 >>> print (nPlWins (newplmoves 101, p2moves) ) 7 Submission for Question 2 You should submit the following three functions: psrisWhoWin (plmove, p2move), nelWins (plmoves, p2moves), findWinningSeo (plmoves, p2moves)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
