My approach to the AI ended up not being very different from what I had planned in my last post.

I ended up making a single class to contain all of the tiles marked as either safe or as a mine. That same class has all of the functions that do checking on tiles as well. It’s called SpikerSweeper.

SpikerSweeper contains two int vectors, each containing a list of mines, either the known safe locations, or known mine locations.

Mines and safes get added to those vectors from my two major algorithms methods: detectMines() and detectSafes().

My mine detection works approximately like:

for every square with value N:
if it has exactly N adjacent-unopened squares:
add each of those squares as mines.

Safe detection is similar:

for every square with value N:
if it has exactly N adjacent-mine squares:
add each of those squares as safes.

The major article I used when developing my strategy for playing the game, that I then put into code for the AI, was a post on Bai Li‘s programming/math/tech blog, located here.

The major feature I didn’t have time to implement that I was hoping to, was Bai Li’s tank algorithm, which would have helped to solve the larger boards with much more consistency. As it is now, the program has a pretty high win rate on the beginner boards, but struggles with higher difficulties.

If anyone is interested in taking a look at the code, in it’s final form, check out my github.

Leave a Reply

Your email address will not be published. Required fields are marked *