$\begingroup$

I think this is a fantastic question, because you actually arrive at a pretty good strategy for how to begin a game. Sorry it's such a long answer, I try to be thorough so you can see this is the correct answer - there is a summary at the end. I'm going to rephrase your question in the way I interpret what you mean.

At the start of a game of minesweeper, if you click adjacent cells what is the chance of there being a mine in a given cell around these clicked cells? Is there any way to use this for a good opening strategy?

Firstly I'd like to define the following parameters:

$n$ is the number of mines in a grid;

$N$ is the number of cells in a grid;

$\rho=n/N$ is the density of mines in a grid, and the probability of hitting a mine in a random cell. $$\begin{array}{c c c c} \mathrm{Difficulty} & n & N & \rho\\ \hline \mathrm{Beginner} & 10 & 64 & 0.156\\ \mathrm{Intermediate} & 40 & 256 & 0.156\\ \mathrm{Expert} & 99 & 480 & 0.206 \end{array}$$

Secondly I'd like to define the following random variables and events:

$C=\bigcup_i C_i$ is the event of the grid configuration, where $C_i$ is the event of a particular mine configuration (see below). Note that the $C_i$ are disjoint events, so $\mathbb{P}(C)=\sum_i\mathbb{P}(C_i)$.

$X_i=\{\mathrm{mine\ in\ cell\ }i|C\}$ is the event there is a mine in cell $i$, given the situation of the board (these are the probabilities we want to find).

(these are the probabilities we want to find). $Y_i$ is a random variable representing the number of mines in a group of cells as specified later on. $\mathbf{Y}$ is the corresponding vector.

Let's assume we neither hit a mine or an opening, as these events are trivial. Instead, let's start by supposing our first click, placed somewhere in the middle of the grid, reveals a 1, which is the most likely case. The probability of any of the 8 surrounding cells containing a mine is $\frac{1}{8}=0.125$, which is lower than $\rho$ on any normal game, so the safest move is to choose an adjacent cell. If the first click were to reveal a 2, you should not click an adjacent cell as $\frac{2}{8}=0.25>\rho$. One possible resulting configuration is displayed below (I use '$(i)$' to label a cell as 'cell $i$'). $$\begin{array}{c c c c c c c} _{(1)} &|& _{(4)} &|& _{(5)} &|& _{(8)}\\ \hline _{(2)} &|& \mathbf{1} &|& \mathbf{1} &|& _{(9)}\\ \hline _{(3)} &|& _{(6)} &|& _{(7)} &|& _{(10)} \end{array}$$

The way to calculate the probabilities $\mathbb{P}(X_i)$ for $1\leq i\leq 10$, is to consider all possible configurations of mines in these 10 cells. Cells 1, 2 and 3 are effectively equivalent, as they have the same probabilities and are independent to the other cells in each configuration. In this case there are 3 such groups of cells, $\{1, 2, 3\}, \{4, 5, 6, 7\}, \{8, 9, 10\}$, which $Y_1, Y_2, Y_3$ refer to respectively.

There are two configurations: $\mathbf{Y}= (1,0,1)$ or $(0,1,0)$, which I refer to as $C_1$ and $C_2$ respectively, so $\mathbb{P}(C_1)=\mathbb{P}(Y_1=1,Y_2=0,Y_3=1)$. These are illustrated below.

$\begin{array}{*{7}c} \star &|& &|& &|& \star\\ \hline \star &|& 1 &|& 1 &|& \star\\ \hline \star &|& &|& &|& \star \end{array}\qquad$ $\begin{array}{*{7}c} &|& \star &|& \star &|& \\ \hline &|& 1 &|& 1 &|& \\ \hline &|& \star &|& \star &|& \end{array}$

Now we use conditional probability, and the fact that if $Y_1=1$ then we are in configuration 1. $$\begin{align} \mathbb{P}(Y_1=1|C) &= \frac{\mathbb{P}(\{Y_1=1\}\cap C)}{\mathbb{P}(C)}\\ &= \frac{\mathbb{P}(C_1)}{\mathbb{P}(C_1)+\mathbb{P}(C_2)} \end{align}$$

To calculate $\mathbb{P}(C_1)$, think about what is required for this to occur - we need exactly 1 mine in a given 3 cells, none in a given 4 cells, and 1 in a different 3 cells. Now to simplify the problem, we will assume that the mine density doesn't change, which is a good approximation at least for large grids like expert. We get $$\begin{align} \mathbb{P}(C_1) &= \left[\binom{1}{3}\rho(1-\rho)^2\right] \times (1-\rho)^4 \times \left[\binom{1}{3}\rho(1-\rho)^2\right]\\ &= 9\rho^2(1-\rho)^8, \end{align}$$ which corresponds to two situations of choosing 1 mine in 3 cells, 8 cells with no mine, and 2 cells with mines. Thinking of it this way makes it much easier to just write down probabilities, and we can see $\mathbb{P}(C_2)=4\rho(1-\rho)^9$.

This gives $$\begin{align} \mathbb{P}(Y_1=1|C) &= \frac{9\rho^2(1-\rho)^8}{9\rho^2(1-\rho)^8+4\rho(1-\rho)^9}\\ &= \frac{9\rho}{9\rho+4(1-\rho)}\\ &= \frac{9\rho}{4+5\rho}. \end{align}$$

