Rock Paper Scissors - Mrs-oc

advertisement
Rock Paper Scissors
Use logic to teach the computer how to play a game
Rock Paper Scissors
 Comes from a Japanese game
called “jan-ken”
 It’s a game usually played by two
people, where players make one
of three shapes with their hands
at the same time. The "rock"
beats scissors, the "scissors" beat
paper and the "paper" beats rock;
if both players throw the same
shape, the game is tied.
http://en.wikipedia.org/wiki/Rock-paper-scissors#Asian_origin
Objective
 To complete a Rock Paper Scissors game using BYOB that
allows a person to play against the computer.
 The game has been started for you on the compsci drive in
the Designing Tech folder.
Directions
Start BYOB
2. Open the RockPaperScissors_YourName file from the
Compsci drive in the Designing Tech folder.
3. Save it to your H: drive with your own name.
1.
Some information
 It’s easier for a computer to
work with numbers
 For this program, the
computer will assign a
number to each choice
 ROCK=0
 PAPER=1
 SCISSORS=2
 To choose the winner you
have to compare the
computer’s choice with the
player’s choice.
Try the program
 It’s not finished yet.
 Choose J, K or L and see what happens
 Is it the same every time?
 The only part missing in this program is
the code to decide who wins.
 That’s your job.
How will you decide the winner?
Algorithm 1
 If player1 chooses rock..
 If computer chooses rock
it’s a tie
 If computer chooses
scissors, then player 1 wins
because rock smashes
scissors
 If computer chooses paper
then computer wins
because paper covers rock.
Algorithm 2
 If player1 chooses rock
and computer chooses
rock it’s a tie
 If player1 chooses rock
and computer chooses
scissors, player 1 wins
because rock smashes
scissors
 If player1 chooses rock
and computer chooses
paper then computer wins
because paper covers
rock.
Can you see how these 2 algorithms are different but they both do the same thing?
What do the conditions look like?
Algorithm 1
 If player1 chooses rock..
 If computer chooses rock
it’s a tie
Algorithm 2
 If player1 chooses rock
and computer chooses
rock it’s a tie
Can you see how these 2 algorithms are different but they both do the same thing?
Choose the algorithm that makes the most sense to you.
Answer questions on Edline
 Use BYOB and the Rock Paper Scissors program to answer
the questions.
 If you can’t get into your Edline account, ask the sub for a
paper to write your answers on.
Finish the program
 Complete the code
 It’s in the computer sprite script
 Fix the part after
when I receive
determine winner.
 Make it say who wins
and why
Challenge
 Add 3 more variables and count:
 How many rounds were played
 How many times the computer wins
 How many times the player wins
Download