Pig is the simplest dice game worth analysing. Roll as often as you like; every face but 1 adds to a turn total, a 1 wipes it. Bank when you choose. First to 100 wins.
Everyone knows the rule: hold at 20. It is not folklore, it is a theorem. One more roll is worth exactly (20 − k)/6 points when your turn total is k, so 20 is precisely where rolling stops paying, and 20 and 21 tie at 8.141795 points a turn.
It is also the answer to the wrong question, because the game is scored in wins.
Play it: https://dev48.infy.uk/game/day73-pig.html
Solving the win game
The state is (your score, their score, turn total), which is 505,000 states for a target of 100. Value iteration over that gives the exact optimal policy — not a heuristic, the actual answer.
The folk rule does not survive contact with it:
| claim | reality |
|---|---|
| the optimal hold is 20 | true on 557 of 10,000 score pairs |
| hold-at-20 matches the table | disagrees on 116,095 of 495,000 decisions |
That much is a known result. The part that rewrote this page is what happens when you score fixed thresholds on wins against the perfect player.
The curve is not a hill
You expect a single peak somewhere near 20. You get five:
| local maximum | 16 | 19 | 25 | 33 | 50 |
|---|---|---|---|---|---|
| = 100 / | 6 | 5 | 4 | 3 | 2 |
Those are not coincidences. It is a resonance with the target. What matters is not how many points a threshold earns per turn, it is how evenly your typical bank divides the 100 you need. Bank about 25 and four good turns finish exactly; bank 20 and you need five, with the last one mostly wasted.
So 20 is not even a local maximum — 19 beats it, and hill-climbing from 20 walks downhill before it finds anything better.
// the points-optimal rule, derived in one line
// E[gain from one more roll] = (5/6)·(average face 2..6) − (1/6)·turnTotal
// = (5/6)(4) − k/6 = (20 − k)/6
// zero at k = 20. Correct, and about the wrong objective.
Why this keeps happening
The points rule optimises a rate. The game pays out on a threshold. Any time those two differ, the rate-optimal answer is a good approximation everywhere except near the boundary — and the boundary is where games are decided.
Verified by an independently written implementation: 5,493,245 assertions, 0 failures, plus 3,687,974 in-page checks across 47 self-checks. Vanilla JavaScript, one file, no build step.
Top comments (0)