Overview
Rock Paper Scissors (Piedra, Papel o Tijeras) is a timeless game of chance where you compete against the computer. Make your choice and see if you can outsmart the AI! The game tracks your score across multiple rounds and maintains a complete match history.This implementation includes balloons animation when you win - celebrate your victories! 🎉
How to Play
Game Rules
The classic triangle of victory:- 🪨 Rock beats Scissors (Rock crushes scissors)
- ✂️ Scissors beats Paper (Scissors cut paper)
- 📄 Paper beats Rock (Paper covers rock)
- Same choice = Tie
Game Interface
The game displays: Scoreboard:- Your wins counter
- Computer wins counter
- Reset button to start fresh
- Three large, emoji-labeled buttons for Rock, Paper, and Scissors
- Instant result display
- Last 5 rounds displayed
- Shows your choice vs computer choice
- Result of each round
Implementation Details
Core Game Logic
The winner determination is handled by a simple but effective function:streamlit_game.py:4
- Check if both choices are identical → Tie
- Check all three winning combinations for the user
- If none match → Computer wins
Why This Logic Works
Why This Logic Works
The function covers all 9 possible outcomes:
By checking the 3 user-win conditions, we implicitly handle the 3 computer-win conditions in the else clause!
| User | Computer | Result |
|---|---|---|
| Rock | Rock | Tie |
| Rock | Paper | Computer |
| Rock | Scissors | User |
| Paper | Rock | User |
| Paper | Paper | Tie |
| Paper | Scissors | Computer |
| Scissors | Rock | Computer |
| Scissors | Paper | User |
| Scissors | Scissors | Tie |
Game Initialization
streamlit_game.py:14
rps_user_score: Your win countrps_computer_score: Computer’s win countrps_round_result: Latest round outcome messagerps_history: List of all round results (newest first)
Scoreboard Display
Metrics provide a clean, professional look:streamlit_game.py:26
- Column 1: User score with Streamlit metric widget
- Column 2: Computer score with metric widget
- Column 3: Reset button
Interactive Button Grid
Large, emoji-enhanced buttons make choices clear:streamlit_game.py:36
use_container_width=True makes buttons expand to fill their column, creating a visually appealing grid.
Round Processing
When a choice is made:streamlit_game.py:46
- Computer randomly selects from three options
- Determine winner using
get_winner() - Build result message with both choices
- Update appropriate score counter
- Add special effects (balloons for user win)
- Store result in history (insert at position 0 for newest-first)
st.balloons() is a fun Streamlit feature that displays falling balloons animation - perfect for celebrations!History Display
Recent matches are shown below the game:streamlit_game.py:69
- Only shows last 5 rounds (
:5slice) - Newest rounds appear at the top
- Simple text format for quick scanning
Example History
Example History
Tips & Strategy
Is There a Winning Strategy?
Is There a Winning Strategy?
Against a truly random computer opponent, all choices are equally likely to win. The game is pure chance with:
- 33.3% chance to win
- 33.3% chance to lose
- 33.3% chance to tie
- Tracking patterns (though this computer is random)
- Setting win goals (first to 5, first to 10)
- Playing best-of series
Common Psychological Patterns
Common Psychological Patterns
Against human opponents, players often:
- Open with Rock (most common first choice)
- Avoid repeating after a loss
- Stick with winners (repeat winning choices)
Making It Competitive
Making It Competitive
Set challenges for yourself:
- Can you win 3 games before losing 3?
- Can you maintain a winning record over 20 rounds?
- Track your long-term win rate (should approach 33%)
- Speed challenge: How many wins in 2 minutes?
Code Architecture
Session State Management
| Variable | Type | Purpose |
|---|---|---|
rps_user_score | int | Cumulative user wins |
rps_computer_score | int | Cumulative computer wins |
rps_round_result | str | Most recent round message |
rps_history | list | All round results (newest first) |
Randomness Source
The computer’s choice uses Python’srandom module:
streamlit_game.py:48
random.choice() provides uniform distribution - each option has exactly 1/3 probability.
UI Components Breakdown
Metric Widgets
Streamlit’s metric component provides clean score display:- Large, prominent numbers
- Built-in styling
- Professional appearance
- Optional delta indicators (not used here)
Success/Error Messages
The result is displayed with appropriate styling:streamlit_game.py:66
st.success()for winsst.error()for lossesst.info()for ties
Dividers
Visual separation improves readability:streamlit_game.py:33
Game Flow Diagram
Enhancements & Variations
Best of X Series
Best of X Series
Add a match system:
Add Rock-Paper-Scissors-Lizard-Spock
Add Rock-Paper-Scissors-Lizard-Spock
Expand to 5 choices (popularized by The Big Bang Theory):
- Rock crushes Scissors and Lizard
- Paper covers Rock and disproves Spock
- Scissors cuts Paper and decapitates Lizard
- Lizard eats Paper and poisons Spock
- Spock vaporizes Rock and smashes Scissors
Statistics Dashboard
Statistics Dashboard
Track additional metrics:
- Win percentage
- Most used choice
- Current win/loss streak
- Choice distribution chart
Difficulty Modes
Difficulty Modes
Create different AI behaviors:
- Easy: Computer favors losing choices
- Normal: Pure random (current)
- Hard: Computer favors winning choices against player’s most-used option
- Psychic: Computer analyzes player patterns
Fun Facts
Rock Paper Scissors has been used to settle:
- A $20 million art auction (Sotheby’s vs Christie’s)
- Court custody disputes
- Business partnership decisions
- Professional sports coin toss alternatives