Every project / Games
✂️ Rock Paper Scissors AI
Play against a computer that learns your habits and tries to predict your next move.
- Language
- Python
- Level
- Beginner
- Category
- Games
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).
| Setting | Starts at | File | What it does |
|---|---|---|---|
WINS_NEEDED | 3 | main.py | wins to take the match |
Files
| File | Lines | |
|---|---|---|
main.py | 49 | where the program starts |
Challenges
Each one is a bit harder than the last. Teachers: these make good assignment instructions.
- Change it to first to 5 wins.
- Add lizard and Spock (look up the rules!).
- Show the percentage of times the computer guessed you right.
- Make the AI smarter: predict based on your last two moves, not just your favorite.
- Add a two-player mode on one keyboard.