I have been trying to solve this problem all day and I think i'm going insane.
I'm trying to write a code to simulate minesweeper - I dont want to overcomplicate it, but I want to get the basic functionality down. I know there are a few bugs in the code here but the thing I am most struggling on is how to clear the area of "0s" when you click on a grid space that has no mine and no mine neighbours. (Google minesweeper if you don't know what I am referring to).
This is what I want to achieve:
- A square is clicked, it contains no mine and no neighbouring mines
- Uncover this square and its surrounding 8 squares
- Find which of these 8 squares also have no neighbouring mines
- Uncover the 8 neighbours of these squares
- Repeat steps 3 and 4 until all squares are uncovered and the perimeter of the "mine free" area is shown
So far I am just sweeping across in one direction until I hit an area where the mines begin to appear, but I don't know how best to keep repeating this until all the area is cleared.
I have attached my code so hopefully it should be easier to visualise my problem. I think I can't think straight after thinking about this for so many hours (I am v new to MatLab).
Huge thanks in advance!
0 Comments
Sign in to comment.