1. ▼ dafuq did I do?
Join Date
Dec 2013
Posts
204
Rep Power
0

## MineSweeper algorithm?

I decided to make minesweeper and I'm having a little trouble with the algorithm used when you select a tile with 0 surrounding bombs, you know, how it fans out and uncovers all of the tiles with no surrounding bombs. Can someone explain to me how this works? If I knew how it worked I could convert it to code.

This is what I currently have:

I have bombs visible (red X) for debugging.

It works otherwise though. It's pretty cool.
Last edited by zFollette; 12-31-2013 at 07:15 AM.

2. ## Re: MineSweeper algorithm?

The algorithm resembles a 'flood fill' algorithm and is quite simple if implemented recursively: if a cell contains no neighbouring mines, you can open all neighbouring cells (if not open yet). For each neighbour cell, if it contains no neighbouring mines, you can recursively do the same. If it does contain neighbouring mines, show the number of mines and stop the recursion for that cell (otherwise the algorithm would solve the entire puzzle for you)

kind regards,

Jos

3. Just a guy
Join Date
Jun 2013
Location
Netherlands
Posts
5,114
Rep Power
9

## Re: MineSweeper algorithm?

Slightly off-topic: that's an excellent idea for a game to use as a study help, especially because of this one really nasty tiny little game element to implement. I'm actually curious what people who don't apply recursion can come up with to hack it together anyway, it might actually open up some really creative thinking. I'm going to add it to the list of projects to torture interns with :)

4. ▼ dafuq did I do?
Join Date
Dec 2013
Posts
204
Rep Power
0

## Re: MineSweeper algorithm?

Sounds good. Ill take a whack at it.

Update: Got it to recursively uncover the whole board. Now setting restrictions.

I think I just about have it, can someone verify this?

My flood fill starts from the poorly drawn blue X
Last edited by zFollette; 12-31-2013 at 07:25 PM.

5. ## Re: MineSweeper algorithm?

Originally Posted by gimbal2
Slightly off-topic: that's an excellent idea for a game to use as a study help, especially because of this one really nasty tiny little game element to implement. I'm actually curious what people who don't apply recursion can come up with to hack it together anyway, it might actually open up some really creative thinking. I'm going to add it to the list of projects to torture interns with :)
Your interns get to write minesweeper?

...are you hiring? :p

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•