I have used the page
https://www.lrvideckis.com/blog/2020/07/17/minesweeper_probability.html as research to help calculate and explain the probabilities.
There are two types of probability in this calculator: Local and Global.
Local calculates only the adjacent tiles near number tiles, and it does not consider any mines that would be in non-adjacent tiles.
Global calculates all unknown tiles. Most minesweeper games have a global mine count, and it not only influence the probability for non-adjacent tiles, but it also affects probability for adjacent tiles as well.
This page describes the formula used to calculate them.
To give an example on how to calculate them, consider this 5x5 board.
There are 14 possible solutions as shown below.
Local Probability
To calculate the Local probability, simply count the number of mines per tile for each solution. Then divide by the number of solutions.
For the variables \( S \), a solution array of unknown tiles, in a solution array set \( SS \) s.t. \[ \forall i \in \{0, 1, \dots, n-1\},\quad S[i] \in \{0, 1\} \]
and a tile number \( T \) s.t. \[
T \in \{0, 1, \dots, |SS|-1\}
\]
Then the local probability is calculated as
\[
\text{LocalProbability}(T) = \frac{ \displaystyle \sum_{ S \in SS } S[T] }{ |SS| }
\]
For a calculation example, let's say the tile numbers are numbered from 0 to \( |S| \) as shown below.
Note that |S| is the same as the number of unknown adjacent tiles near number tiles only.
\[
\begin{aligned}
\text{LocalProbability}(0) &= \frac{ 2 }{ 14 }\\
\text{LocalProbability}(1) &= \frac{ 3 }{ 14 }\\
\text{LocalProbability}(2) &= \frac{ 1 }{ 14 }\\
\text{LocalProbability}(3) &= \frac{ 3 }{ 14 }\\
\text{LocalProbability}(4) &= \frac{ 2 }{ 14 }\\
\dots
\end{aligned}
\]
It should be noted that for any \( T \),
\[ \text{LocalProbability}(T) = 100\% \text{ (guaranteed mine)} \]
\[ \text{ only if } \displaystyle \sum_{ S \in SS } S[T] = |SS| \]
\[ \text{LocalProbability}(T) = 0\% \text{ (guaranteed safe)} \]
\[ \text{ only if } \displaystyle \sum_{ S \in SS } S[T] = 0 \]
Global Probability (Adjacent Tiles)
To calculate the global probability of adjacent, the global mine count as \( M_G \) is considered, including the number of mines for each solution array \( S \) in a solution set \( SS \).
Here are also other variables to define:
\[
\begin{array}{l}
U_A \text{ as number of all adjacent tiles},\\
\text{where }U_A=|S|,\\
U_{NA} \text{ as number of non-adjacent unknown tiles},
\end{array}
\]
Note that there are 12 solutions which have 2 mines, and 2 solutions which have 1 mine in the 5x5 1-1-1 board.
Let's describe a map function that maps each number of mines to its number of occurances.
\[
\begin{array}{l}
MF_t : \text{ℤ}_{\ge 0} \rightarrow \text{ℤ}_{\ge 0}\\
MF_t(m) = n,\\
m \text{ as number of mines},\\
n \text{ as number of occurances},\\
MF_t(m) =
\begin{cases}
n_0 & \text{if } m = m_0 \\
n_1 & \text{if } m = m_1 \\
n_2 & \text{if } m = m_2 \\
\dots \\
0 & \text{otherwise}
\end{cases}
\end{array}
\]
Then mapping the solutions of mines to occurances to a function \( MF_G(m) \) is then
\[
MF_G(m) =
\begin{cases}
2 & \text{if } m = 1 \\
12 & \text{if } m = 2 \\
0 & \text{otherwise}
\end{cases}
\]
Let's also describe a set \( S_M = \{ m_0, m_1, m_2, \dots \}\) for the set of the number of mines in the solution set.
\[ S_{M_G} = \{ 1,2 \} \]
The reason why the number of mines and the occurances are considered is because the leftover mines, e.g. \( M_G - m_n \),
are arranged in a combination of all non-adjacent tiles \( U_{NA} \). We'll use this number and the function \( MF_G \) to create the sample space for the formula for adjacent tiles, or \( \text{GlobalProbability}_A(T) \).
The formula to count all combinations above is \( \binom{U_{NA}}{M_G - m_n} \).
For example, there are 10 non-adjacent tiles from the 5x5 board below written as N.
Let's say we have a global mine count \( M_G = 4 \), and counting \( m = 2 \) from a solution. There would be \( M_G - m = 4 - 2 = 2\) mines left over.
The mine combinations would be shown as the following
...and so forth.
The number of combinations would be \[ \binom{U_{NA}}{M_G - m_n} = \binom{10}{4 - 2} = \binom{10}{2} = 45\]
The formula of the sample space, or denominator, for \( \text{GlobalProbability}_A(T) \) is
\[
\displaystyle \sum_{ m \in S_{M_G} } MF_G(m) \cdot \binom{U_{NA}}{M_G - m}
\]
This formula enumerates each number of occurances of each number of mines from the solution set, and multiplies the leftover mine combination \( \binom{U_{NA}}{M_G - m_n} \) as the "weighted sum" for each \( m \in S_{M_G} \).
To find the numerator for each adjacent tile, we use the same formula above to get the number of mines, the occurances, and the leftover mine combinations but counting only if \( S[T] = 1 \) as from the Local Probability.
For example, for tile 0,
\[
\begin{array}{l}
MF_0(m) =
\begin{cases}
2 & \text{if } m = 2 \\
0 & \text{otherwise}
\end{cases}\\
\text{ and } S_{M_0} = \{ 2 \}
\end{array}
\]
This describes that only 2 solutions have this tile as a mine, and those solutions have 2 mines.
For tile 1,
\[
\begin{array}{l}
MF_1(m) =
\begin{cases}
3 & \text{if } m = 2 \\
0 & \text{otherwise}
\end{cases}\\
\text{ and } S_{M_1} = \{ 2 \}
\end{array}
\]
This describes that only 3 solutions have this tile as a mine, and those solutions have 2 mines.
For tile 2,
\[
\begin{array}{l}
MF_2(m) =
\begin{cases}
1 & \text{if } m = 1 \\
0 & \text{otherwise}
\end{cases}\\
\text{ and } S_{M_2} = \{ 1 \}
\end{array}
\]
This describes that only 1 solution has this tile as a mine, and that solution only has 1 mine.
...and so forth.
It should be noted that \( \forall S_{M_n}, S_{M_n} \sub S_{M_G} \), meaning that tiles may or may not contain all number of mines from \( S_{M_G} \).
The whole formula to get the global probability for adjacent tiles is.
\[
\text{GlobalProbability}_A(T) =
\frac{
\displaystyle \sum_{ m_T \in S_{M_T} } MF_t(m_T) \cdot \binom{U_{NA}}{M_G - m_T}
}{
\displaystyle \sum_{ m \in S_{M_G} } MF_G(m) \cdot \binom{U_{NA}}{M_G - m}
}
\]
It should be noted that for guaranteed safe and mine tiles,
\[
\begin{array}{l}
\text{If } M_T = \empty,\\
\text{then } \text{GlobalProbability}_A(T) = 0
\end{array}
\]
\[
\begin{array}{l}
\text{If } MF_T(m) = MF_G(m) \text{ } \forall m,\\
\text{then } \text{GlobalProbability}_A(T) = 1
\end{array}
\]
Global Probability (Non-Adjacent Tiles)
The number of combinations of leftover mines is used for the global probability of non-adjacent tiles. It is also the denominator or sample space, described as
\[
\displaystyle \sum_{ m \in S_{M_G} } \binom{U_{NA}}{M_G - m}
\]
To check the number of combinations for a tile that has a mine, let's check some mine combinations again for \( m = 2 \) and \( M_G = 4 \), but only considering the top-left tile (marked as a flag).
It seems that there are 9 combinations out of \( \binom{10}{2} = 45 \) that is a mine while the rest is not a mine.
To get this number 9, or getting a formula for counting combinations of any non-adjacent tile that have a mine for \( \binom{U_{NA}}{M_G - m} \) combinations,
we can fix one specific tile we are choosing, and find the number of combinations of all non-adjacent tiles - 1 with leftover \( M_G - m \) - 1 mines, or \( \binom{U_{NA} - 1}{M_G - m - 1} \).
It shows that \( \binom{9}{1} = 9 \).
Let's also check \( m = 1 \). Using the formula, there are \( \binom{U_{NA}}{M_G - m} = \binom{10}{3} = 120 \text{ combinations}\) and \( \binom{U_{NA} - 1}{M_G - m - 1} = \binom{9}{2} = 36 \text{ combinations that have a mine in any tile.}\)
The global probability for non-adjacent tiles is the following.
\[
\text{GlobalProbability}_{NA} =
\frac{
\displaystyle \sum_{ m \in S_{M_G} } \binom{U_{NA} - 1}{M_G - m - 1}
}{
\displaystyle \sum_{ m \in S_{M_G} } \binom{U_{NA}}{M_G - m}
}
\]
Global Probability (Adjacent Tiles), where only some solutions are valid
What happens if the global mine count \( M_G \) is just 1? This means that there can only be 2 solutions that are valid that have 1 mine, and the 12 solutions that are 2 mines are simply discarded.
So the formula can be changed depending on the global mine count, and thus \( \text{GlobalProbability}_A(T) \) can be rewritten as the following.
\[
\frac{
\displaystyle \sum_{ m_T \in S_{M_T} | m_T \le M_G } MF_T(m_T) \cdot \binom{U_{NA}}{M_G - m_T}
}{
\displaystyle \sum_{ m \in S_{M_G} | m \le M_G } MF_G(m) \cdot \binom{U_{NA}}{M_G - m}
}
\]
Note, that if the global mine count is less than all known solution mine numbers, then the program will throw an error of 'Too little mines!'.
Moreover, if \( M_G \gt max(S_{M_G}) + U_{NA} \), the program will throw an error of 'Too Many Mines!', since the maximum number of mines in a solution set + non-adjacent tiles is the limit that would fill the board with mines.
Convolution to Calculate Mine Count and Frequencies of the Whole Board
Let's consider a board with 2 subsystems. Subsystems, in the context of this calculator, are board systems where adjacent tiles are not shared from other systems, and can be independently calculated for its solutions counting the frequencies and number of mines.
For example: Let's calculate the mines and frequencies map of this whole board with a 1-1-1 and a 2-3-2 for each adjacent tile marked with a number, where the adjacent tiles are not shared between the 1-1-1 and 2-3-2.
\[
\begin{array}{l}
MF_0(m) = MF_4(m) = MF_5(m) = MF_6(m) = MF_7(m) = MF_{11}(m)\\
=
\begin{cases}
2 & \text{if } m = 2 \\
0 & \text{otherwise}
\end{cases}\\
MF_1(m) = MF_3(m) = MF_8(m) = MF_{10}(m)\\
=
\begin{cases}
3 & \text{if } m = 2 \\
0 & \text{otherwise}
\end{cases}\\
MF_2(m) = MF_9(m)\\
=
\begin{cases}
1 & \text{if } m = 1 \\
0 & \text{otherwise}
\end{cases}\\
MF_{12}(m) = MF_{16}(m) = MF_{17}(m) = MF_{18}(m) = MF_{19}(m) = MF_{23}(m)\\
=
\begin{cases}
2 & \text{if } m = 4 \\
0 & \text{otherwise}
\end{cases}\\
MF_{13}(m) = MF_{15}(m) = MF_{20}(m) = MF_{22}(m)\\
=
\begin{cases}
4 & \text{if } m = 3 \\
9 & \text{if } m = 4 \\
0 & \text{otherwise}
\end{cases}\\
MF_{14}(m) = MF_{21}(m)\\
=
\begin{cases}
4 & \text{if } m = 3 \\
0 & \text{otherwise}
\end{cases}\\
\end{array}
\]
Let's also consider the mine and frequency map functions for each subsystem to count the total number of valid solutions. \(MF_{G_1}\) describes the 1-1-1 subsystem and \(MF_{G_2}\) describes the 2-3-2 subsystem.
\[
\begin{array}{l}
MF_{G_1}(m) =
\begin{cases}
2 & \text{if } m = 1 \\
12 & \text{if } m = 2 \\
0 & \text{otherwise}
\end{cases}\\
MF_{G_2}(m) =
\begin{cases}
8 & \text{if } m = 3 \\
12 & \text{if } m = 4 \\
0 & \text{otherwise}
\end{cases}\\
\end{array}
\]
You can verify these numbers by clicking the board above, and pasting it to calculate its probability. Clicking on adjacent tiles will give the number of solutions s and the number of mines m per tile and the system.
Let's define the whole system as \( G_G \) that descibes the set of the solutions for 1-1-1 and 2-3-2 together.
In order to consider the number of solutions of the whole board and tile rather than the individual subsystems, we would have to count each solution from \( G_1 \) and \( G_2 \). By multiplying the valid number of solutions from \( G_1 \) and \( G_2 \).
It seems there are (2+12) = 14 valid solutions for \( G_1 \) and (8+12) = 20 valid solutions for \( G_2 \). This means there are a total of 14*20 = 280 solutions that should be considered.
For calculating the number of mines, it seems that there can be a minimum of (1+3) = 4 mines and a maximum of (2+4) = 6 mines. There can also be (2+3) = 5 mines as part of the solution too.
With the information of the separate systems, it doesn't tell the number of solutions per mine number for a tile and the whole board.
In order to get the total number of solutions and number of mines of the whole board rather, discrete convolution would be used.
The convolution formula to get \( MF_{G_G}(m) \), where \( BS = \{1, 2, 3, \dots\} \) describes the subsystems is the following.
\[
MF_{G_t}(m) = \sum_{ S \in BS \setminus \{t\} }{ (MF_{G_t} \ast MF_{G_S})(m) }
\]
We convolve with all other different systems other than itself.
To do convolution, we try to add every combination of \( m_t \) from the first map function with \( m'_t \) from another map function.
Also, \( n_t \) is multiplied from the first map function with \( n'_t \) from another map function.
The function below descibes a dictionary of the convolution of a \( (m_t,m'_t) \) pair and the \( (m,n) \) sum/multiplication pair.
\[
CD(MF_1,MF_2) =
\left\{
\begin{array}{lll}
(m_0,m'_0) : & \{ m: m_0 + m'_0, & n: MF_1(m_0) \cdot MF_2(m'_0) \}\\
(m_0,m'_1) : & \{ m: m_0 + m'_1, & n: MF_1(m_0) \cdot MF_2(m'_1) \}\\
(m_0,m'_2) : & \{ m: m_0 + m'_2, & n: MF_1(m_0) \cdot MF_2(m'_2) \}\\
& \vdots & \vdots \\
(m_1,m'_0) : & \{ m: m_1 + m'_0, & n: MF_1(m_1) \cdot MF_2(m'_0) \}\\
(m_1,m'_0) : & \{ m: m_1 + m'_1, & n: MF_1(m_1) \cdot MF_2(m'_1) \}\\
& \vdots & \vdots \\
(m_a,m'_b) : & \{ m: m_a + m'_b, & n: MF_1(m_a0) \cdot MF_2(m'_b) \}\\
\end{array}
\right\}
\]
We need to sum all \( m_t + m'_t \) pairs that are equal together.
The whole convolution formula for some map functions \( MF_1 \) and \( MF_2 \) can finally be defined as the following using Iverson Bracket notation.
\[
(MF_1 \ast MF_2)(m) = \sum_{(m_i,m'_j) \text{ s.t. } m_i \in S_{M_1}, m'_j \in S_{M_2} }{[m_i + m'_j = m] \cdot MF_1(m_i) \cdot MF_2(m'_j)}
\]
The Iverson Bracket notation \( [m_i + m'_j = m] \) means that for every \( m_i + m'_j \) that sums to \( m \), it is 1. Otherwise it is 0 whether \( m_i + m'_j \neq m \). Sum every same \( m \) with \( n_i * n'_j \) or \( MF_1(m_i) \cdot MF_2(m'_j) \)
Using this, the following formulas would be used to get the total number of solutions per mine number of the whole board.
\[
\begin{array}{ll}
MF_{G_G}(m) &= \sum_{S \in BS \setminus \{1\}}{(MF_1 \ast MF_{G_S})(m)} \\
& = \sum_{S \in BS \setminus \{2\}}{(MF_2 \ast MF_{G_S})(m)} \\
& = \sum_{S \in BS \setminus \{3\}}{(MF_3 \ast MF_{G_S})(m)} \\
& \vdots
\end{array}
\]
The first map function \( MF_1 \) can just be used as the other subsystems 2, 3, 4, ... would result in the same calculation.
An example calculation of MF_{G_G} is:
\[
\begin{array}{ll}
CD(MF_{G_1},MF_{G_2}) &=
\left\{
\begin{array}{l}
(1,3) : \{ m: 1 + 3, n: MF_{G_1}(1) \cdot MF_{G_2}(3) \}\\
(1,4) : \{ m: 1 + 4, n: MF_{G_1}(1) \cdot MF_{G_2}(4) \}\\
(2,3) : \{ m: 2 + 3, n: MF_{G_1}(2) \cdot MF_{G_2}(3) \}\\
(2,4) : \{ m: 2 + 4, n: MF_{G_1}(2) \cdot MF_{G_2}(4) \}\\
\end{array}
\right\}\\
&=
\left\{
\begin{array}{l}
(1,3) : \{ m: 4, n: 16 \}\\
(1,4) : \{ m: 5, n: 24 \}\\
(2,3) : \{ m: 5, n: 96 \}\\
(2,4) : \{ m: 6, n: 144 \}\\
\end{array}
\right\}\\
\\
MF_{G_G}(m) &=
\begin{cases}
16 & \text{if } m = 4 \\
24 + 96 & \text{if } m = 5 \\
144 & \text{if } m = 6 \\
0 & \text{otherwise}
\end{cases}
=
\begin{cases}
16 & \text{if } m = 4 \\
120 & \text{if } m = 5 \\
144 & \text{if } m = 6 \\
0 & \text{otherwise}
\end{cases}\\
\end{array}
\]
It should be noted that 16 + 120 + 144 = 280, the total number of solutions of 1-1-1 and 2-3-2 board systems combined.
The numbers can be verified by checking the Probability Results tab of the Whole System.
To get the total number of solutions per mine number of a tile, it is similar to the calculation above.
We convolve each tile using every other \( MF_{G_u} \) where \( u \) is not in the same subsystem as the tile.
\[
MF_t(m) = \sum_{S \in BS \setminus \{u\}}{(MF_t \ast MF_{G_u})(m)} \text{, } t \text{ is NOT an adjacent tile of } G_u
\]
Here is an example calculation for tile 0.
\[
\begin{array}{ll}
CD(MF_0,MF_{G_2}) &=
\left\{
\begin{array}{l}
(2,3) : \{ m: 2 + 3, n: MF_0(2) \cdot MF_{G_2}(3) \}\\
(2,4) : \{ m: 2 + 4, n: MF_0(2) \cdot MF_{G_2}(4) \}\\
\end{array}
\right\}\\
&=
\left\{
\begin{array}{l}
(2,3) : \{ m: 5, n: 16 \}\\
(2,4) : \{ m: 6, n: 24 \}\\
\end{array}
\right\}\\
(MF_0 \ast MF_{G_2})(m) &=
\begin{cases}
16 & \text{if } m = 5 \\
24 & \text{if } m = 6 \\
0 & \text{otherwise}
\end{cases}
\end{array}
\]
So the global probability calculated for tile 0, given the global mine count \( M_G = 9 \), number of non-adjacent tiles \( U_{NA} = 5 \), and using convolution of the map functions is the following:
\[
\begin{array}{ll}
\text{GlobalProbability}_A(0) &=
\frac{
\displaystyle \sum_{ m_0 \in S_{(M_0 \ast M_{G_2})} } (MF_0 \ast MF_{G_2})(m_0) \cdot \binom{U_{NA}}{M_G - m_0}
}{
\displaystyle \sum_{ m \in S_{(M_{G_1} \ast M_{G_2})} } (MF_{G_1} \ast MF_{G_2})(m) \cdot \binom{U_{NA}}{M_G - m}
}\\
&=
\frac{
\displaystyle \sum_{ m_0 \in S_{(M_0 \ast M_{G_2})} } (MF_0 \ast MF_{G_2})(m_0) \cdot \binom{5}{9 - m_0}
}{
\displaystyle \sum_{ m \in S_{(M_{G_1} \ast M_{G_2})} } (MF_{G_1} \ast MF_{G_2})(m) \cdot \binom{5}{9 - m}
}\\
&=
\frac{
(MF_0 \ast MF_{G_2})(5) \cdot \binom{5}{4} + (MF_0 \ast MF_{G_2})(6) \cdot \binom{5}{3}
}{
(MF_{G_1} \ast MF_{G_2})(4) \cdot \binom{5}{5} + (MF_{G_1} \ast MF_{G_2})(5) \cdot \binom{5}{4} + (MF_{G_1} \ast MF_{G_2})(6) \cdot \binom{5}{3}
}\\
&=
\frac{
16 \cdot 5 + 24 \cdot 10
}{
16 \cdot 1 + 120 \cdot 5 + 144 \cdot 10
}\\
&=
\frac{
320
}{
2056
}\\
& \approx 15.6\%
\end{array}
\]
This percentage probability can be verified using the same board and global mine count \( M_G = 9 \).