Skip to content

TanMinhPlus/Minesweeper-AI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Minesweeper-AI

💣 Minesweeper AI: CSP vs Probabilistic Reasoning

📌 Overview

This project implements an intelligent agent to solve the Minesweeper game using two independent AI approaches:

  • Constraint Satisfaction Problem (CSP)
  • Probabilistic reasoning (exact inference + Monte Carlo)

The goal is not only to solve the game, but to compare deterministic vs uncertainty-based decision making in AI systems.


🧠 AI Approaches

1. CSP-based Agent

  • Knowledge-based reasoning
  • Logical inference using constraints (sentences)
  • Identifies safe cells and mines with certainty

✔ Strength:

  • Guaranteed correctness when inference is possible

❌ Limitation:

  • Fails when uncertainty appears (no safe moves)

2. Probabilistic Agent

  • Builds constraint models from the board

  • Uses:

    • Exact inference (backtracking)
    • Monte Carlo sampling (for large states)
  • Computes probability of each cell being a mine

✔ Strength:

  • Can act under uncertainty

❌ Limitation:

  • Slower and not always optimal

⚖️ Comparison

Feature CSP Probabilistic
Deterministic
Handles uncertainty
Speed Fast Slower
Accuracy High (when solvable) Risk-based

🏗️ System Architecture

Game Engine (Minesweeper)
        ↓
AI Agent
 ├── CSP Reasoning
 └── Probabilistic Inference
        ↓
Decision Making

🎮 Features

  • Playable Minesweeper (Pygame)
  • AI autoplay mode
  • Safe vs mine visualization
  • Performance stats (win rate, speed)
  • Two independent AI agents

▶️ Installation & Run

Install dependencies

pip install pygame

Run CSP agent

python game/runner_csp.py

Run Probabilistic agent

python game/runner_probabilistic.py

📊 Example Behavior

  • CSP:

    • Plays perfectly when logic is sufficient
    • Stops when no safe move is known
  • Probabilistic:

    • Chooses lowest-risk move
    • Continues even under uncertainty

⚠️ Limitations

  • No learning (non-adaptive)
  • Performance drops on large boards
  • Probabilistic agent depends on sampling

🚀 Future Improvements

  • Hybrid AI (CSP + Probability)
  • Reinforcement Learning agent
  • Performance benchmarking system
  • Visualization dashboard

🧠 Key Takeaways

  • Difference between symbolic AI and probabilistic AI
  • Trade-offs between certainty and risk
  • Constraint modeling and inference techniques

📸 Demo

-CSP CSP

-Probability model PM


👨‍💻 Author

Pham Tan Minh


📄 License

This project is licensed under the MIT License.

About

Minesweeper AI with CSP-based logical inference and probabilistic reasoning (exact + Monte Carlo), demonstrating deterministic vs uncertainty-based decision making

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages