Problem
Implement a playable text-based Minesweeper engine.
You are given a board size and mine locations (or a mine count with a deterministic placement method). Implement initialization and the click operation.
Setup
-
Board has
height
rows and
width
columns.
-
Some cells contain mines.
-
Each non-mine cell stores the number of adjacent mines (8-directional neighbors).
Click behavior
Implement click(r, c) with these rules:
-
If
(r, c)
contains a mine, mark it as revealed and the game is over.
-
Otherwise reveal
(r, c)
.
-
If the revealed cell’s adjacent-mine count is
0
, recursively/iteratively reveal all connected zero-cells
and
their boundary non-zero neighbors (standard Minesweeper expansion).
-
Re-clicking an already revealed cell should be a no-op.
I/O / Interaction
-
Provide functions/classes so a user can “play” via repeated clicks.
-
Visualization can be done using
print
(e.g., hidden cells shown as
#
, revealed numbers as
0-8
, mines as
*
only when revealed).
Constraints
-
1 ≤ width, height ≤ 200
(assume up to 40,000 cells).
-
Mines can be up to
width*height - 1
.
-
Your expansion must avoid stack overflow (i.e., recursion depth issues) on large boards.
What to deliver
-
Data structures for the board state.
-
Efficient click expansion implementation.
-
A simple loop/demo showing the board after each click.