Every project / Games

✂️ Rock Paper Scissors AI

Play against a computer that learns your habits and tries to predict your next move.

Rock Paper Scissors AI running
Language
Python
Level
Beginner
Category
Games
▶ Try it & remix

What you'll learn

  • input() and while loops
  • Dictionaries
  • Lists as history
  • Simple prediction
  • Random choices

How it works

  • BEATS says what each move beats.
  • history records every move you make.
  • After 3 rounds, 75% of the time the AI plays whatever beats your most common move.
  • First to 3 wins takes the match.

Knobs to turn

These settings are near the top of the code. Remix it, change one, and watch what happens. The preview updates as you type (press ▶ Run for Python).

SettingStarts atFileWhat it does
WINS_NEEDED3main.pywins to take the match

Files

FileLines
main.py49where the program starts

Challenges

Each one is a bit harder than the last. Teachers: these make good assignment instructions.

  1. Change it to first to 5 wins.
  2. Add lizard and Spock (look up the rules!).
  3. Show the percentage of times the computer guessed you right.
  4. Make the AI smarter: predict based on your last two moves, not just your favorite.
  5. Add a two-player mode on one keyboard.