Project Nayuki

Automatic Minesweeper solver

Conceding that I’m not going to be the fastest or best gamer, I instead chose to exercise my programming skills. I wrote a Java program that plays the Windows Minesweeper game automatically – it reads the screen, computes the moves to make, and performs the mouse movements, all at superhuman speed and accuracy.

Everyone has been exposed to video games at some point in their lives. Although I’m not too bad of a gamer, for every game I played, I’ve seen plenty of players who are much better than myself. I don’t think I have the time or talent to bring myself to the top of the rankings. However, with some unique skills as a programmer, I can design computer programs to play games for me with incredible efficiency.

I’ve wasted my fair share of time on the classic Minesweeper game that’s bundled with Microsoft Windows. But all this time, I was never able to solve the expert difficulty level, either because my logic was insufficient or there were too many ambiguities. This was one of my motivations for writing the solver bot, and it finally did solve the expert level.


Source code only:

Complete package: (source code, compiled classes, bitmaps)

After unzipping, run on the command line with: java MinesweeperAutosolver

Ensure that a Minesweeper window is visible on the screen before running the autosolver. The program will exit if you move the mouse.


  • This program only works on the classic Windows Minesweeper (95, 98, Me, 2000, XP), with its simple graphics and lack of animations. It will not work for the version included with Vista and 7, nor can it be adapted easily. (You can copy the old Minesweeper EXE file to the newer Windows systems, of course.)

  • The solver algorithm has 3 different strategies: single, pair, and random. The first two strategies are analytical and safe. The random strategy is used only if the safe options are exhausted. There are two strategies for looking at each single cell: Suppose a cell has the number N, has F flagged neighbors, and has U unopened neighbors. If N = F + U, then all the unopened neighbors need to be flagged. If N = F, then all the unopened neighbors can be opened. The pair strategy is more complicated, and it basically considers what happens when all the unopened neighbors of a numbered cell A are also neighbors of a numbered cell B. The page at Minesweeper Wiki provides a decent introductory explanation of the pair strategy.

  • The program uses quite a bit of CPU time to capture a screenshot. Since this functionality is provided by the Java standard library, I cannot meaningfully speed up this part of the code.

More info