Minesweeper is a game that is played on a grid, behind which hide a certain number of “mines”. The objective is to click no all squares except the mines. If a square does not contain a mine, clicking on it reveals the number of mines in the adjacent 8 squares, but clicking on a mine results in a loss right away.

Detailed rules and strategies can be found right here: minesweeper.info

My bot uses three basic techniques to play minesweeper:’

(code can be found here: GitHub)

- If the number on a square is equal to the number of uncovered squares around it, all of them must be mines.
- If a square already has mines around it equal to the number on it, the remaining uncovered squares around it must be safe.
- If the above two rules fail to produce any “safe squares”, it resorts to checking each and every possible combination of mines in the remaining independent boundary pieces (called the Tank Algorithm).

Failing all of that, it click on a random square.

The first two rules are usually enough to win most games in basic and intermediate, whereas the third rule helps in the expert level.

Finally, here’s a video of my bot playing at the expert level: