What does Windows Minesweeper do to make sure a mine is not uncovered on the first click? According to Ivars Peterson’s Minesweeper Logic page, if a mine is uncovered on the first click, it is moved to the upper-left corner of the board. If the upper-left corner is occupied the mine is moved to the right of it. This link on the other hand claims a bit more eccentric behavior for Minesweeper first click. I decided to investigate and settle the question for good.
The only way for any investigation of Minesweeper to make a definitive claim is to reverse engineer and examine the Minesweeper code. I did just that and it turns out that the first claim is true.
I used the WinDbg debugger to run Minesweeper and watch its behavior while it is executing. The crucial code is embedded in the StepSquare function. I disassembled and read the code to determine the actual algorithm. The disassembled code can be viewed by following this link.
The StepSquare function is invoked by Minesweeper every time an unmarked square is clicked. The function checks if it is the first click, and that the square being clicked is a mine. It then tries to move the mine to the upper-left corner. If unsuccessful it tries the square to the right of it. If all of the first row is occupied by mines, the function tries to put the mine in the leftmost square of the row below, and so on.
Using the debugger I generated identical boards to demonstrate this behavior. Figure 1 shows a board on which the first click was on a square not containing a mine. Figure 2 shows the same board but now the first click was on a square containing a mine. Notice that the mine in the upper-right corner in figure 1 has moved to the upper-left corner in figure 2.
|Figure 1.||Figure 2.|
I generated two additional boards to demonstrate Minesweeper behavior when the upper-left corner is occupied. The board in figure 3 is one where a non-mine square was clicked. Figure 4. is the same board as in figure 3. but the first click in this case was on a mine. The rightmost mine was the one that was clicked and it has consequently moved to the right of the upper-left corner.
|Figure 3.||Figure 4.|
This behavior has an interesting consequence, the upper-left corner is typically not a good place to look for a cascade during a Minesweeper game. On the first click, corners are the best place to look for cascades, but the upper-left corner is the worst choice of the four corners. A cascade can occur in the other three corners even if the corner itself is a mine: the first-click will simply move the mine elsewhere. But, in case of the upper-left corner the mine will move right adjacent, and will block the cascade.
After the first click, the upper-left corner has an above average probability of containing a mine: a mine could have moved there from the first-clicked square. Therefore, the player will be taking undue risk by clicking the upper-left corner.
If you open Minesweeper by clicking the upper-left corner it would be best to switch to another corner. The actual impact of clicking the upper-left corner depends on the total number of mines in the board. The impact can be very significant for boards with lots of mines and totally insignificant for boards with very few mines.
LAST UPDATED by Usman Latif [Nov 30, 2003]
Thanks to Ruben V. for pointing out errors in this article.