I REALLY NEED HELP IN SOLVING THIS ROCK PAPER SCISSOR
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.
Core.
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
Computer: scissors
You won.
If the random choice was paper and the users chose rock, then the output would be:
Your choice: rock
Computer: paper
You lost.
If both choices were paper then the method should print out:
Your choice: paper
Computer: paper
Draw.
Complete the playRSPGame method so that it calls the the playRound method 6
times. You should use a while loop to do this.
Hints
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.
Completion
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.
Challenge
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.
Re: I REALLY NEED HELP IN SOLVING THIS ROCK PAPER SCISSOR
Please read the forum rules. Your other post has been deleted, and this one moved to a more appropriate location. Further, we are not a homework service. If you wish to get help, I recommend reading the link in my signature 'getting help' as well as http://www.catb.org/~esr/faqs/smart-questions.html
Re: I REALLY NEED HELP IN SOLVING THIS ROCK PAPER SCISSOR
Here is a suggestion
First make a prototype.
I would put in this prototype what was said and 3 variables.
Rock
Paper
Scissors.
I got you started ^-^
Re: I REALLY NEED HELP IN SOLVING THIS ROCK PAPER SCISSOR
heres what i did so far but i cant get it to give me a draw if hey are the same output!!!!
public void playRound(){
String playersChoice = UI.askString("Enter your choice");
if (playersChoice.equals("rock")){
UI.println("Your choice: rock");
}
else if (playersChoice.equals("paper")){
UI.println("Your choice: paper");
}
else if (playersChoice.equals("scissors")){
UI.println("Your choice: scissors");
}
UI.println("computer:");
if ( Math.random()<0.333) { // do something with probablity 0.333
double size = ( double )(Math.random()*1.0); // a random double between 0 and 1.0.
UI.println("rock");
}
if ( Math.random()<0.667) { // do something with probablity 0.667
double size = ( double )(Math.random()*1.0); // a random double between 0 and 1.0.
UI.println("paper");
}
else {
UI.println("scissor");
}
Code java:
< if((" Math.random()").equals("playersChoice")){
UI.println("draw");>
}
}
Re: I REALLY NEED HELP IN SOLVING THIS ROCK PAPER SCISSOR
Quote:
give me a draw if hey are the same output!!!!
What lines of the code are not working the way you want?
Please Edit your post and wrap your code with[code=java]<YOUR CODE HERE>[/code] to get highlighting
Re: I REALLY NEED HELP IN SOLVING THIS ROCK PAPER SCISSOR
Re: I REALLY NEED HELP IN SOLVING THIS ROCK PAPER SCISSOR
Re: I REALLY NEED HELP IN SOLVING THIS ROCK PAPER SCISSOR
Where is a String that holds the value chosen by the computer that you can compare with the value of playersChoice?
Why is playersChoice in "s? That is probably not what you want to compare against. You want to compare against the contents of playersChoice.
Re: I REALLY NEED HELP IN SOLVING THIS ROCK PAPER SCISSOR
well i thought that holds the computers value is math.random which is a double. What do you suggest then to fix it?
Re: I REALLY NEED HELP IN SOLVING THIS ROCK PAPER SCISSOR
You need to set a String's value according to the value returned by the random() method. You have code that prints out the computer's choice, set the value of a String there.
Re: I REALLY NEED HELP IN SOLVING THIS ROCK PAPER SCISSOR
could you tell me how please
Re: I REALLY NEED HELP IN SOLVING THIS ROCK PAPER SCISSOR
Define a String, assign it a value depending on the value of random, compare it to playersChoice.
Re: I REALLY NEED HELP IN SOLVING THIS ROCK PAPER SCISSOR
could you tell me how please bro