Every Minesweeper player asks whether the first click can kill them. In this implementation the answer is fixed in code, and the same file answers where to open, whether flags are required, and why some endgames are pure luck.
The three boards and their exact mine counts
The difficulty table defines three boards. Easy is 9 by 9 with 10 mines. Medium is 16 by 16 with 40. Hard is 16 by 30 with 99. The safe cell counts you must reveal to win are 71, 216, and 381.
Mine density rises with each step. Easy places mines in about 12 percent of cells, medium about 16 percent, hard about 21 percent. The jump from medium to hard is the largest, so treat hard as a different discipline rather than a bigger medium.
Why the first click can never explode
Mines are not placed when the board is drawn. The engine waits for your first click, then places mines with the clicked cell as the safe anchor. The placement code skips every cell within one row and one column of your click, shuffles the remaining candidates with a Fisher-Yates shuffle, and mines the first ones in the shuffled order.
Three consequences follow.
1. The first click can never be a mine, on any difficulty, in any cell including corners.
2. The first clicked cell always has zero adjacent mines, so the reveal always takes the flood fill branch and opens a connected region. Your first click never shows a number.
3. A first click away from the edges guarantees a mine-free 3 by 3 zone, so the opening covers at least nine cells. A corner click clips that zone to a 2 by 2 block, so the minimum opening is four cells.
The rule for step one is direct. Open your first cell near the middle of the board, never at a corner or edge, because the guaranteed opening is larger and the win still requires every safe cell.
Flags are optional and can block you
The win check is a single comparison. When the revealed count equals the safe cell count, you win, and the engine then flags every remaining mine automatically. Nothing in the win condition counts your flags.
Flags carry a real cost. The reveal function returns immediately on a flagged cell, and the click handler ignores revealed cells. If you flag a safe cell by mistake, that cell cannot be revealed until you unflag it, and you must reveal every safe cell to win.
Follow these rules.
1. Flag only cells you have deduced, never on suspicion.
2. Audit your flags whenever the counter disagrees with your reading of the board.
3. Play entire games with zero flags placed, because flags exist to protect your attention, not to satisfy the engine.
The counters and the timer
The header displays the mine count minus your flag count. On hard it starts at 99 and drops by one per flag. It can go negative, and the display clamps at minus 99.
The timer starts on your first click and runs until the game ends, capped at a display of 999. Your score is the elapsed seconds. The engine saves your best time per difficulty in your browser under the key minesweeper_best, so best times never leave your machine.
What this implementation does not have
There is no chording. Clicking a revealed number does nothing, so the desktop shortcut that opens all neighbors of a satisfied number costs individual clicks here. There is also no disambiguation for split endgames. When two cells remain and one mine, the engine offers no information, and a hard board with 99 mines across 381 safe cells produces such cases regularly.
Plan for that. Clear ambiguous regions last, so one guess cannot end an otherwise solved board early.
Hard mode layout
The 16 by 30 board is wider than the play area, so the engine switches to horizontal scrolling with a scrollbar under the board. Cell size clamps between 18 and 52 pixels. Mis-clicks near the scroll edge are a real risk on narrow screens, so scroll deliberately before you click.
A first-click routine you can trust
- [ ] Open near the board center on any difficulty.
- [ ] Let the flood fill finish before you plan flags.
- [ ] Deduce every flag, because a flagged safe cell blocks the reveal you need to win.
- [ ] Read the counter as mines minus flags, and treat surprises as an audit signal.
- [ ] Clear ambiguous corners of the board last on hard.
Honest downsides. The split endgame is unwinnable without a guess on this engine. No chording means more clicks per clear than the desktop versions you may know. The timer runs while you think, and best times are stored per browser, so they do not follow you across devices.
Play the [Minesweeper game](/en/minesweeper) and test the safe zone on a hard board. If your first click ever lands on a number or a mine, send a screenshot, because that would contradict the placement code and we would treat it as a bug.