Large JPG-Aro Ha_0380.jpg
 

An AI for Minesweeper in Python

The earlier Chess engine project made me want to consider other game-theoretic problems. One of the problems for the Harvard CS50 open course is exactly that: Writing a solver for the classic game of Minesweeper.

I have since written a more sophisticated solver in C++, see also CppSweeper.

Recreating the principles of the game itself is simple enough, especially in Python. The solver works along two dimensions - aspects that are deterministically solvable through propositional logic, and some probabilistic estimates.

The probabilistic estimates are rather crudely implemented as they only probabilities yielded from uncovered cells individually, i.e. a number of n mines over m adjacent cells suggests an upper bound of m/n as a probability that each adjacent cell contains a mine. The minimum is hence selected if no cell is known to be safe anymore using the basic deduction rules.

To obtain an exact probability, the entire configuration space of mines (accounting for the constraints imposed by uncovered cells) would need to be considered; and to estimate the probability, this space could be sampled. Again, this was covered in the more advanced CppSweeper game.

For details on this simpler first project, the LinkedIn article expands a bit on this project and the code is available on Github.

What I got from it:

  • Some experience in Python and using the pygame module

  • An interesting example for automation of the thought process behind solving a game

  • Nostalgic feelings for a classic!

Zurück
Zurück

PyChess (Python)

Weiter
Weiter

Mandelbrot (Delphi)