I am writing a Minesweeper game, and would like the whole area up to the numbers, to be revealed when you choose a grid location. Like it does in the windows version of minesweeper. Right now, all it reveals, is a 3x3 grid. I'm not sure how to go about making the changes to keep checking if the space still has blanks in it. Thanks..
I found a brute force solution to this problem, although it does not involve recursion.
When a space with 0 mines around it is cleared then the 8 spaces around it are automatically cleared. You have this part so far. If any of the 8 spaces just cleared also have no mines around it then those spaces should be cleared around. This leads to the 'chaining' of space clearing which sometimes clears large areas of the minefield, as seen in the MS version.
Here's the way I did this: Once the initial clearing of the 1st 3x3 grid is done I check if any of those 8 spaces have no mines around it. If so, I make a pass over the entire minefield looking for spaces with no mines around it and which has not been cleared around. This is repeated until no more such spaces are found. This actually works.
With your way, how would I make sure that ONLY the section up to the numbers are cleared, and not ALL the spaces on the board? As it sounds like it does in:
I make a pass over the entire minefield looking for spaces with no mines around it and which has not been cleared around. This is repeated until no more such spaces are found. This actually works.
That's why I thought recursion might be better, but I'm not sure how to go up, down left then right ( not necessarily in that order ), till just a space is cleared up yo the numbers that show how many mines touch that space.
I described the procedure poorly. Sorry.
I meant this:
I make a pass over the entire minefield looking for already cleared spaces with no mines around them and which have not been cleared around. This is repeated until no more such spaces are found.
Spaces with a zero surrounding mine count which are still covered should of course NOT be cleared around.
Here is the function which my program uses when a space with no mines around it is clicked on. I am using a structure to represent a minefield space.