Skip to content

Latest commit

 

History

History
57 lines (38 loc) · 1.12 KB

rps.md

File metadata and controls

57 lines (38 loc) · 1.12 KB

Rock Paper Scissors

When two people play rock paper scissors, someone wins, loses, or they tie.

There are 9 combinations.

For Player 1:

Player 1 Rock Paper Scissors
Rock Tie Lose Win
Paper Win Tie Lose
Scissors Lose Win Tie

We will code Human vs Computer.

Computer generates random numbers so we will use 0, 1, 2, instead of Rock, Paper, or Scissors.

Random random = new Random();

random.nextInt(3);

The computer will choose either 0, 1, or 2.

Human will choose using Scanner.

Below is a chart of human's wins and losses.

|Computer|

Human 0: Rock 1: Paper 2: Scissors
Rock Tie Lose Win
Paper Win Tie Lose
Scissors Lose Win Tie

Each condition will have its own if statement.

if (computer == 0) {
    if (human == 0) ...
    if (human == 1) ...
    if (human == 2) ...
} 


if (computer == 1) {
    ...
} 

Better RPS

You will notice that when human == computer, the game is a tie.

Using some math you can also figure out that when human is one more than computer, the game can be a win or a lose...