Finally, divide this by $3$ to get $\mathbb{P}(X_1),\mathbb{P}(X_2),\mathbb{P}(X_3)$, and use this to deduce the other cells' probabilities. So we get the following probabilities (for expert grid): $$\begin{array}{*{7}c} 0.123 &|& 0.158 &|& 0.158 &|& 0.123\\ \hline 0.123 &|& \mathbf{1} &|& \mathbf{1} &|& 0.123\\ \hline 0.123 &|& 0.158 &|& 0.158 &|& 0.123 \end{array}$$ So we conclude that the best next move would be to click on one of the side cells on the left or right, next to the clicked cells, as $0.123<\rho$, so there is a lower chance of hitting a mine.

To speed up these calculations for other situations, notice it is easier to think of the ratio of the configuration probabilities, only having to consider the number of combinations and the relative number of mines. For example, if our second click was a 2 instead of a 1, to give $\begin{array}{*{5}} \hline |& 1 &|& 2 &| \\ \hline \end{array}$ the two combinations $C_1$ and $C_2$ are $\mathbf{Y}=(1,0,2)$ or $(0,1,1)$. $$\frac{\mathbb{P}(C_1)}{\mathbb{P}(C_2)}=\frac{\binom{1}{3}\binom{2}{3}\rho}{\binom{1}{4}\binom{1}{3}(1-\rho)}$$

However, we can approximate $\rho\approx 0.2$ so that the relative chance of hitting a safe cell to hitting a mine is $\frac{1-\rho}{\rho}=4$. The calculations then become very easy: $$\begin{align} 4\times12\mathbb{P}(C_1) &= 9\mathbb{P}(C_2)\\ \mathbb{P}(X_1) &= \frac{1}{3}\mathbb{P}(Y_1=1|C)\\ &= \frac{\mathbb{P}(C_1)}{3(\mathbb{P}(C_1)+\mathbb{P}(C_2))}\\ &= \frac{9}{3\times(4\times12+9)} = \frac{1}{19}\\ \mathbb{P}(X_4) &= \frac{1}{4}\left(\frac{4\times12}{4\times12+9}\right) = \frac{4}{19}\\ \mathbb{P}(X_7) &= \frac{2}{3}\left(\frac{9}{4\times12+9}\right) + \frac{1}{3}\left(\frac{4\times12}{4\times12+9}\right) = \frac{22}{57}. \end{align}$$

So we see the cells that are only adjacent to the 1 are very safe. $$\begin{array}{*{7}c} 0.05 &|& 0.21 &|& 0.21 &|& 0.39\\ \hline 0.05 &|& \mathbf{1} &|& \mathbf{2} &|& 0.39\\ \hline 0.05 &|& 0.21 &|& 0.21 &|& 0.39 \end{array}$$

We would see a similar result if it were a 3 on the right next to the 1. In any of these cases, our best option is to click one of $X_1, X_2, X_3$. Let's consider the case that we click $X_2$. We're fairly likely to hit an opening at this point, but lastly, I will analyse the other likely situation, of hitting another number 1, giving us $$\begin{array}{*{9}c} _{(1)} &|& _{(4)} &|& _{(6)} &|& _{(8)} &|& _{(10)}\\ \hline _{(2)} &|& \mathbf{1} &|& \mathbf{1} &|& \mathbf{1}\ \mathrm{or}\ \mathbf{2} &|& _{(11)}\\ \hline _{(3)} &|& _{(5)} &|& _{(7)} &|& _{(9)} &|& _{(12)} \end{array}$$

The equivalence groups are $\{1,2,3\}, \{4,5\}, \{6,7\}, \{8,9\}, \{10,11,12\}$. For the 1 1 1 case... the configurations are $\mathbf{Y}\in\{(1,0,0,1,0), (0,1,0,0,1), (0,0,1,0,0)\}$, and $\mathbb{P}(C_1):\mathbb{P}(C_2):\mathbb{P}(C_3) = 3\cdot2:2\cdot3:4\cdot2 = 3:3:4$

For the 1 1 2 case... the configurations are $\mathbf{Y}\in\{(1,0,0,1,1), (0,1,0,0,2), (0,0,1,0,1)\}$, and $\mathbb{P}(C_1):\mathbb{P}(C_2):\mathbb{P}(C_3) = 3\cdot2\cdot3:2\cdot3:4\cdot2\cdot3 = 3:1:4$

Working out how many mines result in each section with these configurations, we arrive at the following probabilities. $$\begin{array}{*{9}c} 0.1 &|& 0.15 &|& 0.2 &|& 0.15 &|& 0.1\\ \hline 0.1 &|& \mathbf{1} &|& \mathbf{1} &|& \mathbf{1} &|& 0.1\\ \hline 0.1 &|& 0.15 &|& 0.2 &|& 0.15 &|& 0.1 \end{array}$$

$$\begin{array}{*{9}c} 0.13 &|& 0.06 &|& 0.25 &|& 0.19 &|& 0.38\\ \hline 0.13 &|& \mathbf{1} &|& \mathbf{1} &|& \mathbf{2} &|& 0.38\\ \hline 0.13 &|& 0.06 &|& 0.25 &|& 0.19 &|& 0.38 \end{array}$$

In summary:

A good opening strategy is as follows: