Skip to content

Latest commit

Β 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Adaptive Rock-Paper-Scissors AI 🧠

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.

πŸš€ Overview

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.

🧠 How the Prediction Works

The AI utilizes a Behavioral Analysis model:

  1. Move Tracking: The last 5 moves are stored in a deque (double-ended queue).
  2. Bigram Frequency: The system generates "bigrams" (pairs of moves) from your history.
  3. Probability Mapping: It calculates the frequency of which move usually follows a specific pair.
  4. Counter-Strategy: It selects the move that mathematically beats your most likely next choice.

πŸ“Š Modes

  • 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.

πŸ› οΈ Requirements & Installation

This project is built using the Python Standard Library and requires no external dependencies, making it extremely lightweight.

  1. Clone the repository:
    git clone [https://github.com/htrhd/Pattern-Predict-RPS.git](https://github.com/htrhd/Pattern-Predict-RPS.git)
  2. Run the application:
    python main.py

πŸ“ˆ Technical Implementation

  • Data Structures: collections.deque for memory management and collections.Counter for 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.

About

A Rock-Paper-Scissors AI that uses pattern recognition and bigram frequency analysis to predict and counter human moves in real-time.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages