Skip to content

A classic Minesweeper game implemented in Python, featuring both a human-playable version and an AI player capable of strategic moves.

Notifications You must be signed in to change notification settings

RTS-Technology-Solutions/MinesweeperAI

Repository files navigation

Minesweeper AI Learning Project 🎯

Python License Beginner Friendly

A comprehensive Minesweeper AI implementation designed as a learning project for new programmers. This project demonstrates fundamental AI concepts including constraint satisfaction problems (CSP), probability estimation, and logical reasoning.

Minesweeper AI Demo

🎮 What You'll Learn

  • Game Logic Implementation: Understanding how Minesweeper works internally
  • AI Decision Making: Implementing safe move detection and probability-based reasoning
  • Constraint Satisfaction Problems: Using logical constraints to solve puzzles
  • Python Programming: Object-oriented programming, data structures, and algorithms
  • GUI Development: Both console and graphical interfaces using Tkinter

📁 Project Structure

minesweeper-ai/
├── README.md                      # This file
├── CONTRIBUTING.md                # How to contribute to the project
├── requirements.txt               # Python dependencies
├── docs/                          # Detailed documentation
│   ├── GETTING_STARTED.md        # Step-by-step beginner guide
│   ├── AI_CONCEPTS.md            # AI concepts explained
│   ├── API_REFERENCE.md          # Code documentation
│   └── TUTORIALS.md              # Learning exercises
├── src/                          # Main source code
│   ├── __init__.py
│   ├── minesweeper_game.py       # Core game logic
│   ├── minesweeper_ai.py         # AI implementation
│   └── gui/                      # GUI components
│       ├── __init__.py
│       └── game_gui.py           # Tkinter interface
├── examples/                     # Example scripts and demos
│   ├── basic_game.py            # Simple game example
│   ├── ai_demo.py               # AI demonstration
│   └── interactive_tutorial.py  # Guided learning script
├── tests/                       # Unit tests
│   ├── __init__.py
│   ├── test_game.py
│   └── test_ai.py
└── assets/                      # Game assets
    └── icons/
        ├── logo.png
        ├── mine.png
        └── sad.png

🚀 Quick Start

Prerequisites

  • Python 3.7 or higher
  • Basic understanding of Python (variables, functions, classes)
  • Enthusiasm to learn! 🎉

Installation

  1. Clone or download this repository

    git clone https://github.com/your-username/minesweeper-ai.git
    cd minesweeper-ai
  2. Install dependencies (currently none required for basic functionality)

    pip install -r requirements.txt
  3. Run the basic game

    python examples/basic_game.py
  4. Try the AI

    python examples/ai_demo.py

🎯 Learning Path

Beginner (Week 1-2)

  1. Understand the Game: Play the basic Minesweeper to understand rules
  2. Read the Code: Study minesweeper_game.py to understand game mechanics
  3. Complete Tutorial 1: Basic game modifications in docs/TUTORIALS.md

Intermediate (Week 3-4)

  1. Study AI Basics: Read docs/AI_CONCEPTS.md
  2. Implement Safe Moves: Complete the is_safe_move function
  3. Complete Tutorial 2: Add simple AI logic

Advanced (Week 5-6)

  1. Constraint Satisfaction: Implement CSP-based reasoning
  2. Probability Estimation: Add probabilistic move selection
  3. Complete Tutorial 3: Build a complete AI solver

🤖 AI Features

Current Implementation

  • ✅ Basic game interface
  • ✅ Safe move detection framework
  • ✅ Cell tracking (uncovered/flagged)
  • ⚠️ TODO: CSP reasoning logic
  • ⚠️ TODO: Probability estimation
  • ⚠️ TODO: Advanced strategies

Planned Features

  • 🔲 Multiple AI difficulty levels
  • 🔲 Performance analytics
  • 🔲 Interactive learning mode
  • 🔲 Tournament mode (AI vs AI)
  • 🔲 Web interface

💻 Code Examples

Basic Game Usage

from src.minesweeper_game import Minesweeper

# Create a 9x9 board with 10 mines
game = Minesweeper(9, 9, 10)

# Make moves
result = game.uncover(4, 4)  # Uncover center cell
game.flag(0, 0)              # Flag a suspected mine

# Print current state
game.print_board()

AI Usage

from src.minesweeper_game import Minesweeper
from src.minesweeper_ai import MinesweeperAI

# Create game and AI
game = Minesweeper(9, 9, 10)
ai = MinesweeperAI(game)

# Let AI make a move
ai.make_move()
game.print_board()

🧠 Key AI Concepts

  1. Constraint Satisfaction Problem (CSP)

    • Using numbered cells to constrain mine locations
    • Logical deduction from partial information
  2. Probability Estimation

    • When logic isn't enough, estimate mine probabilities
    • Choose moves with lowest risk
  3. Frontier Analysis

    • Focus on border between known and unknown areas
    • Most information gained from frontier cells

🤝 Contributing

We welcome contributions from learners at all levels! See CONTRIBUTING.md for details.

Ways to Contribute

  • 🐛 Report bugs or issues
  • 💡 Suggest new features or improvements
  • 📚 Improve documentation
  • 🧪 Add test cases
  • 🎨 Enhance the GUI
  • 🏆 Create new tutorials or examples

📚 Additional Resources

🏆 Challenges

Try these challenges as you learn:

  1. Beginner: Make the AI solve a 9x9 board with 90% success rate
  2. Intermediate: Implement different difficulty levels for the AI
  3. Advanced: Create an AI that can solve expert-level boards efficiently
  4. Expert: Build a neural network-based Minesweeper solver

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • Original Minesweeper game concept by Microsoft
  • Inspired by various AI learning resources and tutorials
  • Thanks to the Python community for excellent documentation

Happy Learning! 🎓

Remember: The goal isn't just to build a working AI, but to understand the concepts and have fun while learning!

About

A classic Minesweeper game implemented in Python, featuring both a human-playable version and an AI player capable of strategic moves.

Topics

Resources

Contributing

Stars

Watchers

Forks

Languages