Need Logic Help with Minesweeper

Started by
1 comment, last by NuclearCarnage 15 years, 3 months ago
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
____________________________Portfolio (under construction) Nastycritter
My tutorial site: Noobic
(my video site is coming soon)
Advertisement
The algorithm I believe you might be looking for is a flood fill. Hopefully that will give you some clues for how to proceed.
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.
3. Add square to Q.
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?
____________________________Portfolio (under construction) Nastycritter
My tutorial site: Noobic
(my video site is coming soon)

This topic is closed to new replies.

Advertisement