Hey there again, I’m writing minesweeper in Unity for educational purposes and I’ve got a specific case in which my flood fill algorithm is not uncovering blocks that it should. Here’s a screenshot to illustrate:
In traditional windows minesweeper, under the same circumstances, the block circled is revealed.
My function:
public void floodFill(int x, int y, bool[,] visited){
// Stay in bounds
if (x >= 0 && y >= 0 && x < GameManager.boardScript.columns && y < GameManager.boardScript.rows) {
if (visited [x, y]) {
return;
}
// Reveal block with appropriate count
elements[x, y].loadTexture(adjacentMines(x, y));
// Close to a mine? Stop
if (adjacentMines(x, y) > 0){
return;
}
// One down
visited [x, y] = true;
// Go go go
floodFill (x - 1, y, visited);
floodFill (x + 1, y, visited);
floodFill (x, y - 1, visited);
floodFill (x, y + 1, visited);
}
}
Any help greatly appreciated! I’m still very new to unity and programming.