Skip to content

Commit

Permalink
Clean up propagateEmptyTiles method
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldoylecs committed Dec 16, 2024
1 parent 01ca33a commit b990b63
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/minesweeper/minesweeper-game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,18 @@ export class MinesweeperGame {

while (toVisit.length > 0) {
const [currX, currY] = toVisit.pop()!;

// Check if already visited
const stringifiedCoords = JSON.stringify([currX, currY]);
if (visitedCoords.has(stringifiedCoords)) {
continue;
}
visitedCoords.add(stringifiedCoords);

// Reveal tile
board[currX][currY].isVisible = true;

// If the tile has no adjacent bomb, add neighbor tiles to toVisit list
if (board[currX][currY].adjacentBombCount === 0) {
const adjacentTiles = this.getAdjacentTiles(board, currX, currY);
toVisit = toVisit.concat(adjacentTiles);
Expand Down

0 comments on commit b990b63

Please sign in to comment.