Why Minesweeper's First Click Is Never a Mine
A game that can end before you've made a single decision isn't a game. Here's exactly how my Minesweeper avoids that, and the harder question I still haven't answered.
A Coin Flip Is Not a Game
My best time on a twenty-mine board is fifteen seconds. I lead with that because Minesweeper has a reputation as a luck game, and a fifteen-second clear isn't luck, it's one deduction loop run until it stops feeling like reasoning.
But the reputation has a real source, and it starts at the very first click.
Do the arithmetic on a naive implementation. A 7x7 board at Medium density carries eight mines in forty-nine cells, so laying them before the player touches anything loses roughly one game in six before a single decision. On Cyborg density it's closer to one in three. That isn't difficulty. That's a slot machine in a puzzle's clothes, and it is why half the world grew up believing Minesweeper is gambling.
So every serious Minesweeper guarantees the first click. There are two ways to do it, they are not equivalent, and the choice leaks into the rest of the game in ways that took me a while to notice.
Relocate, or Don't Place Yet
The first places the mines up front and moves whichever one you hit. You click, the game notices a mine under your finger, picks another cell (the classic Windows behaviour was to scan from the top-left for the first mine-free square), moves the mine there and recomputes the neighbour counts. Cheap, and it preserves one property I'll come back to.
The second places nothing until you've clicked. The board exists as a grid of empty cells, and the first click triggers generation.
Mine does the second. Every cell is created with its mine flag false, and a first-click flag on the game state starts true. The reveal handler checks that flag before anything else: on the first reveal it calls the placement routine with the index of the cell you just clicked, then flips the flag off. Nothing is relocated because nothing was ever there, and that handler is the only caller of the placement function in the whole file.
Nine Safe Cells, Not One
Here's the part I care about. The routine doesn't just exclude the cell you clicked. It builds a safe set of that cell plus all eight neighbours, removes those nine from the candidate pool, and shuffles the mines into what's left.
That does more than prevent a death. Because all eight neighbours are guaranteed mine-free, the cell you opened necessarily has an adjacency count of zero, so it always cascades. Your first click can never be a lone "1" sitting in darkness, and a lone 1 is nearly as useless as a mine: one clue, no context, guess away. A zero cascade blooms a whole region open and hands you a real frontier of numbers to reason against.
Beginners deserve a first move that begins the puzzle rather than one that might end it. That was the most deliberate decision in the build.
What the Guarantee Costs
It isn't free, and I've never seen anyone write down the cost.
Carving nine cells out of the pool packs the remaining mines into a smaller space than the density label implies. Take an 11x11 board at Medium: nineteen mines across 121 cells reads as 15.7 percent, but those mines actually live in the 112 cells that weren't reserved, which is 17 percent. Small, but real. And it runs the other way on small boards: on a 5x5 grid the nine-cell safe pocket is thirty-six percent of the entire board. The beginner sizes are far more generous than their density numbers suggest, which I only noticed while writing this.
Two smaller consequences fall out of the same choice. You can't flag before your first reveal, because the flag handler returns early while the board is still empty. And winning never requires flags at all: the win check compares revealed cells plus mine count against the total, so flags are notation for your own benefit, not scoring. Plenty of people play for years without realising that.
The Daily Challenge Problem
Deferred generation has one consequence I'm not happy with, and I'd rather say it than have somebody find it.
The shuffle that lays the mines is seeded from the game seed mixed with the index of the cell you first clicked. That mixing is what makes a restart reproduce the same board when you open the same cell. But it also means the daily challenge, which derives its grid size and seed from the date so everyone worldwide gets the same puzzle, only produces an identical layout for two players who open the same first cell. Same size, same mine count, same seed, different opening square, different field.
That's a tension, not a bug I forgot about. You cannot have all three of a fully shared board, a free choice of first click, and a guaranteed-safe opening. Something gives. Relocation would fix the shared layout and break the zero cascade; a pre-generated board with a designated starting square would fix both and take away the choice. I left it because the cascade matters more to me than an identical daily field, but that isn't the only defensible call.
The Harder Question: Should It Be Solvable at All?
Guaranteeing the first click is easy. Guaranteeing the rest of the board can be finished by pure logic is a much bigger claim, and it is genuinely contested among people who build these things.
My version does not do it. At high density you will hit positions where two covered cells are symmetric under every constraint you have and the only move left is a coin flip. The argument for fixing that is strong: if a coin flip on move one is unacceptable, a coin flip on move seventy is worse, because it costs you a game you already spent five minutes on. Several respected implementations do generate verified guess-free boards, running a solver over each candidate and rejecting any that need a guess.
The arguments against are also real. A guess-free generator doesn't produce uniformly random boards, it produces a filtered subset, and strong players learn to read that filter and exploit it. And in this architecture there's a hard engineering wall: because the board is generated after the first click, a solver would have to run inside the click handler, on whatever phone the player is holding, between the tap and the paint. A guess-free board can't be precomputed when the player's first cell is an input to it.
So the honest position: this build gives you a guaranteed opening and an unfiltered middlegame, and sometimes that middlegame is unfair. I'd rather say so than let you find out on a 30 percent board at move sixty. When you hit a forced guess, take it at the frontier that opens the most board.
If you want grid logic with no randomness at all, Nurikabe and Takuzu are pure deduction end to end, and Flag Zone builds a different game on the flagging half of Minesweeper. I wrote more about why grids work on us in this piece on grid-based games. The rest of the puzzle catalogue follows the same principle as that nine-cell pocket: the game should start before it can end.
โถ Basraโถ Briscolaโถ Euchre ZAPโถ Spider Solitaire