Public Group

# Need Logic Help with Minesweeper

This topic is 3625 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Ok so i decided to make my own version of minesweeper using the console in c++. I wanted to do this to extend my noob knowledge of c++ a little further. And i've done alright, i've got it nearly working. I have 2, 2 dimensional arrays. One is what the user sees and the one is where the bombs are. When you "dig" on a square, it obviously has to calculate the number of bombs touching it or blow you up depending on whether theres a bomb there. This is simple enough I can do this... The problem comes where you "dig" on a square that has 0 mines touching it... Because on the origonal version of minesweeper if you do this a block squares with 0 mines surrounding them are uncovered. I need to work out how i'm gonna do this? I'm presuming a loop or two? Anyone think they can help me? (i just want an explanation, i dont need any code) Thanks, NuclearCarnage

##### Share on other sites
The algorithm I believe you might be looking for is a flood fill. Hopefully that will give you some clues for how to proceed.

##### Share on other sites
Yes thats exactly what i'm looking for thanks :)

Adapting the third pseudo code example, i have come up with this

Flood-fill (square):
1. Set Q to the empty queue.
2. If the square has more than 0 mines surrounding it, return.
4. For each element n of Q:
5. If square n has 0 mines surrounding it:
6. Set w and e equal to n.
7. Move w to the west until it reaches a square that has more than 0 mines surrounding it.
8. Move e to the east until it reaches a square that has more than 0 mines surrounding it.
9. Set the squares between w and e equal to the id of 0-mine-squares.
10. For each square n between w and e:
11. If the square to the north of n has 0 mines surrounding it, add that square to Q.
If the square to the south of n has 0 mines surrounding it, add that square to Q.
12. Continue looping until Q is exhausted.
13. Return.

Does that look right to you guys?

1. 1
2. 2
3. 3
Rutin
24
4. 4
5. 5
khawk
14

• 11
• 11
• 23
• 10
• 9
• ### Forum Statistics

• Total Topics
633651
• Total Posts
3013129
×