A program for optimal yahtzee strategies

Yahtzee ist a popular dice game which combines luck with advantage of the player. The rules are easy and can be read in Wikipedia or other pages. In contrast to some other variants, this programm don't use any bonus rules for a second or third yahtzee. So the maximum reachable score is 375.

Demo

See how it works on yahtzee.holderied.de.

Download

Download and unzip one of the following versions:

Don't start the program with double click. Open a command line image (terminal, console, cmd), change into the yahtzee directory and type yahtzee -h, yahtzee.exe -h, ./yahtzee -h or something like this. If you see the help page it works.

Preparation

Before analysing situations, you have to precompute propabilities and expectation values and store them to file. This takes between 5 to 20 hours. Sorry for that, but the program has to analyse all situations, combined with all dice rolls and different strategies. It's about playing billions of yahtzee games. You also will need about 1.6 GB free space to store tha data files. You run the preparation with The output runs from 524287 down to 0.

States and Situations

I differ between states and situations. The state respects only the sheet, before you roll the dices or select dices to keep. The situation combines a state of the sheet with dices on the table. Between two entries on the sheet, there are 5 situations: 1st roll, 1st selection, 2nd roll, 2nd selection, 3rd roll. All values referring to states are precomputed and stored in the files data/*.dat. All values of situations are computed while running the programm.

Strategies

Strategy 1: Maximize the Expectation Value

The straightforward strategy to calculate is to maximize the expectation value. It's a single player strategy without respecting the opponents game. In average, an optimal player expects a value of 245.904728. You get this value with the command
yahtzee -a - - - - - - - - - - - - - 0 
Now you can play with the options. If you like to analyse a situation of the game you use
yahtzee -a - - 9 - 15 - 24 - - 30 40 0 - 1 22135 
This means The Programm will tell you which dices you should keep and which value you will expect in this case. To understand the program just try
yahtzee -a - - 9 - 15 - 24 - - 30 40 0 - 2 22132 
yahtzee -a - - 9 - 15 - 24 - - 30 40 0 - 3 22232 
yahtzee -a 1 4 9 16 15 18 24 0 25 30 40 0 17 0
yahtzee -a - 2 9 16 15 18 24 0 25 30 40 0 17 0
The strategy of the maximum expectation value isn't optimal to beat an opponent. If you play against another player, your goal is only to get more points than your opponent.

Strategy 2: Reach a given threshold

Another strategy, which points already on the two player strategy, is reaching a given threshold. E.g. your opponent already finished the game and reached 236 point. Your only goal is to beat this.
yahtzee -a 3 2 9 16 15 18 - 0 25 30 40 0 17 1 25244
In this case it's also possible to compute all cases with pencil and paper, but this will take a little time. The strategy computes all cases and is optimal in respect to the goal "reach a given threshold"

Strategy 3: Beat your opponent

To beat your opponent you have to adapt your strategy dynamically to your opponents state. The program does this as follows. It computes all threshold probabilities of the opponent, and optimizes your game with the function (convolution):
p(opponent reaches exactly 0 points) * p(you reach 1 or more points)  
...
+ p(opponent reaches exactly 200 points) * p(you reach 201 or more points) 
+ p(opponent reaches exactly 201 points) * p(you reach 202 or more points)
...
+ p(opponent reaches exactly 375 points) * p(you reach 376 or more points)
You see, the optimal strategy is not precise enough. Would you like to get more points than your opponent or is it enogh to get as much as your opponent. In the second case the goal function is:
p(opponent reaches exactly 0 points) * p(you reach 0 or more points)  
...
+ p(opponent reaches exactly 200 points) * p(you reach 200 or more points) 
+ p(opponent reaches exactly 201 points) * p(you reach 201 or more points)
...
+ p(opponent reaches exactly 375 points) * p(you reach 375 or more points)
The program has implemented both strategies win, winoreven and a third one which is called combined. It's the combination of both and maximizes the expectation of the function win=1, even=0, lose=-1. To analyse a two player situation try:
yahtzee -t p1 - - - - - - - - - - - - - p2 - - - - - - - - - - - - - p1 0
yahtzee -t p1 - - - 12 - - - - - 30 - - - p2 - - - - - - - - - - 40 50 - p1 1 23316

Is this strategy really optimal?

I don't really know! If you find an example to prove it or a way to prove the optimality, it would be great to tell me.

Further features to use the program

Simulate game alone with strategy 1
yahtzee -p1 mev
Simulate game alone with strategy 2, reach 300 points
yahtzee -p1 t300
Simulate games alone with strategy 1
yahtzee -p1 mev 10
Simulate games alone with strategy 1, always using the same initial random (to reproduce the experiment)
yahtzee -p1 mev 10 4711
Simulate two player game, both playing strategy 1
yahtzee -p2 mev mev
Simulate two player game, p1 playing strategy 1, p2 like to win
yahtzee -p2 mev win
Simulate two player game, both playing combined strategy
yahtzee -p2 combined combined
Simulate 10 two player games, initial random is 4711
yahtzee -p2 combined combined 10 4711

For comments or requests for source code, please contact

Felix Holderied (felix@holderied.de) July 10, 2014