Jump to content
  • Advertisement
Sign in to follow this  
NuclearCarnage

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!