Mines is the Minesweeper-flavored grid game: a 5×5 board hides a few mines, you open tiles one at a time, and a multiplier climbs with every safe tile. The multiplier looks like a design choice, but it's almost entirely determined by one probability. This post derives it, writes it in JavaScript, and points out two easy mistakes along the way.
The code blocks below form one script: paste them into a single .mjs file in order and node prints the output shown under each.
The survival probability
Take a board of T tiles with M mines, so T − M tiles are safe. Mine positions are fixed before the first click, and you open tiles without replacement.
The first tile is safe with probability (T − M) / T. Given that it was safe, the board now has T − 1 tiles left and still M mines, so the second is safe with probability (T − M − 1) / (T − 1). Keep going for k picks:
P(survive k) = ∏_{i=0}^{k−1} (T − M − i) / (T − i)
This is a hypergeometric probability: the chance that a sample of k tiles drawn without replacement contains zero mines. Written with binomial coefficients, it's the number of all-safe k-tile subsets over the number of k-tile subsets:
P(survive k) = C(T − M, k) / C(T, k)
From probability to multiplier
A multiplier is fair when its expected payout equals the stake: P(survive k) × m_k = 1, so m_k = 1 / P(survive k). A game with a house edge e pays a fraction of that:
m_k = (1 − e) / P(survive k)
In code:
// Chance of opening `picks` tiles in a row without a mine,
// on a board of `tiles` tiles with `mines` mines.
function survival(tiles, mines, picks) {
const safe = tiles - mines;
if (picks < 0 || picks > safe) return 0;
let p = 1;
for (let i = 0; i < picks; i++) p *= (safe - i) / (tiles - i);
return p;
}
// Multiplier that returns (1 − edge) of the stake on average.
function multiplier(tiles, mines, picks, edge) {
return (1 - edge) / survival(tiles, mines, picks);
}
On the standard board, T = 25 and M = 3, five picks:
const T = 25, M = 3, k = 5;
const p = survival(T, M, k);
console.log(`survival ${p.toFixed(6)}`);
console.log(`fair multiplier ${(1 / p).toFixed(4)}`);
console.log(`with a 1% edge ${multiplier(T, M, k, 0.01).toFixed(4)}`);
console.log(`with a 5% edge ${multiplier(T, M, k, 0.05).toFixed(4)}`);
survival 0.495652
fair multiplier 2.0175
with a 1% edge 1.9974
with a 5% edge 1.9167
That survival chance is 22/25 · 21/24 · 20/23 · 19/22 · 18/21, which reduces to 57/115: just under a coin flip, though no single pick was worse than 6 in 7.
Mistake 1: treating picks as independent
The tempting shortcut is (22/25)^5, as if each pick had the same 88% chance:
console.log(`(22/25)^5 ${((22 / 25) ** 5).toFixed(6)}`);
(22/25)^5 0.527732
That's 6.5% too high at five picks, and the gap widens with every pick, because each safe tile you open removes a safe tile from the board. After j safe picks, the chance that the next tile is a mine is M / (T − j): the mines are all still there, and the board is smaller.
// Chance that the next tile is a mine, after `done` safe picks.
for (const done of [0, 5, 10, 15, 20, 21]) {
console.log(`after ${String(done).padStart(2)} safe picks: ${((M / (T - done)) * 100).toFixed(2)}%`);
}
after 0 safe picks: 12.00%
after 5 safe picks: 15.00%
after 10 safe picks: 20.00%
after 15 safe picks: 30.00%
after 20 safe picks: 60.00%
after 21 safe picks: 75.00%
Every stopping point has the same expectation
Because the multiplier is defined as (1 − e) / P, the expected return of stopping after k picks is P × (1 − e) / P = 1 − e, whatever k is. That's an identity, not something a simulation needs to confirm. The mine count and the stopping point change the shape of the outcome (frequent small payouts, or rare large ones) but not its mean.
A symmetry in the table
Here is the multiplier on a 5×5 board with a 1% edge, to four decimals:
const cols = [1, 2, 3, 5, 10];
console.log("mines" + cols.map((c) => `${c} pick${c > 1 ? "s" : ""}`.padStart(12)).join(""));
for (const mines of [1, 3, 5, 10, 24]) {
const cells = cols.map((c) => {
const s = survival(T, mines, c);
return (s ? (0.99 / s).toFixed(4) + "×" : "—").padStart(12);
});
console.log(String(mines).padStart(5) + cells.join(""));
}
mines 1 pick 2 picks 3 picks 5 picks 10 picks
1 1.0313× 1.0761× 1.1250× 1.2375× 1.6500×
3 1.1250× 1.2857× 1.4786× 1.9974× 5.0044×
5 1.2375× 1.5632× 1.9974× 3.3926× 17.5154×
10 1.6500× 2.8286× 5.0044× 17.5154× 1077.6132×
24 24.7500× — — — —
3 mines and 5 picks gives 1.9974×; so does 5 mines and 3 picks. 1 mine and 3 picks equals 3 mines and 1 pick, and 10 mines and 5 picks equals 5 mines and 10 picks. That follows from the binomials:
C(T − M, k) / C(T, k) = C(T − k, M) / C(T, M)
Both sides equal (T − M)! (T − k)! / (T! (T − M − k)!), which is symmetric in M and k. In words: "the k tiles I open contain no mine" is the same event as "the M mines all sit among the T − k tiles I didn't open". Swap the number of mines and the number of picks and the probability doesn't change.
(Print this table to two decimals and the symmetry seems to break: 1 mine / 3 picks shows 1.12× and 3 mines / 1 pick shows 1.13×. Both are exactly 0.99 × 25/22 = 1.125, but one comes out of the floating-point product as 1.1249999999999998, and toFixed(2) rounds the two values in opposite directions.)
Mistake 2: forgetting what rounding costs
Displayed multipliers are usually rounded down to two decimals. That takes up to 0.01 off each multiplier, which is a bigger share of a small multiplier than a large one. With a 5% edge:
// Round the multiplier down to two decimals and see what it returns.
for (const picks of [1, 2, 3, 4, 5, 10]) {
const s = survival(T, M, picks);
const raw = 0.95 / s;
const shown = Math.floor(raw * 100) / 100;
console.log(`${String(picks).padStart(2)} pick${picks > 1 ? "s" : " "}: ${raw.toFixed(4)} -> ${shown.toFixed(2)}, returns ${(s * shown * 100).toFixed(3)}%`);
}
1 pick : 1.0795 -> 1.07, returns 94.160%
2 picks: 1.2338 -> 1.23, returns 94.710%
3 picks: 1.4188 -> 1.41, returns 94.409%
4 picks: 1.6429 -> 1.64, returns 94.835%
5 picks: 1.9167 -> 1.91, returns 94.670%
10 picks: 4.8022 -> 4.80, returns 94.957%
The loss isn't monotonic (it depends on where each raw value falls between two cents), but the first pick, the smallest multiplier, takes the biggest hit here, returning 94.16% instead of 95%. If you publish a return figure, say "up to", or compute it from the rounded values rather than the formula.
Exact fractions with BigInt
The running product is fine in double precision for boards this size, but it's a product of rounded divisions. For exact work, keep the fraction C(T − M, k) / C(T, k) as two BigInts and reduce it:
// Exact binomial coefficient: after step i, r is C(n, i + 1), so each division is exact.
function binom(n, k) {
let r = 1n;
for (let i = 0n; i < BigInt(k); i++) r = (r * (BigInt(n) - i)) / (i + 1n);
return r;
}
const gcd = (a, b) => (b === 0n ? a : gcd(b, a % b));
// Survival as an exact fraction C(T − M, k) / C(T, k), in lowest terms.
function survivalExact(tiles, mines, picks) {
const num = binom(tiles - mines, picks);
const den = binom(tiles, picks);
const g = gcd(num, den);
return [num / g, den / g];
}
console.log(survivalExact(25, 3, 5));
const [a, b] = survivalExact(25, 3, 22);
console.log(survivalExact(25, 3, 22), survival(25, 3, 22), Number(a) / Number(b));
[ 57n, 115n ]
[ 1n, 2300n ] 0.00043478260869565214 0.0004347826086956522
The worked example reduces to 57/115. The longest run on 25 tiles with 3 mines, all 22 safe tiles, is exactly 1/2300. The running product lands on the neighboring double rather than the one nearest to 1/2300: harmless here, but it's the kind of drift that matters once you compare values with === or floor them to cents. If you do need a Number, convert the reduced numerator and denominator once at the end.
If you'd rather try boards than read tables, our small team built a mines calculator that runs these same formulas for any board from 3×3 to 7×7, any mine count and any edge.
Takeaways
- P(survive k) = C(T − M, k) / C(T, k), a hypergeometric probability, not (1 − M/T)^k.
- The multiplier is (1 − e) / P, so every stopping point has the same expectation, 1 − e.
- Mines and picks are interchangeable in the formula, which is why the table is symmetric.
- Rounding down to two decimals costs up to 0.01 per multiplier, most noticeably on small ones.
Top comments (0)