How Minesweeper Boards Are Generated
Every Minesweeper game starts the same way: you click a cell, and a board full of numbers appears. But how are those mines placed? Is every board fair? And how do no-guess versions guarantee solvability?
This guide walks through the algorithms behind Minesweeper board generation, from classic random placement to the techniques behind Minesweeper Blast.
Classic Mine Placement (Random)
The original Microsoft Minesweeper and most clones use a straightforward method:
The Basic Algorithm
- The player clicks a cell (the first click)
- The game generates a list of all grid positions
- It removes the first-clicked position (and sometimes its neighbors) from the candidate list
- It selects N random positions from the remaining candidates (where N = total mines)
- Mines are placed at those positions
- Numbers are calculated for all non-mine cells
In pseudocode:
function generateBoard(width, height, mines, firstClick):
candidates = all cells except firstClick
minePositions = randomSample(candidates, mines)
for each cell in grid:
if cell in minePositions:
cell.isMine = true
else:
cell.number = countAdjacentMines(cell)
This is fast, simple, and produces truly random boards. The downside: many randomly generated boards contain positions that require guessing.
First-Click Safety
Almost all modern implementations guarantee the first click is safe. The question is: how safe?
Level 1: First Cell Safe
The minimum guarantee: the cell you click does not contain a mine. This is trivial — just exclude that cell from mine placement.
Problem: The first click might reveal a number (say “3”), giving you almost no information. You still have to guess your second click.
Level 2: First Cell Opens (Zero)
Better implementations guarantee the first click is a 0 (blank), which triggers a cascade that reveals a region of cells. This gives you a meaningful starting position.
Method: Before placing mines, exclude the first-clicked cell and all 8 of its neighbors from the candidate pool. Since none of those 9 cells can be mines, the click produces a zero and cascades outward.
Trade-off: On Beginner (9×9, 10 mines), you are placing 10 mines in 72 remaining cells instead of 80 — the effective density increases slightly.
Level 3: First Click Produces a Large Opening
Some implementations go further. Minesweeper Blast generates boards where the first click opens a large enough region to give the player actionable information immediately. This is combined with the no-guess guarantee (see below).
Random Number Generation (RNG)
Mine placement depends on the quality of the random number generator. Most implementations use a pseudorandom number generator (PRNG) seeded by the system clock or a hash.
Why Seeds Matter
A seed is the input that initializes the PRNG. Given the same seed, the same sequence of “random” numbers is produced. This enables:
- Reproducible boards: Daily challenges use a fixed seed (e.g., the date) so every player gets the same board
- Replay verification: Record the seed to verify a record was achieved on a specific board
- Fair competition: Tournaments can distribute seeds so all players solve identical boards
The daily Minesweeper challenge on Minesweeper Blast uses date-based seeding — every player worldwide sees the same three puzzles each day.
Uniform Sampling
When selecting N mine positions from C candidates, the algorithm must ensure uniform distribution — every possible combination of mine positions is equally likely. The standard method:
- Shuffle the candidate array using the Fisher-Yates algorithm
- Take the first N elements as mine positions
Fisher-Yates guarantees each permutation is equally likely, so every subset of N positions from C candidates is equally probable.
Solvable Board Generation (No-Guess)
No-guess Minesweeper guarantees that every board can be solved without guessing. This is significantly harder to generate than random boards because most randomly placed boards are not fully solvable by logic alone.
Method 1: Generate and Test (Rejection Sampling)
The simplest approach:
- Generate a random board (standard mine placement)
- Run a solver on the board
- If the solver can solve the board completely without guessing, accept it
- If not, discard it and generate a new random board
- Repeat until a solvable board is found
Pros:
- Simple to implement
- Produces boards that are statistically random (since the mine placement is random)
Cons:
- Slow. On Expert, only ~5–15% of random boards are solvable without guessing (estimates vary by solver strength). You may need to generate 7–20 boards before finding a good one.
- Depends heavily on the solver’s strength. A weak solver rejects boards that a smarter solver could handle.
Method 2: Constructive Generation
Place mines one at a time, checking solvability at each step:
- Start with an empty board and the first-click position
- Place one mine randomly
- Check if the partial board is still potentially solvable
- If adding this mine creates an unsolvable configuration, remove it and try a different position
- Repeat until all mines are placed
Pros:
- Can be faster than rejection sampling if early pruning is effective
Cons:
- Complex to implement
- Can create subtle biases in mine distribution (not perfectly random)
- “Potentially solvable” is hard to check for a partial board
Method 3: Solver-Guided Generation
A hybrid approach:
- Generate a random board
- Run the solver
- If the solver gets stuck, move mines that cause the ambiguity
- Re-run the solver on the modified board
- Repeat until the board is fully solvable
Pros:
- Often faster than pure rejection sampling
- Can produce boards at specific difficulty levels
Cons:
- Mine distribution may be slightly biased
- Complexity of implementation
Difficulty Control
Not all solvable boards are equally hard. Board generators can control difficulty through:
Mine Density
Higher mine density → harder boards. The standard densities are:
| Difficulty | Density |
|---|---|
| Beginner | 12.3% |
| Intermediate | 15.6% |
| Expert | 20.6% |
Required Pattern Complexity
A generator can analyze which patterns are needed to solve the board:
| Tier | Patterns Required | Difficulty |
|---|---|---|
| Basic | 1-1-X, 1-2-X, simple counting | Easy |
| Intermediate | Reduction, chains, chording chains | Medium |
| Advanced | Double constraints, range reasoning | Hard |
| Expert | Parity, mutual exclusion, bridging | Very hard |
See the pattern library for descriptions of each pattern type.
3BV (Board Complexity Metric)
3BV (Bechtel’s Board Benchmark Value) is the minimum number of left-clicks needed to solve a board. Lower 3BV → fewer required clicks → usually easier or faster.
Typical 3BV ranges:
| Difficulty | 3BV Range |
|---|---|
| Beginner | 5–35 |
| Intermediate | 30–120 |
| Expert | 100–250 |
Generators can filter for specific 3BV ranges to control difficulty. The benchmarks guide explains how 3BV relates to time targets.
The Number Calculation
After mines are placed, every non-mine cell gets a number: the count of mines in its 8 neighbors (orthogonal + diagonal). Cells with 0 adjacent mines are blank and cascade open when clicked.
function calculateNumbers(grid):
for each cell in grid:
if cell.isMine: continue
count = 0
for each neighbor in cell.neighbors:
if neighbor.isMine: count++
cell.number = count
Edge and Corner Cells
Edge cells have 5 neighbors. Corner cells have 3. This is why wall patterns work — the reduced neighbor count gives number clues more power near borders.
Cascade (Flood Fill)
When a blank cell (0) is revealed, all its neighbors are automatically revealed. If any of those neighbors are also blank, their neighbors are revealed too. This continues recursively.
This is a flood fill algorithm — the same technique used to fill an area in graphics programs.
function reveal(cell):
if cell.revealed: return
cell.revealed = true
if cell.number == 0:
for each neighbor in cell.neighbors:
reveal(neighbor)
The size of the cascade from a corner click depends on mine placement. On Beginner, a good corner click can reveal 30–50% of the board instantly. See the opening strategy guide for corner-click analysis.
Daily Puzzle Generation
Daily puzzle systems like the one on Minesweeper Blast need boards that are:
- Deterministic: Everyone gets the same board on the same day
- Solvable: No-guess guarantee
- Varied: Each day’s board feels different
- Appropriately difficult: Three difficulty levels maintained consistently
Typical approach:
- Use the date (YYYY-MM-DD) as part of the seed
- Generate a candidate board using the seeded RNG
- Verify solvability with the solver
- If unsolvable, increment the seed and try again
- The first solvable board for each difficulty becomes the daily puzzle
Historical Approaches
Microsoft Minesweeper (1990)
The original had minimal guarantees: purely random mine placement with first-click safety. No solvability checking. Many games required guessing.
Arbiter & Minesweeper X
Competition-focused versions introduced seed recording for verification but still used random (possibly unsolvable) boards.
Modern No-Guess Implementations
Games like Minesweeper Blast, Simon Tatham’s Mines, and others use solver-verified generation to guarantee solvability. This is now the standard for fair, competitive play.
Further Reading
- No-Guess Minesweeper — why solvable boards matter
- How Minesweeper Solvers Work — the solver used to verify boards
- Minesweeper and Computer Science — the NP-completeness connection
- Daily Challenge — see daily generation in action
- Minesweeper Benchmarks — 3BV and time standards