Skip to main content
🎮 Game Logic

What you're building

The core engine of Minesweeper — board generation and the satisfying flood-fill reveal that opens a whole region with a single click.

You will implement:

  • createBoard(rows, cols, mines) — returns a 2-D grid where each cell is { mine: bool, adjacent: number, revealed: false }.
  • reveal(board, row, col) — mutates the board in place: reveals the cell; if adjacent === 0 and not a mine, recursively reveals all 8 neighbours. Returns "boom" if the cell is a mine, otherwise "ok".

Requirements

  • Mine positions must be spread across the grid (no duplicates, no out-of-bounds).
  • adjacent is the count of mines in the 8 surrounding cells (0-8).
  • reveal stops recursing at already-revealed cells (prevents infinite loops).
  • Revealing a mine returns "boom" without marking it revealed.
  • Revealing a cell with adjacent > 0 reveals only that cell (no flood fill).
  • Revealing a cell with adjacent === 0 flood-fills all contiguous zero-adjacent, non-mine neighbours.

Stretch goals

  • Add a flag(board, row, col) toggle.
  • Detect and return a "win" state (all non-mine cells are revealed).

What this proves

2-D array manipulation, BFS/DFS flood-fill, and neighbour-coordinate iteration — three patterns that appear constantly in grid-based interview problems.

âš¡ 50 XP
solution.jsRuns in your browser
Loading editor…
Tests4 to pass
createBoard produces correct dimensions
createBoard places exactly N mines
reveal returns boom on mine
reveal flood-fills zero-adjacent region

Run your code to check these.