Question presented to candidate: "Build Minesweeper. A 9 by 9 board hides 10 mines. Clicking a cell reveals it: a mine ends the game, a number shows how many of its eight neighbours are mines, and an empty cell opens up all the connected empty area around it. Right-click places a flag. The first click must never be a mine."
Requirements:
- 9 by 9 board, 10 mines, a mines-left counter (mines minus flags) and a New game button.
- First click is always safe and opens an area: mines are placed after it, avoiding that cell and its neighbours.
- Revealing an empty (zero) cell opens the connected empty region and its numbered border.
- Right-click, the F key, or a Flag mode toggle (for touch) flags and unflags; flagged cells cannot be revealed.
- Hitting a mine shows all mines and stops the game; opening every safe cell wins.
- Arrow keys move between cells; cells are labelled for screen readers.
What a strong answer should cover:
- A cell model (
mine,adj,open,flag) and rules as pure functions (reveal,toggleFlag) with a seeded RNG for mine placement. - Deferred, first-click-safe placement with a (partial) Fisher-Yates over the allowed cells, then neighbour counts.
- An iterative flood fill with an explicit stack or queue, marking cells when they are pushed, and why recursion overflows the call stack on large boards.
- Win detection by counting opened safe cells, not by rescanning the board each time.
- Immutable updates that copy only the cells that changed, plus keyboard and touch alternatives to right-click.
Clarifying questions expected:
- "Should the first click be safe on its own, or should it always open an area (its neighbours safe too)?"
- "Do you want chording (clicking a number whose flags are all placed opens its other neighbours) and a timer?"
- "Do we need custom board sizes?"
Code / implementation expected: Yes. A playable board in the framework of your choice, with reveal and flood fill in plain functions.