RSS

Minesweeper Automation

October 26th, 2008

code, games, portfolio, projects

A few years ago, I was playing a lot of Minesweeper, and I realized that I was spending most of my time implementing two very simple rules repeatedly:

  1. If the number of mines indicated by this square is equal to the number of neighboring mines already flagged, clear any uncleared/unflagged neighbors.
  2. If the number of mines indicated by this square is equal to the number of neighboring mines already flagged plus the number of uncleared neighbors, then flag all uncleared neighbors as mines.

These rules should be obviously correct to anyone who’s ever played Minesweeper; in fact, I can’t even imagine making any progress in a Minesweeper game without them. So I decided to implement these rules in Gnomine, the open source version of Minesweeper that comes with Gnome on Linux. It only took me a few hours before I had this patch (applicable to gnome-games v2.20.1). Of course, this patch assumes that no mines are ever incorrectly flagged, but I think that’s a reasonable assumption.

And after playing with it, it’s surprising how much of the board can be cleared mechanically before you ever even get to any interesting decisions. When the sweeping does stop, what’s left are a few random decisions, where you can’t do any better than a 50/50 guess, and also the genuinely interesting positions where you have to apply set theory to make deductions.

I sent this patch off to the gnome-games mailing list owner, and have yet to receive a response. I’m sure that adding minor features to gnomine is absolutely no one’s top priority, but maybe if someone else has been similarly inspired, they might find this patch useful.


Comments

Leave a Reply