Yahtzee

Yahtzee (1956) is a classic dice game where players roll five dice up to three times per turn, trying to make various scoring combinations. The player with the highest total score after 13 rounds wins.

Theory

This solver computes optimal dice-keeping decisions using dynamic programming with precomputed expected values. The approach models Yahtzee as a Markov Decision Process and achieves an expected score of ~229.64 points per game.

Game State

The game state tracks which of the 13 scoring categories have been filled, represented as a 13-bit integer. This gives 213=81922^{13} = 8192 possible game states. For each state, we precompute the expected value of optimal play from that point forward using backward induction.

Dice Representation

A dice configuration is represented as a count vector c=(c1,c2,c3,c4,c5,c6)c = (c_1, c_2, c_3, c_4, c_5, c_6) where cic_i is the number of dice showing face ii. This order-invariant representation reduces the state space from 65=77766^5 = 7776 permutations to just C(n+k1)=C(10,5)=252C(n + k - 1) = C(10, 5) = 252 multisets.

The Bellman Equation

Let V(s)V(s) be the expected value of game state ss (which categories remain). For a single turn with dice cc and rr rolls remaining:

Base case (no rolls left):

V(c,0,s)=maxis[Score(i,c)+V(s{i})]V(c, 0, s) = \max_{i \notin s} \left[ \text{Score}(i, c) + V(s \cup \{i\}) \right]

Recursive case:

V(c,r,s)=maxm[cP(c)V(ckept+c,r1,s)]V(c, r, s) = \max_{m} \left[ \sum_{c'} P(c') \cdot V(c_{\text{kept}} + c', r-1, s) \right]

The key insight is that when choosing which category to score, we consider not just the immediate points but the future expected value of the resulting game state.

Precomputation

Expected values for all 8,192 game states are precomputed offline via backward induction, starting from terminal states (all categories filled) and working backward. This table is loaded at runtime, making real-time optimal play computationally feasible.

Simplifications

To keep the state space tractable, we do not track progress toward the 35-point upper section bonus. Tracking this would multiply states by ~64x (for each possible upper score from 0-63). The precomputed values still achieve near-optimal play in practice.

Probability Reference

Single Roll Probabilities

OutcomeProbabilityWays / Total
Yahtzee (5 of a kind)0.08%6 / 7776
Large Straight1.54%240 / 7776
Four of a Kind1.93%150 / 7776
Full House3.86%300 / 7776
Small Straight12.35%~960 / 7776

Three-Roll Probabilities (Optimal Play)

Starting from a random roll and playing optimally:

OutcomeProbability
Yahtzee~4.6%
Large Straight~16.1%
Small Straight~45.3%
Full House~38.4%
Four of a Kind~20.2%
Three of a Kind~94.5%

Dice

2 rolls left

Scorecard

Upper Section

0/63
Ones
0
Twos
0
Threes
0
Fours
4
Fives
10
Sixes
12
Bonus(63+)
0

Lower Section

0 pts
Three of a Kind
0
Four of a Kind
0
Full House(25)
0
Small Straight(30)
0
Large Straight(40)
0
Yahtzee(50)
0
Chance
26
Yahtzee Bonus(100 each)
0