Part 1: A Rock Paper Scissors game.
Rock Paper Scissors is an old game known in many differenct countries. It is a two-player game, and the rules are simple - each player independently makes a choice of Scissors, Paper, or Rock. The two choices are then compared. If both players chose the same value, then the game is a draw; otherwise, Rock loses to Paper (paper can wrap a rock), Paper loses to Scissors (scissors can cut paper), and Scissors loses to Rock (a rock can make scissors blunt).
You are to write a program that plays Rock-Paper-Scissors with the user. There is a template provided for you that contains two methods. The playRound method should play a single round of Rock-Paper-Scissors with the user and reports the outcome. The playRSPGame method should play a whole game of Rock-Paper-Scissors by calling the playRound method multiple times.
Complete the playRound method so that it makes a random choice for the computer player, then asks the user for their choice, and then reports the computer's choice and whether the user won, lost, or it was a draw.
For example, if the computer's random choice was scissors and the user chose rock, then the output would be the following (note that it assumes that the user typed "rock" in response to the "Your choice: " question.
Your choice: rock
If the random choice was paper and the users chose rock, then the output would be:
Your choice: rock
If both choices were paper then the method should print out:
Your choice: paper
Complete the playRSPGame method so that it calls the the playRound method 6
times. You should use a while loop to do this.
To make a random choice, use the Math.random() method to get a random number (double) between 0.0 and 1.0. If the number is less than 0.333, then make one choice; if the number is greater than 0.667, make the second choice, otherwise make the third choice.
There are quite a lot of cases to handle (9 possible combinations), and therefore your method may be quite long in order to check all of them.
Modify the playRound method so that it also returns an integer which is the score for the user: 1 if the user won, -1 if the user lost, and 0 if it was a draw. Remember that you must specify the type ( int) returned by the method, and you must also have a return statement to return the value.
Modify the playRSP method so that it will play rounds (by calling playRound), keeping track of the total score of the user, until the user reaches a score of 5 or -5. You will need a variable to keep track of the score, and a while loop that repeatedly calls playRound, adding the result to the score, as long as the score is between -5 and 5.
Modify the program to keep track of what the user has chosen in the past, and analyse those choices in order to improve the computer's choice. For example, if the user chooses paper more than 1/3 of the time, then the computer will do better to choose scissors. A more sophisticated analysis would look for patterns in the sequence of choices and try to predict the user.