Skip to content

Latest commit

 

History

History
38 lines (30 loc) · 2.12 KB

File metadata and controls

38 lines (30 loc) · 2.12 KB

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.