制作可解释的扫雷器
Making Explainable Minesweeper

原始链接: https://sublevelgames.github.io/blogs/2025-07-06-making-explainable-minesweeper/

我对“ 14扫雷变种”中的提示很感兴趣,并意识到许多玩家,包括我过去的自我,依靠运气在扫雷中,因为不了解推力模式。模棱两可的情况通常可以在逻辑上解决。 这启发了我创建“可解释的扫雷器”,这是一个游戏,所有难题都可以通过逻辑而不是猜测来解决。该游戏用自然语言解释了推论规则。水平生成使用AI测试潜在地图,丢弃那些需要随机猜测的人。仅通过“直观”动作和特定的扣除规则可解决的映射。人工智能还预先预揭示了一些正方形以减轻难度。 该游戏采用全局模式(查找所有矿山/安全的单元),简单的模式(基于邻居计数的标记/揭示)以及高级模式(分析相邻编号的单元格的常见区域和独特区域)。通过比较这些区域的矿山要求,可以推导出安全或富含矿山的细胞。目的是教玩家如何通过逻辑扣除来接近扫雷器,并避免不必要的猜测。该游戏有9种语言,欢迎反馈。

这个黑客新闻线程讨论了“可解释的扫雷器”,这是经典游戏的一种版本,旨在消除猜测的需求。 几位评论者提到西蒙·塔瑟姆(Simon Tatham)的难题应用程序,该应用程序还具有100%逻辑上可解决的板的扫雷器变体。 Simon的版本通过随机创建板,然后迭代调整矿井位置来产生难题,直到确定性求解器可以找到解决方案为止。 尽管有些人欣赏保证的解决性,但另一些人则发现它的吸引力不如原始猜测,而战略猜测可以成为时间优化方法的一部分。 该线程还提到了诸如Bombe和Tametsi之类的替代性扫雷游戏,它们探索了不同的拼图解决机制并提高了复杂性。 原始文章的创建者承认了演示中的监督,他们的解决方案仅说明了两个或更少数字的模式。
相关文章

原文

🎮Game 🧩Puzzle 💣Minesweeper 🤖Algorithm 💻Game Dev

I recently purchased and played a game called 14 Minesweeper Variants during a Steam Summer sale. It was a fun game. However, I became curious while looking at the hints provided in the game. What exactly are these?

This is the screen when using hints. Can you figure out what this means?

Actually, when I played Minesweeper, which was a default Windows game, I could solve cases where there was a definite answer, but I remember stepping on countless mines in ambiguous situations. For example, situations like this:

What should you do here? Usually, you step on a mine.

The numbers 1 and 2 indicate the number of mines in each cell’s 8 neighbors (up, down, left, right, and diagonals). Empty cells mean there are no mines in their neighbors. However, in situations like the image above, it’s not easy to figure out which squares have mines and which don’t. It’s also difficult to accurately guess the mine locations because there are too few mines.

Let’s look at this situation. This image is from this source, and it’s exactly a 50/50 probability. There’s 1 mine left, and whichever of the two remaining squares you choose, there’s a chance it could be a mine.

Should I cut the red wire or the blue wire? What if I cut both?

This situation occurs due to Minesweeper’s map generation algorithm. The original Minesweeper usually doesn’t let you step on a mine on your first click. This is because it places mines in locations other than the square the user selects on their first click. Since mines are placed at that moment, it can’t perform enough calculations to prevent 50/50 situations. When I experimented, finding boards solvable only through logical deduction required about 250,000 attempts per level on a 9x9 board with 33 mines.

However, there’s a common mistake that beginners like my past self often make. They think it’s a 50/50 situation and leave it to luck when deduction is actually possible! The 14 Minesweeper Variants I mentioned earlier provides hints for such situations. Let’s go back to the previous image:

This is the screen when using hints. Can you figure out what it means now?

Here’s how to interpret this image. The purple square is the common area shared by the two highlighted 2 cells. The upper 2 still has 7 neighbors remaining, but the lower 2 is at the edge of the game map, so it only has 4 neighbors. Due to the existence of the lower 2, there must be exactly 2 mines in the common area. So what’s in the 3 cells above the upper 2? At least they’re not mines. That’s why those cells are safe to open.

Indeed! There were no mines in the 3 upper cells!

