The Math Behind Minesweeper: Probabilities and Predictions

By Neal Taparia - 10/24/2023


Minesweeper is a classic game that made its debut on early computers and requires both logic and luck to master. Players clear a grid of squares while avoiding hidden mines; at first glance, it seems like a very straightforward game. However, beneath the game are mathematics that players can take advantage of. The game’s probabilistic nature is one of the many fascinating aspects of Minesweeper; let’s try to decipher some of it.

Covering the Basics

Before we move on to more intricate mathematical constructs, let’s briefly go over the basic mechanics of Minesweeper; we’ll need it to establish proper probabilities later on.

The playing board consists of a grid of covered squares, some of which are empty and some of which conceal mines. When a player uses the left mouse button to click on a square, one of three things can happen:

  1. The square is empty and reveals a number, indicating how many mines touch that square.
  2. The square is empty and reveals no number, leading to adjacent squares opening automatically.
  3. The square contains a mine, and the game is over.

The objective of the game is to uncover all the squares without detonating any mines. Players can also use the right click to place a flag, allowing them to mark squares they think hide mines, but it’s not necessary to finish the game.

Universal Probabilities of Minesweeper

One of the initial questions players face is: Where should I click first?

In the absence of any prior knowledge, every square has an equal probability of being a mine; however, the first click can never be a mine in most versions of Minesweeper, including Microsoft Minesweeper. While the layout is established before the first click, if a player clicks on a square that contains a mine, it is shifted instead to the first empty square on the top row.

Let’s assume you can hit a mine on your first move. For a standard beginner’s board of 9×9 squares with 10 mines, the probability of hitting a mine on the first click is 10/81, or about 12.35%. As you move to larger boards with more mines, the math adjusts accordingly; an expert board of 16×30 with 99 mines has a 20.625% chance of a mine being in a given square. Technically, you can hit a mine with your first move, but even so, it will just move and you won’t lose the game.

Conditional Probabilities to Know

Things get more interesting after that first click. Based on the numbers revealed, players can now calculate conditional probabilities. If a 1 is revealed, it means one of its touching squares contains a mine. If the square touches eight uncovered squares, there’s a 1/8 chance each of them hides a mine.

The true power of conditional probability, however, shines when these probabilities overlap. Consider two adjacent squares, revealing a 1. This means only one of the surrounding squares has a mine. If they share a common uncovered square, then you can be certain that square has a mine. If not, the shared squares have a reduced probability compared to the rest.

Players can quickly recognize patterns in Minesweeper. For example, a 1-2-1 pattern along a straight line indicates a definite mine directly above and below the middle square (or to the left and right if the pattern is vertical). These patterns arise from basic combinatorics and are key to beating Minesweeper, especially on higher difficulties.

Learning these probabilities can help you win, and even speedrun the game.

Bayesian Predictions in Minesweeper

Bayesian reasoning is a method of statistical inference where new information can be used to update the probability estimate for a given hypothesisin the case of Minesweeper, whether a certain square contains a mine or not. It’s a mathematical way of combining new data with prior beliefs to generate new, updated results.

Bayes’ theorem consists of four basic elements:

  • P(A) — Prior Belief
  • P(B) — Evidence
  • P(B|A) — Likelihood
  • P(A|B) — Posterior Belief

These four elements form the following equation:

P(A|B)=(P(A|B) x p(A))/(P(B))

The Prior Belief in the case of Minesweeper is the initial probability that a particular square contains a mine. For instance, on a fresh game board, if there are 40 mines out of 400 squares, P(A) is equal to 0.1 (or 10%).

As you uncover squares, the numbers you see are Evidence of where mines might be. For instance, seeing a 3 on a square suggests three of its neighboring squares contain mines.

Given that a certain square contains a mine, how likely are you to observe the current configuration of numbers on the board? For example, if you believe a square contains a mine and all its neighbors show 1, then the Likelihood is 1 (or 100%).

The Posterior Belief is the updated belief about whether a square contains a mine after considering the evidence and likelihood.

Imagine you have a square in Minesweeper that's touching an uncovered 1. Initially, you believe there's a 10% chance this square contains a mine (because of the overall mine density on the board).

Now, suppose there are eight covered squares around the 1, including the square in question. The likelihood you'd see a 1 given that this particular square contains a mine is 1/8.

To find P(1) (the evidence), consider all ways a 1 could be produced by the neighboring squares. This is tricky because it depends on the configuration of the board, but for simplicity, if we assume an equal chance for any of the eight squares to have a mine, P(1) would also be 1/8.

Bayesian predictions in Minesweeper allow players to combine new evidence (the numbers they uncover) with their prior beliefs (initial mine densities or previous inferences) to make educated decisions about where mines are likely located. In a real game, considering the entire configuration of numbers on the board and combining evidence from multiple numbers can lead to more refined and accurate beliefs than the oversimplified example we’ve shown.