How to Calculate Probabilities in Minesweeper
At a glance
- 1. Write clue constraints
Represent each hidden square by a zero-or-one variable and translate adjacent numbered clues into equations.
- 2. Find valid layouts
Keep only mine placements that satisfy every clue and the known total number of mines.
- 3. Count each layout
If unconstrained squares remain, include the number of ways to place the leftover mines among them.
- 4. Compare safe counts
Divide the layouts where a square is safe by the total consistent layouts.
In Minesweeper, a numbered clue gives a constraint on nearby hidden squares. To calculate a square’s probability of containing a mine, count the mine placements that satisfy all the clues and the board’s total mine count. A local guess based only on one clue can miss information elsewhere on the board.
This calculation assumes that every mine placement consistent with what you know is equally likely. That is appropriate when the board’s mines were placed uniformly at random and you have no other information about the generation process. Some versions use special rules, such as ensuring a solvable board; those rules can change the probabilities.
Turn clues into equations
For each hidden square, use a binary variable: means it contains a mine, and means it is safe. A revealed number says how many mines are in its adjacent squares. If some adjacent squares are already confirmed mines, subtract them from the clue.
For example, if a clue shows 2 and one adjacent square is known to be a mine, the other hidden neighbors must contain exactly one mine. If those hidden squares are and , write
A square marked with a flag is not mathematically confirmed to be a mine just because it is flagged. Treat flags as certain only if you are sure they are correct.
Count consistent layouts
A layout is one complete assignment of mines and safe squares to the locations still hidden. Keep only layouts that satisfy every clue and the known number of remaining mines. If there are equally likely consistent layouts, and of them put a mine in a particular square, then
The probability the square is safe is . When you must choose a square to uncover, compare the mine probabilities of the available squares and choose one with the smallest value.
When several hidden squares have no adjacent revealed clues, they are often called unconstrained squares. Do not simply ignore them: the total number of mines remaining can restrict how many of them are mines.
Worked example: include the total mine count
Suppose the clues give these two constraints on three hidden squares:
There are two possible assignments:
| Assignment | Mines among |
|---|---|
| 2 | |
| 1 |
Now suppose there are two more hidden, unconstrained squares, and , and exactly 2 mines remain among all five squares.
- If , then and must both be safe. This gives 1 layout.
- If , exactly one of and must be a mine. This gives 2 layouts: or .
There are consistent layouts. Thus
The same calculation gives and . Notice that the two clue-compatible patterns are not equally likely after the total mine count is included: the second pattern has two possible placements for its remaining mine.
A counting shortcut for unconstrained squares
Suppose a particular assignment to the clue-adjacent squares uses mines, there are unconstrained squares, and mines remain in total. The leftover mines can be placed among the unconstrained squares in
ways, provided . Use this as the weight of that assignment. Add the weights of all valid assignments to get the total number of layouts; for a square’s mine probability, add only the weights of assignments in which it is a mine.
In the example, the pattern has weight , while has weight . This is why counting just the number of patterns in the constrained area gives the wrong result.
Common mistakes
- Using a clue in isolation: A square next to a 1 is not automatically a 50–50 chance. Other clues may force it to be safe or mined.
- Forgetting the global mine count: The number of mines left can change which local patterns are possible and how many full layouts each pattern represents.
- Treating patterns as equally likely: Two patterns in clue-adjacent squares may allow different numbers of placements elsewhere.
- Counting flags as facts: A mistaken flag can make every calculation based on it wrong. If uncertain, include both possibilities.
- Assuming the board-generation rule: Uniform counting is valid only under a matching uniform-placement assumption. A game that selects boards or first moves using extra rules may need a different probability model.
For a small frontier of hidden squares, listing the valid binary assignments is usually enough. For a larger frontier, a solver can combine clue constraints and count assignments by their number of mines, then apply the same weighting for unconstrained squares.
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.