Design a Minesweeper game that supports board generation with hidden mines, user actions like reveal and flag, and win/loss detection based on game rules.
Minesweeper is a classic single-player puzzle game where the player’s objective is to reveal all non-mine cells on a grid without triggering a mine. The game requires logic, deduction, and careful strategy.
0
to 8
indicating how many of its adjacent cells contain mines.0
, all adjacent cells are automatically revealed recursively.In this chapter, we’ll explore the low-level design of a Minesweeper game.
Lets start by clarifying the requirements:
Before starting the design, it's important to ask thoughtful questions to uncover hidden assumptions and better define the scope of the system.
Here is an example of how a conversation between the candidate and the interviewer might unfold:
Candidate: Should the game support different board sizes and difficulty levels (e.g., Beginner, Intermediate, Expert)?
Interviewer: Yes, support configurable board sizes and mine counts based on difficulty levels.
Candidate: Should the player be allowed to flag suspected mines, or is it enough to only reveal cells?
Interviewer: Yes, players should be able to flag and unflag cells they believe contain mines.
Candidate: Should the first cell the player clicks on always be safe, or can it contain a mine?
Interviewer: Good question. The first click should always be safe—it must never reveal a mine.
Candidate: What happens when a player clicks on a cell with no adjacent mines? Should we auto-reveal surrounding cells?
Interviewer: Yes, if a cell has zero adjacent mines, the game should recursively reveal its neighbors until all non-mine cells with adjacent mines are found.
Candidate: Is there a time limit or scoring mechanism based on how fast the user completes the board?
Interviewer: No time limit, but we can show a simple timer for reference. No scoring for this version.
Candidate: Should we support undo functionality or saving and resuming the game?
Interviewer: Not in this version. Let’s keep the scope limited to a single continuous game session.
After gathering the details, we can summarize the key system requirements.