How The AI Works
In one-player Yahtzee, a good move depends not only on the score available this turn, but also on what remains open on the scorecard, how close the upper section is to its bonus, and whether future Yahtzee bonuses are still possible.
The solver accounts for future consequences by assigning a value to every relevant game position: the expected number of additional points obtainable from that position under optimal play. It computes those values backward. A completed scorecard has no future value. From there, the solver evaluates positions with one category left, then two, and so on until it reaches the empty scorecard. Inside each turn it works backward in the same way: first determine the best category to score after the final roll, then the best dice to keep after roll two, then after roll one, and finally average over the possible opening rolls.
The key simplification is that the state of the game between turns is much smaller than the full history of play. Dice and roll number matter during a turn, but once a category has been filled they disappear. Only the scorecard information that can affect future rewards needs to persist.
Valuing a scorecard
Let \(\mathcal{V}(b)\) be the optimal expected number of points still to be earned from a boundary state \(b\). If all 13 categories have been filled, \(\mathcal{V}(b)=0\).
A boundary state contains only scorecard information that can affect future rewards. It records which categories have been filled, the upper-section subtotal capped at 63, and the state of the Yahtzee box: still open, filled with zero, or filled with 50 and therefore eligible for later 100-point bonuses.
Several things are deliberately absent. The score already accumulated does not matter: those points are fixed and cannot change which future action is best. Values above 63 in the upper section are equivalent because the 35-point bonus has already been secured. Likewise, the solver need not remember how many Yahtzee bonuses have already been earned; it only needs to know whether one can be earned.
Now suppose the player has reached the final roll of a turn. Let \(x\) be the five dice, and suppose scoring them in category \(c\) gives an immediate reward \(r_c\) and produces the next boundary state \(b'\). The value of that final roll is
This is the first important dependency in the computation. A scoring choice is worth its points now, plus the optimal value of the scorecard it leaves for the remaining turns.
The reward includes the category score, the 35-point upper bonus when that mark first reaches the threshold, and an eligible 100-point repeated-Yahtzee bonus. The set of legal categories can also depend on the scorecard. For a repeated Yahtzee, an open matching upper box is mandatory. If it is already filled, Three or Four of a Kind take priority; only after those boxes are filled can Chance or the fixed-score Joker categories be used, with another upper box as the final fallback. If the Yahtzee box previously scored zero, the same placement rules apply but no 100-point bonus is awarded.
Representing dice and keeps
During a turn, the identity and order of dice do not matter. A roll such as 1,1,3,4,6 is strategically identical to 6,1,4,1,3, because Yahtzee scoring depends only on how many times each face appears. The solver therefore stores every roll as a sorted tuple. This reduces the number of possible rolls to
These 252 tuples are all the possible combinations of five dice when order is ignored.
A keep action selects which dice remain and which dice are rerolled. For example:
Current roll: 1 1 3 4 6
Keep mask: K K R R R
Here the two ones are kept and three dice are rerolled. If \(n\) dice are rerolled, there are exactly \(6^n\) equally likely ordered outcomes. The solver sorts each outcome and counts how often it produces each successor tuple. This gives the exact transition probability \(\mathbb{P}(x'\mid x,k)\), without simulation or sampling.
There are \(2^5=32\) possible keep masks because each of the five positions independently has two choices: keep or reroll. Some masks are strategically equivalent when equal faces occur, but the solver retains all 32 to use a simple fixed indexing scheme. Keeping all five dice is also a valid action. This represents stopping early and carrying the same dice through any unused roll stages.
These sorted roll states, keep masks, and exact transition counts provide the probability model used in the backward calculations that follow.
Working backward through a turn
For a current dice roll \(x\) and a keep action \(k\), let \(\mathbb{P}(x'\mid x,k)\) be the probability that the next roll is \(x'\). After the second roll, the best value is
The weighted sum is the expected value of choosing a keep; the maximum chooses the best keep. After the first roll, exactly the same calculation is applied one stage earlier:
Finally, at the beginning of the turn no dice have been seen, so all five are rolled:
These four quantities form the whole computational chain: next scorecard value → final scoring choice → second-roll keep → first-roll keep → value before rolling.
Solving the entire game
The remaining question is how the solver obtains the boundary values \(\mathcal{V}\) needed by the scoring equation.
Every time a turn ends, exactly one previously open category is filled. The game therefore always moves toward a completed scorecard and can never return to an earlier scorecard state. That gives the solver a natural order of calculation. It starts with completed scorecards, whose future value is zero. It then solves every state with one category left open, followed by states with two categories open, and continues backward until it reaches the empty scorecard.
For each boundary state, the solver temporarily computes the values for all final rolls, backs those values through the second-roll choices, then through the first-roll choices, and finally obtains the single number \(\mathcal{V}(b)\). The temporary within-turn values can then be discarded. By the time a scoring action refers to a successor scorecard, that successor has already been solved.
This is why no iterative convergence or random game sampling is required. The calculation exhaustively follows the finite dependency graph of the game.
Making the exact calculation practical
The mathematical model does not require a huge stored policy table. Only the boundary values need to survive after the offline calculation. The deployed boundary table uses a 12-bit mask for the non-Yahtzee categories, one of three Yahtzee-box states, and 64 possible capped upper totals. This results in
float64 entries, or exactly 6 MiB. From that table, the within-turn calculations can be reconstructed whenever an actual move needs to be evaluated.
Several precomputed tables make that reconstruction faster without changing the mathematics. The 252 sorted rolls and 32 keep masks have fixed indices; reroll transitions are stored as exact integer counts, sparsely because most successor rolls are impossible for a particular keep; and ordinary category scores are precomputed for every roll. Scorecard-dependent Yahtzee bonuses and Joker rules remain part of the scoring transition rather than being folded into that ordinary score table.
The result is an exhaustive solver with a comparatively small permanent representation. Under the implemented Hasbro 2016 rules, the value of a new game is approximately 254.21 points under optimal play. That number is an expectation over every possible future sequence of fair dice, not a predicted score for any particular game.