A Python implementation of the classic Minesweeper game, enhanced with an AI player that learns and deduces safe moves to intelligently play the game. The AI uses logical inference to mark cells as safe or as mines and makes random moves when necessary.
This repository is one of the projects in CS50 AI with Python course.
- Classic Minesweeper Gameplay: Play the traditional game on an
8x8grid. - AI Player:
- Learns from each move and builds a knowledge base.
- Deduces safe moves and mines based on game rules.
- Makes random moves only when no guaranteed safe moves are available.
- Customizable Grid: Adjust the size of the game grid.
The AI leverages logical inference through the following mechanisms:
- Knowledge Base: Stores sentences about the state of the game, including:
- Which cells are safe.
- Which cells contain mines.
- Marking Safe/Mine Cells: Based on the information provided by the game, the AI deduces which neighboring cells are safe or contain mines.
- Move Decision:
- Chooses a move known to be safe.
- If no safe moves are available, chooses a random cell that is not already a known mine.
- Clone the repository:
git clone https://github.com/yourusername/minesweeper-ai.git
cd minesweeper-aiEnsure Python 3.x is installed on your system. Install any dependencies:
pip install -r requirements.txt Run the game:
python runner.py