Skip to the content of the web site.

Project M.2: Rock-scissors-paper

Write a game to play rock-scissors-paper.

The easy way for the computer to cheat is to always pick the appropriate response to win; however, this is no fun.

If the computer randomly chooses rock, scissors or paper, then on average, there will be one-third wins, one-third draws, and one-third loses.

Instead, you should record every selection the user makes and attempt to guess what the best response should be. Note that if the user is also making random chooses, no matter what strategy you come up with, there will be, on average, one-third wins, one-third draws, and one-third loses.

Rock, scissors, paper or quit (r/s/p/q)? r
I picked paper; you lose
Rock, scissors, paper or quit (r/s/p/q)? r
I picked scissors; you win
Rock, scissors, paper or quit (r/s/p/q)? p
I picked paper; draw
Rock, scissors, paper or quit (r/s/p/q)? q
Your wins:  1
Your loses: 1
Draws:      1