St · Statistics & Probability

How to Calculate Mine Probabilities in Minesweeper

Published By the 9to5Science editorial team

At a glance

  1. 1. List the unknowns

    Mark covered squares as variables that are either mines or safe.

  2. 2. Translate clues

    For each revealed number, count the adjacent mines required by that clue.

  3. 3. Apply the total

    Use the remaining mine count to reject layouts that cannot fit the whole board.

  4. 4. Count layouts

    For each square, divide consistent layouts where it is a mine by all consistent layouts.

Minesweeper clues tell you how many mines are next to each revealed square, but they do not always identify exactly which covered squares are mines. To estimate a covered square’s risk, treat the revealed board as evidence and compare the mine placements that remain possible.

The key is to count complete board layouts consistent with the evidence. A local pattern that looks like one possibility may represent many complete layouts once you include covered squares elsewhere on the board.

What probability means here

Suppose you know which squares are covered, the numbers around them, and how many mines remain. A layout is a particular assignment of “mine” or “safe” to every covered square. Keep only layouts that satisfy every revealed clue and the known total number of mines.

If all those layouts are equally likely under the game’s mine-placement rules, then for a covered square XX,

P(X is a mine∣revealed information)=number of consistent layouts where X is a minenumber of all consistent layouts.P(X\text{ is a mine}\mid\text{revealed information})= \frac{\text{number of consistent layouts where }X\text{ is a mine}}{\text{number of all consistent layouts}}.

This is a conditional probability: you are asking about the square after taking the visible board information into account. Some game variants handle the first click or other special cases differently; the calculation should reflect those placement rules if they affect which boards are possible or equally likely.

Turn clues into constraints

Give each covered square a variable that is 11 if it is a mine and 00 if it is safe. A revealed number says that the variables for its adjacent covered squares must sum to that number, after accounting for any adjacent mines that are already known.

For example, if a revealed 1 touches two covered squares AA and BB, and no other adjacent square could be a mine, the clue gives

A+B=1.A+B=1.

That permits two assignments: A=1,B=0A=1,B=0 or A=0,B=1A=0,B=1. If another clue touches BB and CC and also shows 1, it gives B+C=1B+C=1. You must satisfy both equations at once, not solve each clue independently.

Worked example: include unconstrained squares

Suppose five covered squares remain: A,B,C,D,EA,B,C,D,E. The visible clues give

A+B=1,B+C=1,A+B=1,\qquad B+C=1,

and you know there are exactly two mines among the five squares.

The two clue equations allow just two patterns for A,B,CA,B,C:

PatternMines among A,B,CA,B,CAssignments for D,ED,E that make two total mines
A=1,B=0,C=1A=1,B=0,C=12Both DD and EE are safe: 1 assignment
A=0,B=1,C=0A=0,B=1,C=01Exactly one of D,ED,E is a mine: 2 assignments

There are three consistent complete layouts altogether. In one, AA and CC are mines; in the other two, BB is a mine and either DD or EE is the other mine. Therefore,

P(A is a mine)=13,P(B is a mine)=23,P(C is a mine)=13.P(A\text{ is a mine})=\frac{1}{3},\qquad P(B\text{ is a mine})=\frac{2}{3},\qquad P(C\text{ is a mine})=\frac{1}{3}.

Each of DD and EE is a mine in one of the three layouts, so each also has probability 1/31/3.

This example shows why it is not enough to compare the two local patterns and give them equal weight. The pattern with BB mined has two compatible ways to place the remaining mine outside the constrained group. Counting only the local patterns would miss that difference.

A practical method

  1. Mark every covered square that touches at least one revealed clue. These are often called frontier squares.
  2. Write one constraint for each relevant clue, using only squares that could still contain mines.
  3. Enumerate assignments of safe/mine to the frontier squares, keeping only assignments that satisfy all constraints.
  4. Apply the total number of remaining mines. Count the ways to place any leftover mines in covered squares not constrained by clues.
  5. For each candidate square, count the complete layouts in which it is mined and divide by the total number of complete layouts.

For small groups, you can enumerate assignments by hand. With many frontier squares, a program can test assignments or use constraint-solving techniques. If consistent layouts are not equally likely—for example, because of a special placement rule—counting layouts alone is not enough; use their actual probabilities as weights.

Common mistakes

  • Dividing nearby mines by nearby covered squares: a ratio such as “one mine among three squares” is not generally a square’s probability. Clues can rule out some combinations while leaving others.
  • Solving clues separately: a square shared by two clues links their possibilities. A choice that fits one clue may violate another.
  • Ignoring the total mine count: the number of mines remaining elsewhere can eliminate local assignments or change how many complete boards each assignment represents.
  • Counting patterns rather than complete boards: unconstrained covered squares may have several compatible mine placements. Their multiplicity can change the probabilities of frontier squares.
  • Treating an estimate as certainty: a square with the lowest probability is the safest available choice only among the squares you compared; it may still contain a mine. If several squares tie, the clues and assumptions used so far do not distinguish their risks.

References

  1. A First Course in Probability, Sheldon Ross

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.