Minesweeper AI is an interactive PyQt6-based Minesweeper game with manual play, AI-assisted solving, and rule-based hints. It combines classic gameplay with modern AI agents (CNN & RL) trained on thousands of game sessions.
Players can switch between Manual Mode 🎮 and AI Mode 🤖, featuring smooth UI, sounds, and animations.
- 🎮 Manual Play – Classic Minesweeper with smooth UI and sounds
- 🤖 AI Mode – Let a trained CNN/RL agent play for you
- 🧩 Rule-Based Solver – AI-powered hints explain safe/unsafe moves
- 🔔 Sound Effects & Animations – Interactive experience with explosions, flags, and victory sounds
- 📊 Score System – Separate high scores for Manual & AI play
- 📂 Sample Datasets – Included JSON/NPZ files to showcase AI training
- 💻 Cross-Platform – Works on macOS (DMG installer available) & Windows (Portable EXE available)
| Platform | Format | Python Required |
|---|---|---|
| macOS | .dmg |
❌ No |
| Windows | .zip (Portable EXE) |
❌ No |
| Source | GitHub | ✅ Yes (3.10+) |
For macOS users, you can directly install the game without running from source.
👉 Download Minesweeper-macOS-Installer.dmg
-
Double-click the .dmg file.
-
Drag Minesweeper.app into the Applications folder.
-
Launch the app from the Applications folder.
ℹ️ If macOS Gatekeeper blocks the app on first launch, go to System Settings → Privacy & Security and allow it manually.
For Windows users, Minesweeper AI is distributed as a portable executable package.
👉 Download: Minesweeper-Windows-Installer.zip
- Download
Minesweeper-Windows-Installer.zip - Extract the ZIP file.
- After extraction, open the newly created folder.
- Double-click
MinesweeperAI.exeto launch the game.
✅ No installation required
✅ No administrator permissions needed
✅ Works offline
The extracted folder will look like this:
MinesweeperAI.exe→ Main application_internal/→ Required libraries, AI models, sounds, and assets
_internal folder, as the application depends on it.
To uninstall the game, simply delete the extracted folder.
This portable setup is the Windows equivalent of a macOS DMG drag-and-drop app.
| Component | Technology Used |
|---|---|
| GUI | PyQt6 |
| Game Logic | Custom Python (env, hints) |
| AI Models | TensorFlow (CNN & RL) |
| Dataset Format | NumPy (.npz, JSON) |
| Sounds/Graphics | WAV, GIF, PNG assets |
📂 Here's how the core directory looks:
Minesweeper/
├── main.py
├── game_ui.py
├── game_ai.py
├── game_manual.py
│
├── ai/
│ ├── ai_agent.py
│ └── rule_based_solver.py
│
├── core/
│ ├── hint_manager.py
│ ├── minesweeper_env.py
│ ├── scoreManager.py
│ ├── settingsManager.py
│ └── soundManager.py
│
├── assets/
│ ├── icons/
│ ├── sounds/
│ ├── dmg_background.png
│ ├── explosion.gif
│ └── flame.gif
│
├── data/
│ ├── sessions_sample.json
│ ├── game_sample1.json
│ └── game_sample2.json
│
├── dataset/
│ └── final_moves_dataset.npz
│
├── model/
│ ├── final_rl_model.keras
│ └── minesweeper_cnn_model.keras
│
├── json/
│ ├── settings.json
│ ├── highscore_manual.json
│ └── highscore_ai.json
│
├── Minesweeper-Installer.dmg
├── requirements.txt
├── .gitattributes
├── .gitignore
└── README.mdOur full training process (CNN, RL, Hint reasoning) is documented in Kaggle notebooks.
Sample data (.npz) is included in this repo. Full datasets are available via Kaggle links above.
If you only want to play the game, prefer the Windows EXE or macOS DMG. Running from source is intended for development, research, or training the AI models.
git clone https://github.com/DSinghania13/Minesweeper-AI.git
cd Minesweeper-AIpython -m venv .venv
# macOS / Linux
source .venv/bin/activate
# Windows
.venv\Scripts\activatepip install -r requirements.txtpython main.py- Manual Mode → Play Minesweeper yourself
- AI Mode → Watch the AI solve in real-time
- Python 3.10+
- PyQt6
- numpy
- tensorflow (required for AI mode)
Note:
- Development was done on macOS using Python 3.13
- Windows builds require Python 3.10 for stability (TensorFlow, PyInstaller, and PyQt6 are most stable on Windows with Python 3.10)
- Windows EXE → No Python required
- macOS DMG → No Python required
The performance of the AI is evaluated in two parts: the overall Reinforcement Learning (RL) agent's ability to win the game, and the underlying CNN's effectiveness at predicting mine locations.
1. Reinforcement Learning (RL) Agent Performance
The RL agent was trained over ~15,000 games to learn a winning strategy.
Learning Progress
The agent's learning is demonstrated by the cumulative win rate, which starts volatile and stabilizes as the agent gains experience. This shows a clear, positive learning trend.
Final Win Rate
After training, the agent achieves a stable win rate of 30.4%, a strong performance for a game with high uncertainty.
Behavioral Analysis
Analysis of lost games shows that the AI is most vulnerable in the early stages, with 66.5% of losses occurring within the first 10 moves. This suggests that the agent's primary weakness is navigating the sparse information available at the beginning of a game.
2. CNN Model Performance (Mine Prediction)
The CNN acts as a fallback to predict mine probabilities when no logically safe move exists. Its performance is measured on a highly imbalanced dataset (many more safe cells than mines).
Classification Report & Confusion Matrix
The model achieves 99% accuracy, but this is misleading due to the class imbalance. The key metrics are precision and recall for the "Mine" class.
--- Classification Report ---
precision recall f1-score support
Not a Mine 0.99 1.00 1.00 727559
Mine 0.73 0.04 0.08 4519-
Precision (Mine) = 0.73: When the CNN predicts a mine, it's correct 73% of the time.
-
Recall (Mine) = 0.04: The CNN only finds 4% of all actual mines.
This shows the model is risk-averse: it avoids guessing "Mine" unless it is very confident, making it good for finding the safest move, but not for identifying all mines.
Precision-Recall Curve
This curve is the most honest view of the model's performance on an imbalanced dataset. It shows that to achieve higher precision (certainty), the model must sacrifice recall (finding all mines). This trade-off is central to its risk-averse strategy.
- 🎓 Transformer-based reasoning for complex board states
- 🌍 Online leaderboard & multiplayer mode
- 📦 Optional Windows installer (Inno Setup) for Start Menu integration
- 🧠 Improved AI-human interaction with explainable move reasoning
Minesweeper is easy to play, but hard to master. With AI, it becomes a whole new challenge.
This project is licensed under the MIT License.
You are free to use, modify, and distribute this software with proper attribution.












