Minesweeper is NP-Complete. However, that doesn’t stop us from coding a little bot to play it. It may not be able to fully crack the game on its own, and needs your help sometimes.

You decide the first move, and the game starts. The bot will continuously place moves and flags until it can’t anymore. Then it’s your turn to place moves and flags (there are times you need to guess), and the bot will move whenever possible.

Here are the tactics that are implemented:

  1. If a cell’s number of neighbouring flags is equal to its number, then open all other cells around it.
  2. If a cell’s number of unopened neighbours is equal to its number, then flag all those cells.
  3. One-Two trick. The pink cell must be a mine, otherwise the yellow cell can’t have two neighbouring mines.
  1. One-One trick. The pink cell must be free, since any mine the leftmost “1” has must be shared with the yellow “1”.

All the variations of the One-One trick and One-Two trick are implemented. Test out the bot below!