Minesweeper Logic
Minesweeper uses a simple reveal rule: clicking a cell reveals it; if it has no adjacent mines, all neighbors are revealed recursively (flood-fill). Numbered cells show how many adjacent cells contain mines. The game combines graph traversal (flood-fill) with constraint reasoning.
Loading demo…
Algorithm explanation
Reveal: if cell has a mine, game over. If cell has adjacent mine count > 0, show the number. If count is 0, run flood-fill (BFS/DFS) to reveal all connected zero-cells and their numbered boundaries. Flagging and probability reasoning use the current board state and constraints.
Concepts used
- Flood-fill
- BFS/DFS
- Grid traversal
- Constraint reasoning
Complexity
Time:
O(rows × cols)Space:
O(rows × cols)Real-world usage
- Game logic in grid-based games
- Region-filling in image editing
- Constraint propagation in puzzles