Exploring Algorithms:
Meet Minesweeper AI

GitHub license GitHub issues GitHub stars GitHub forks

App Demo

Introduction

This is the homepage of the project. The repository contains two distinct Python Projects, Combining Cellular Automata with Game Development. The projects are as follows:

  1. CrossFinder: An innovative variant of Conway's Game of Life, meticulously engineered to detect and manipulate cross shapes. Diverging from the conventional Game of Life, CrossFinder integrates additional states and tailor-made rules aimed at pinpointing and transforming cross-shaped patterns.
  2. Minesweeper: A Python implementation of the classic Minesweeper game with a graphical user interface (GUI) using Matplotlib and NumPy. This project includes additional features like reset, hint, next, and undo buttons.

Both projects utilize basic Python libraries such as NumPy and Matplotlib, and were originally designed to run in a local environment.

Note: The projects can now be run via the browser. For more information, please visit the GitHup repo for this repository.

Table of Contents

Minesweeper

A Python implementation of the classic Minesweeper game with a graphical user interface (GUI) using Matplotlib and NumPy. This project includes additional features like reset, hint, next, and undo buttons.

Minesweeper

Minesweeper Features

Installation

  1. Clone the repository:
    git clone https://github.com/Dor-sketch/CrossFinder
    cd CrossFinder
  2. Install the required packages:
    pip install -r requirements.txt

Usage

  1. Run the Minesweeper game:
    python3 mines.py
  2. Play the game using the GUI:
    • Left-click to reveal a cell.
    • Right-click to flag a cell as a mine.

Gameplay Demo

Watch the video here

Gameplay Instructions

Objective: Reveal all non-mine cells without hitting a mine.

Cells:

Buttons:

Minesweeper Gameplay

How the Minesweeper Solver Works

The states of each cell are reduced to three categories: hidden, flagged, or revealed. The solver iterates over the visible grid, applies game rules, and reveals cells based on the rules. The solver uses a custom rule set inspired by Conway's Game of Life to reveal hidden cells.

graph TD A[Start transition] --> B[Iterate over visible grid] B --> C[Check if cell is not flagged or hidden] C -->|Yes| D[Apply game rules] D --> E[End transition] C -->|No| F[Move to next cell] F --> B D --> G[Start apply_rules] G --> H[Get neighboring cells] H --> I[Calculate number of mines and hidden cells in neighborhood] I --> J[Check if number of hidden cells and mines equals cell value] J -->|Yes| K[Flag hidden cells] K --> L[End apply_rules] J -->|No| M[Check neighboring cells] M --> N[Check if number of mines equals cell value] N -->|Yes| O[Mark cells as safe] O --> L N -->|No| P[Move to next cell] P --> M

Note: The solver might not proceed without revealing more cells that might be mines.

CrossFinder

CrossFinder is an innovative variant of Conway's Game of Life, meticulously engineered to detect and manipulate cross shapes within a grid environment. Diverging from the conventional Game of Life, CrossFinder integrates additional states and tailor-made rules aimed at pinpointing and transforming cross-shaped patterns.

This ingenious program was conceived as a response to problem 28 in the seminal book Biological Computation by Ehud Lamm and Ron Unger. It was developed as a key component of the "Biological Computation" course at the Open University of Israel. The solution, amalgamated with another program (simulationEarth), was submitted and acclaimed with a perfect score of 100.

Watch the video here

Finder Features

How the CrossFinder Works

The CrossFinder program operates on a grid where cells can transition between states based on their neighbors. The primary focus is on identifying and marking cross shapes. A cross is defined as a vertical and horizontal line intersecting at a central cell, all of which are alive (1). When a cross is detected, the cells constituting the cross transition to the state 2 (red), signifying the first wave of detection.

CrossFinder CrossFinder

Visualization of the CrossFinder simulation waves: Algorithm identify target '+' shape

Rules Overview

How the CrossFinder Works

The CrossFinder program operates on a grid where cells can transition between states based on their neighbors. The primary focus is on identifying and marking cross shapes. A cross is defined as a vertical and horizontal line intersecting at a central cell, all of which are alive (1). When a cross is detected, the cells constituting the cross transition to the state 2 (red), signifying the first wave of detection.

CrossFinder CrossFinder

Visualization of the CrossFinder simulation waves: Algorithm identify target '+' shape

Rules Overview

How to Run the CrossFinder

The program was tested on python 3.11 and requires the following packages:

Use the following command to run the program:

python3 cross_game.py

If more than one python version is installed, try using the following command:

python3.11 cross_game.py

CrossFinder GUI

The program supports both randomized initial states (press reset button) and user interactive controls (press the matrix cells to change their state).

For the next generation, press next Day button.

Switching Modes

Switch to Conway's Game of Life from the CrossFinder and vice versa by simply clicking the mode button.

Watch the video here

Running Examples

Example 1
Initial state 2 3 4 Finale state
Example 1 Example 1 Example 1 Example 1 Example 1
Example 2

Initial state - 2nd example: 2 valid crosses in different sizes

Initial state 2 3 Finale state
Example 2 Example 2 Example 2 Example 2
Example 3

Complex destruction example - no valid crosses

1 2 3 4
Example 3 Example 3 Example 3 Example 3
5 6 7 8
Example 3 Example 3 Example 3 Example 3
10 11 12 Finale state
Example 3 Example 3 Example 3 Example 3

Contributing

Contributions are welcome! Please open an issue or submit a pull request with any improvements or bug fixes.

Here are some ways you can contribute to the Minesweeper:

Enhancement Category Description Status
Add new features to the game e.g., timer, high scores, custom grid sizes. Create a new game mode or difficulty level. Not Started
GUI enhancements Implement additional buttons or functionalities to enhance the gameplay experience. Modified matplotlib default toolbar to include additional buttons for game controls. Not Started
Algorithm improvements Optimize the game logic or implement new rules for revealing cells. Not Started
Probabilistic solver Develop a solver that uses probability to determine the best move. This is particularly useful in cases where no safe moves are available. This can be implemented using a Monte Carlo simulation or other probabilistic methods, such as Bayesian inference or Markov chains. Not Started
Image recognition solver Create a solver that uses image recognition techniques to analyze game boards as an input image and determine the best move. This can be implemented using computer vision libraries such as OpenCV or TensorFlow. Not Started

Acknowledgements

License

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