A Python-based Rock-Paper-Scissors game that uses Pattern Recognition and Bigram Probability to predict and counter human moves. Unlike a standard random-number-generator game, this AI "learns" your habits the more you play.
The core of this project is a predictive engine that analyzes a player's recent move history to identify non-random patterns. If a human player tends to follow "Rock" with "Paper," the AI will identify this statistical bias and play "Scissors" to win.
The AI utilizes a Behavioral Analysis model:
- Move Tracking: The last 5 moves are stored in a
deque(double-ended queue). - Bigram Frequency: The system generates "bigrams" (pairs of moves) from your history.
- Probability Mapping: It calculates the frequency of which move usually follows a specific pair.
- Counter-Strategy: It selects the move that mathematically beats your most likely next choice.
- Interactive Play: Battle the AI manually and try to outsmart its pattern recognition.
- Non-Random Test (
test204): Benchmarks the AI against a 200-round set of human-like patterned moves. - Random Test (
testrand): Benchmarks the AI against 200 rounds of pure random noise to show baseline performance.
This project is built using the Python Standard Library and requires no external dependencies, making it extremely lightweight.
- Clone the repository:
git clone [https://github.com/htrhd/Pattern-Predict-RPS.git](https://github.com/htrhd/Pattern-Predict-RPS.git)
- Run the application:
python main.py
- Data Structures:
collections.dequefor memory management andcollections.Counterfor frequency analysis. - Pattern Length: Optimized for bigram (length 2) sequences to balance memory and speed.
- Fallback Logic: If no pattern is detected, the AI reverts to a random weighted choice to remain unpredictable.
Created as a study in behavioral logic and predictive algorithms.