RE: rock scissors paper 11-04-2013, 01:26 AM
#11
@ArkPhaze well it's hard for me to understand what u did it's another language i guess its c++ am i right ?
| rock scissors paper filter_list | |
(11-04-2013, 01:26 AM)blackeagle Wrote: @ArkPhaze well it's hard for me to understand what u did it's another language i guess its c++ am i right ?
(11-04-2013, 01:40 AM)blackeagle Wrote: @ArkPhaze i didnt understand what u meant by you don't have to compare values individually like that for every outcome. You can use math to your advantage !!
The way my code works, I calculate the output as probability that the CPU had already won. Depending on if the CPU lost, won, or had a draw with your user input, depends on what I calculate after the fact, for the CPU's choice.
but i guess this is a little hard for me and i guess it's not that bad my way
lol i'm very tired for now i might work on ur idea 2mw thx for the help
(11-04-2013, 12:52 AM)Frooxius Wrote: Just a quick suggestion: Try multiplying the random change by 3, so you don't have to compare it against fractional numbers. Like this:
Code:public static String pcChoice() { double random = Math.random()*3; String choicePc = null; if (random <= 1) { choicePc = "rock"; } if ((random > 1) && (random <= 2)) { choicePc = "paper"; } if (random > 3) { choicePc = "scissors"; } return choicePc; }
while ((!choice.equalsIgnoreCase("rock")) && (!choice.equalsIgnoreCase("paper")) && (!choice.equalsIgnoreCase("scissors")))private boolean isValidChoice(String choice) {
//your code
}while(isValidChoice(choice)) {
} while (playAgain.equalsIgnoreCase("y"));
if (playAgain.equals("n")) {
System.out.println("thx for playing");
}![[Image: 2YpkRjy.png]](http://i.imgur.com/2YpkRjy.png)
Quote:and finally can you tell me why do i need to make methods if i'm using them only once !!
![[Image: 2YpkRjy.png]](http://i.imgur.com/2YpkRjy.png)
(11-04-2013, 02:33 PM)Slarek Wrote: @Deque
I didn't quite understand why you mentioned me
since i have no posts in this thread.
![[Image: 2YpkRjy.png]](http://i.imgur.com/2YpkRjy.png)