Now I’ve explained the ambiguous part. While it’s relatively easy to understand when explained in natural language like this, that game, although excellent, shows this with symbols, which took me a long time to interpret. I thought I probably wasn’t the only one. So what if there was a game that explained this in natural language? Wouldn’t it be able to show many people that they can solve more problems by making one step of deduction in Minesweeper? With this thought, I decided to create a game.

The maps provided in this game must be solvable only through intuitive results or deduction. To achieve this, I had the AI simulate solving puzzles from the player’s perspective and keep only the successful maps. The process is illustrated in the diagram below:

Generating deducible Minesweeper maps using simulation

Let me explain this process step by step.

First, step 1 is generating a random board. A predetermined number of mines are randomly scattered on a board of a predetermined size.

Next, step 2 is finding candidate starting positions. Cells with values of 0, 1, or 2 are good choices, especially cells with value 0 since they also open up surrounding cells as a bonus. We find cells with values 0, 1, and 2, prioritize cells with lower values, and determine candidate starting positions. Here, only 2 candidates are shown.

Then in step 3, we actually try to solve the puzzle. At this point, the cell (0,0) marked with a red arrow gets stuck during the deduction process. It leads to the situation below:

Stuck situation when solving from cell (0,0)

Even using all intuitive results and deduction rules, there are no certain cells. At this point, we abandon this starting point and try the next one. That’s (4,0) with the blue arrow. By solving the problem using intuitive results and deduction rules, we were able to reveal all non-mine regular cells, so this map is usable.

In step 4, we take the map found in step 3 and add some AI moves to make the map start in a slightly more revealed state than the beginning. The purpose is to make the difficulty slightly easier.

The completed level is shown below. It’s a deducible Minesweeper level that doesn’t rely on luck!

A deducible Minesweeper level that doesn't rely on luck

So what deduction rules were used in map generation? Since my game Explainable Minesweeper uses the same deduction rules, let me summarize what happens when you press the hint button.

Process when pressing the hint button in Explainable Minesweeper

First, there are 2 Global Patterns. If you’ve found all mines, the remaining cells must all be regular cells. Or if you’ve found all regular cells, the rest must obviously be mines. Note that in my game, for logical accuracy, not only revealing regular cells but also placing flags in the wrong place results in game over.

Situation where hints are found in Global Pattern

Next, Simple Patterns are literally simple situations. When the number of unrevealed cells around a cell matches the cell’s number, you can flag all those cells. Conversely, if you’ve already placed all the flags, you can safely reveal all remaining cells.

Situation where hints are found in Simple Pattern

Finally, Advanced Patterns are probably the reason I wrote this article. Along with the common area mentioned earlier, you need to consider the unique area that each cell has separate from the common area.

This pattern considers 2 numbers (note that 14 Minesweeper Variants includes patterns involving 3 or more numbers, but I excluded them as they’re too complex). When we call the first number A and the second number B, we compare the number of mines in the common and unique areas. When the difference is clear, we can determine whether the unique area is safe or contains mines.

For example, in the image below, A is 1 and B is 3. B needs 3 mines but already has 1 flagged, so it only needs 2 more. However, we cannot place 2 or more mines in the common area with A, because A must have only 1 mine as a neighbor. We also can’t place 0, because then there wouldn’t be enough spaces to satisfy B’s condition of 3 mines. Therefore, by placing 1 mine in B’s unique area (4,5) and 1 mine in one of the 2 remaining common area cells, A’s unique area becomes safe.

Determining unique area as safe

Conversely, here’s a case where the unique area is determined to contain mines. A has no unique area, and only B has a unique area. Since A must have 1 mine, exactly 1 must be placed in the common area, and in that case, we can see that the only option left for B’s unique area is a mine.

Determining unique area as mine

It’s simpler logic than you might think, right? I can’t believe I kept leaving Minesweeper to luck because I didn’t know this. Of course, there are games in the original Minesweeper where you have to rely on luck even with logical deduction. But there are no such games in Explainable Minesweeper!

Thank you for reading this long article. The method used here isn’t extraordinary deduction and can be thought of with common sense, but I hadn’t thought about it until now. I wrote this article and created the game thinking there might be others who could benefit like me. Since explanation is the main purpose, the game supports a total of 9 languages. If you’d like support for your language, please let me know here. And if possible, please let me know what you think about this method and the game. Thank you.

联系我们 contact @ memedata.com