Minesweeper boards you can finish without guessing
Oct 26, 2026 Β· Game design Β· νκ΅μ΄
The most deflating moment in Minesweeper is a board you have almost cleared, where one of the last two cells is a mine. No number anywhere tells you which one is safe, so all you can do is guess with even odds. Our Minesweeper only made the first cell safe and placed the rest of the mines at random, so a board like that could be left at the end. It happened more on larger boards, especially on Hard (16Γ16). So I changed it to only produce boards you can finish by logic alone.
I weighed three approaches. The first lays the mines, tries to solve the board, and when it gets stuck, moves mines around the stuck spot until it becomes solvable. Simon Tatham's implementation, known from his puzzle collection, works this way. It can produce solvable boards, but the code is long and it can develop a habit of piling mines up on one side. The second quietly changes the board in the player's favor when they guess, but then the board depends on what you press, which doesn't fit the daily challenge where everyone gets the same board. The third, the one I chose, is re-laying. Place the mines at random and let a solver try to clear the board from the starting cell by logic alone. If it gets stuck, lay new mines, and repeat until a solvable board comes out. Boards are at most 16Γ16, so re-laying several times is still quick. I picked it because it was the simplest.
This approach comes with a condition: the solver has to reason exactly the way a person does. Its reasoning has three levels, from easy to hard. The first looks at one number alone. If all the mines around a number have been found, its other closed cells are safe, and if the number of closed cells equals the number of mines left, they are all mines. The second compares two numbers. If all the closed cells of number A are inside the closed cells of number B, then the cells only B touches hold B minus A mines. This is the situation people call the 1-2-1 pattern.
The third looks at the whole frontier at once. It splits the closed cells touching numbers into connected groups, and for each group counts every mine layout consistent with the numbers. This kind of search is called backtracking. It keeps only the combinations that also match the number of mines left on the board, and looks for cells that are safe in every case or a mine in every case. Cells beyond the frontier are judged by the same calculation. Counting is capped at 200,000 layouts; past that, the board is treated as more than the solver can handle and thrown away.
The daily challenge uses a random generator seeded with the date. When a board isn't solvable, it keeps re-laying with the same seeded generator, so everyone arrives at the same board. I generated the board twice from the same seed to confirm it comes out the same.
// plant mines, then try to solve from the start cell using logic only
for (let tries = 1; tries <= 300; tries++) {
const board = plant(startCell, rng);
if (solvable(board, startCell)) return { board, tries, ok: true };
}
return { board: lastBoard, tries: 300, ok: false }; // give up and use the last one
This is a simplified example. The solver functions sit directly on the game's registration object as functions. Values stored there would leak into catalog.js, the file the home page uses for its game list, but a build rule leaves functions out of that file, and I used that.
I tested it in Node with 300 boards per difficulty. Re-laying took 1.1 tries on average (Easy) up to 1.6 (Medium), with a maximum of 7. Each board took under 2ms to make, and not once did it fail after 300 re-lays. To check the solver itself, I compared its verdicts on 150 small boards (5Γ5 and the like) against a complete solver that tries every possible mine layout one by one, and all 150 matched.
I also added one line to the game's guide: "Every board can be solved by logic alone, with no guessing."
References
- Simon Tatham's Portable Puzzle Collection: https://www.chiark.greenend.org.uk/~sgtatham/puzzles/
- Wikipedia, Minesweeper (video game): https://en.wikipedia.org/wiki/Minesweeper_(video_game))
- Wikipedia, Backtracking: https://en.wikipedia.org/wiki/Backtracking
Games from this post
More posts
- Switching a mode button made the whole board wobble Oct 26, 2026
- The wrongly placed flags vanished for 0.7 seconds Oct 26, 2026
- Picking a 3D library and fitting it into a site with no build step Oct 25, 2026
- I deployed, and the old page kept showing for an hour Oct 25, 2026
- Why there is always a cloud within reach in Cloud Hop Oct 25, 2026
