Original Post
So I started making a minesweeper game a few days ago and figured I'd use recursion to do the "Flip all spots that are zero thing if ya know what I mean". For one, I'm not that great with vectors and I'm actually using a vector of vectors of objects. My first question, is there a better way to do this? Such as accessing the vector maybe. This was the first way I thought of to keep the vector from accessing parts that don't exist and I don't think it's the best. (It's also too slow because of all the conditionals and stuff). For one, is there something that may come in handy that I'm not aware of? And two, maybe post suggestions on how I can improve it. There's also a problem where it goes out of bounds sometimes and actually reenters and comes back in and continues recurring. I don't understand that, and another problem: I originally had the top left, top right, etc recurring again instead of just flipping. But I didn't think it was necessary because it would reach that square eventually anyway (i.e for top-right, go up, go right), but i did need to do something there to show the number if it was a corner of the zero cluster. When I just do as I did, it stops recurring when it's still unfinished. I thought I covered all the bases with this but I'd like a new set of eyes to take a look at it. I'd super appreciate ANY help, I usually don't ask for help because I hate being a burden but if there's a better way to work on this, I'd rather not spend time going in circles. Thanks.
void board::FlipAllZeros(int row, int column)
{
ShowBoard(buffer, images); //just temp to illustrate whats happening
if(tileset[row][column].isFlip()) //first base case to prevent redoing work
return;
tileset[row][column].Flip();
if(tileset[row][column].GetValue() == 0){ //second base case, zero is 0 bombs around square
if(column > 0){
if(!tileset[row][column-1].isFlip())
FlipAllZeros(row, column-1); //recur on top
if(row > 0)
tileset[row-1][column-1].Flip(); //top left
}
if(column < tileset[0].size()-1){
if(!tileset[row][column+1].isFlip())
FlipAllZeros(row, column+1); //recur on bottom
if(row < tileset.size()-1)
tileset[row+1][column+1].Flip(); //bottom right
}
if(row > 0){
if(!tileset[row-1][column].isFlip())
FlipAllZeros(row-1, column); // recur on left
if(column < tileset[0].size()-1)
tileset[row-1][column+1].Flip(); //bottom left
}
if(row < tileset.size() - 1){
if(!tileset[row+1][column].isFlip())
FlipAllZeros(row+1, column); //recur on right
if(column > 0)
tileset[row+1][column-1].Flip(); //top right
}
}
}