Maximizing Expected Scores in the Game of Zilch

A Throw of the Dice
Image by Thunderchild7

Zilch is a fun little dice game codified into an online game by Gaby Vanhegan that can be played at http://playr.co.uk/. Zilch is actually a variation of the game Farkle which goes by several other names including Zonk, 5000, 10000, Wimp Out, Greed, Squelch and Hot Dice1. I've worked out the strategy that maximizes your expected game score and wanted to share the analysis, my strategy finder software, and the strategy itself. Depending on whether you have zero, one or two consecutive zilches from previous turns, three successively more conservative turn-play strategies are required to maximize your long term average score. Using these three strategies you rack up an average of 620.855 points per turn, which is the best you can possibly do.

Beyond the scope of Gaby's implementation of Zilch, the scoring rules of Farkle vary from venue to venue and the strategies provided here do not generally apply, but the analysis and the software do.

If you understand conditional probabilities, expectations, and can do a little algebra, you should be able to follow along. If you're just here to take the money and go pound someone in the game, you'll need to at least read and understand Strategy Formulation before you try to interpret the tables.

Contents

Background

I've found several blog postings where folks have offered probabilistic analyses of various aspects of the game2,3,4, but none (that I've seen) find the game strategy that maximizes your expected points. It is possible that I'm the first to publish these solutions. If not, it was still a fun problem. I've always enjoyed software, algorithms, optimization, and probabilities and this problem delves into all of these areas.

The Rules of Zilch

Zilch is played with two players and six six-sided dice. (Though really there's nothing to stop you playing with more people, but this is not supported in the online game.)

Each player takes turns rolling the dice. The dice in a roll can be worth points either individually or in combination. If any points are available from the roll, the player must set aside some or all of those scoring dice, adding the score from those dice to their point total for the turn. After each roll, a player may either reroll the remaining dice to try for more points or may bank the points accumulated this turn (though you can never bank less than 300 points).

If no dice in a roll score, then the player loses all points accumulated this turn and their turn is ended. This is called a zilch, a sorrowful event indeed.

If all dice in a roll score, the player gets to continue his turn with all six dice. This is called a free roll and is guaranteed to brighten your day.

A player may continue rolling again and again accumulating ever more points until he either decides to bank those points or loses them all to a zilch.

If a player ends three consecutive turns with a zilch, they not only lose their points from the turn but also lose 500 points from their banked game score. (This is the only way to lose banked points.) After a triple zilch, your consecutive zilch count is reset to zero so you're safe from another triple zilch penalty for at least three more turns.

The game ends when one player has banked a total of 10,000 points and all other players have had a final turn.

Scoring is as follows:

  • Each 1 is worth 100 points.
  • Each 5 is worth 50 points.
  • A set of three 1s is worth 1000 points.
    A set of three 2s is worth 200 points.
    A set of three 3s is worth 300 points.
    A set of three 4s is worth 400 points.
    A set of three 5s is worth 500 points.
    A set of three 6s is worth 600 points.
    Each extra die in a set doubles the value of the set. So four 4s are worth 800 points and six 1s are worth 8000.
  • Three pair is worth 1500 points.
  • A six die straight is worth 1500 points.
  • Six dice with no other scoring options at all are worth 500 points. (And this is why a 6 die roll is called a free roll: you can't zilch when rolling 6 dice.)
  • Each die can only be used once when scoring. (If you roll two 1s, two 2s, and two 3s you can either count the two 1s for 200 or use all six dice for three-pair and 1500 points — you can't use the ones both ways for 1700 points.)

Limitations

The strategy presented will maximize your expected Zilch scores, but this is not necessarily the same strategy that will let you reach 10,000 points in the fewest number of turns; and certainly falls short of giving a complete gaming strategy that will maximize your chances of winning the game5, the holy grail of Zilch analysis. In particular, the strategy considers neither your current overall score, nor your opponent's score, nor the fact that the game ends when a player reaches 10,000 points (after the other player gets a final turn). All that I offer is a way to maximize your expected Zilch scores.

My intuition is that when you're in the lead you should play more conservatively; and when you're behind you should play more aggressively. (Though I think it a common mistake to be too aggressive too early when behind.) Consider this extreme example. Let's say you're currently beating your opponent 7500 to 1500 and it's your turn. On your turn you rack up 2500 points and are faced with the choice of either banking the 2500 or rolling five dice to go for more points. The strategy identified here advises you to roll the five dice; but surely in this case it is better to bank the 2500, putting you at the game goal of 10,000 points and forcing your opponent to try to put out 8550 points in a single turn to steal the win away from you.

Analysis

Strategy Formulation

I will start by showing how to maximize the expected points for a particular turn. Because of the three consecutive zilch rule, the strategy that actually maximizes the average points gained across all turns is different: it is possible to trade off some expected gain in those turns where you have either zero or one consecutive zilches to reduce your zilch probability and more strongly avoid even getting into a turn where you are facing your third consecutive zilch. I will solve for this more complete strategy later, but for now let's stick with maximizing the expected points for a single turn and just ignore how such a greedy strategy might negatively affect the outcome of subsequent turns.

For my purposes, a Zilch turn has a state that may be completely defined by two variables (s, n) where s is the number of points accumulated in the current turn, and n is the number of dice you are about to roll. At the beginning of a new turn, the turn state is (s=0, n=6). Let's say for your opening roll you throw:

1, 3, 3, 4, 4, 6

The turn state will then advance to (s=100, n=5). You actually have no choice here: you must always select at least one scoring die and since the 1 (worth 100 points) is the only scoring die, you must select it. Furthermore, you are not allowed to bank less than 300 points so you must roll the five remaining dice.

Suppose with the remaining 5 dice you roll:

1, 1, 2, 3, 5

Here you have three scoring dice: two 1s and a 5. You now have a choice of turn states that you may enter:

  1. (s=150, n=4) (take just the 5)
  2. (s=200, n=4) (take a single 1)
  3. (s=250, n=3) (take a single 1 plus the 5)
  4. (s=300, n=3) (take the two 1s)
  5. (s=350, n=2) (take the two 1s plus the 5)

Note that s includes not just the points taken from this roll, but also all points accumulated in previous rolls during this turn as well. It should be clear that state B is better than A and state D is better than C. Of the remaining three states (B, D and E) it's not so obvious which is better. You also have the option of banking from either of states D or E (but not from B since you don't have 300 points in that case). Obviously, banking from state D is just plain dumb: if you're going to bank you'll do so from state E to bank as many points as you can! That leaves you with four reasonable choices:

  1. enter state B = (s=200, n=4) and roll;
  2. enter state D = (s=300, n=3) and roll;
  3. enter state E = (s=350, n=2) and roll; or
  4. enter state E = (s=350, n=2) and bank.

My objective is to find the optimal turn play strategy that defines what to do in all such situations which when followed will maximize the expected number of points for the entire turn starting from any given turn state.

Let E(s, n) be the expected number of additional points you will gain for the turn if you (perhaps non-optimally) roll while in state (s, n) but then follow the optimal turn strategy (which we hope to find) for all subsequent decisions in the turn. Note that E(s, n) includes not just the expected points for the upcoming roll, but all the expected points from all subsequent rolls, if any, as dictated by chance and the optimal play strategy.

Suppose we somehow solve for E(s, n) and find that:

E(s=200, n=4) =149
E(s=300, n=3) =34
E(s=350, n=2) =-20

Applying this information to the example leads to the following final expected scores for the turn.

  1. Final expected score by rolling from state B = 200 + 149 = 349.
  2. Final expected score by rolling from state D = 300 + 34 = 334.
  3. Final expected score by rolling from state E = 350 - 20 = 330.
  4. Final expected score by banking from state E = 350.

So, the choice that leads to the highest expected score for the turn is to bank the 350 points. From this example, it should be clear that if we can find E(s, n) for all possible game states (s, n) we'll have the optimal Zilch turn play strategy.

Finding E(s,n) - the Zilch strategy function

Let,

T(s, n) = { s + max(0, E(s, n))
s + E(s, n)
 for s ≥ 300
 for s < 300
(1)

T(s, n) is simply the total expected points for the turn given that you are in turn state (s, n) and you follow the optimal strategy. The special case for s < 300 models the rule that you can't bank less than 300 points. The max function used when s ≥ 300 models the requirement that you bank when E(s, n) is negative, and roll otherwise.

Suppose we are in some particular state (S, N) then let r1, r2, … rR be all possible rolls of N dice that do not result in a zilch. For any given roll ri you can potentially enter multiple game states (s1, n1), (s2, n2), … (sK, nK) (depending on which combination of scoring dice you choose — just like in the previous example). Define C(ri, S, N) to be the particular scoring combination among all scoring combinations possible with roll ri that when applied to turn state (S, N) will advance the turn to the new state (Si, Ni) that maximizes T. What could be simpler? Let CS be the number of points taken in scoring combination C, and let CN be the number of dice used in scoring combination C.

I also need a simple little function F(n) to reset the state variable n back to 6 when a score is selected that uses all remaining dice:

F(n) = { 6
n
 for n = 0
 for n ≠ 0
(2)

We can now express E(S, N) as a weighted sum of the expected scores of all states reachable from (S, N):

E(S, N) = -pN(S+y) + i  T(Si, Ni) - S
6N
(3)

where

Si=S + CS(ri, S, N)
Ni=F(N - CN(ri, S, N))
pN=probability of zilching when you roll N dice
y=zilch penalty.

To handle the three zilch rule, I've introduced the constant y which gives the additional penalty (beyond loss of all turn points) for rolling a zilch. Setting y to 0 models turns where you have only zero or one consecutive zilches. Setting y to 500 models turns where you are playing with two consecutive zilches. As we shall see, these two cases will lead to two different turn play strategies.

The term -pN(S+y) gives the expected decrease in your score due to the likelihood of a zilch. The terms (T(Si, Ni) - S) give the expected increase in your score given that you throw ri. Summing over all possible ri and multiplying by the probability of rolling any particular ri gives the appropriate weighted sum.

Equation 3 expresses E(S, N) in terms of the T values of all the game states reachable from (S, N). But here's the important thing: any game state (s, n) reachable by any roll r from (S, N) has s > S. (Your score can only go up if you don't zilch and by definition r is not a zilching roll.) So, if we already know T(s, n) for all s > S, then we can calculate E(S, N) using the above summation.

I claim there exists some large value of accumulated turn points SBIG where the optimal turn play strategy is to always bank when faced with rolling less than six dice and to always roll when you have six dice to roll. If I set SBIG equal a million points, then I'm claiming that if you've somehow accumulated a million or more points on the current turn (an absurdly large number of points to be sure) you'll want to bank them if you're ever faced with rolling five (or fewer) dice: the 7% chance of losing all of your points far outweighs any comparatively meager gains you might achieve by continuing to roll. This claim is equivalent to saying:

E(s, n) < 0 for s ≥ SBIG, 1 ≤ n ≤ 5 (4)

Now if you have six dice to roll, you risk nothing so you might as well further insult your opponent by adding to your million point score. The number of points you expect to gain in this situation through the end of your turn is a constant:

E(s, n) = EBIG6 for s ≥ SBIG, n = 6 (5)

Here's how to solve for EBIG6. Let

EB=the expected number of points gained from a single roll of 6 dice given that the roll does not grant another free roll (so you have to bank).
EF=the expected number of points gained from a single roll of 6 dice given that the roll does grant another free roll.
pF=probability of a 6 die roll granting another free roll.

These terms are easily calculable by simply enumerating all the six die rolls and determining the best possible scoring combination in each case. (There's a subtlety here I'm not going to bore you with regarding how to score a roll of four 1s and a pair of either 2s, 3s, 4s or 6s; I explain this in detail in the software comments for the interested reader.) Once found they can be used in the following sum:

EBIG6 = (1-pF) EB + pF (EF + (1-pF) EB + pF (EF + ... )) (6)

This nicely simplifies to,

EBIG6 =  EB + pF
1-pF
EF (7)

Combining Equations 1, 4 and 5 give

T(s, n) = { s + EBIG6
s
 for s ≥ SBIG, n = 6
 for s ≥ SBIG, 1 ≤ n ≤ 5
(8)

Knowing T(s, n) for s ≥ SBIG, we can now use Equation 3 to iteratively calculate E(SBIG - 50, n), E(SBIG - 100, n), … E(0, n). The rest is just the grunt work of writing the software to implement the curious function C; solving for EBIG6; and solving for all E(s, n) for s < SBIG. (Did I just slander my own profession?) But before we start grunting let's see what we can do about the three consecutive zilch problem.

Maximizing expected score across all turns

There are actually three different types of turns:

T0: a turn played with no previous consecutive zilches,
T1: a turn played with one previous consecutive zilch; and
T2: a turn played with two previous consecutive zilches.

Using the technique already described, we can find the strategies that will maximize the expected points in each of these turns independently, but what we really want is a strategy for each turn that when used together will maximize the average score for all of these turn types when weighted by the frequency of the appearance of the turn type in a game.

If zi is the probability of zilching while in turn type Ti (while following some strategy designed specifically for that turn type) then we have the state transition diagram shown in Figure 1.

state
transition diagram showing transitions between states T0, T1 and T2
Figure 1. State transition diagram governing the transitions between states T0, T1 and T2.

Performing a steady state analysis of this system we can find the probability ti of being in any particular state Ti. (I.e., we want to find what fraction of our turns will be of each type.) We have these flow equations which must balance:

t0 = (1-z0)t0 + (1-z1)t1 + t2
t1 = z0t0
t2 = z1t1

Also

t0 + t1 + t2 = 1

Solving gives

t0 = 1 / (1 + z0 + z0z1)
t1 = z0 / (1 + z0 + z0z1)
t2 = z0z1 / (1 + z0 + z0z1)

Define Ei to be the expected points gained for a turn of type Ti. Then the average score for all turns is:

EAVG = t0E0 + t1E1 + t2E2

or

EAVG = E0 + z0E1 + z0z1E2
1 + z0 + z0z1
(9)

EAVG is what we want to maximize. Both Ei and zi are just a function of the strategy used to play a turn of type Ti. The strategy employed for T2 only affects E2, so E2 can be independently maximized — something we already know how to do. That leaves the strategies for T0 and T1. E2 is the term that's pulling down our average score since it's the turn played with the 500 point penalty for zilching. Can we modify our strategies for T0 and/or T1 in such a way so as to trade off some of our expected gains in those turns to reduce the coefficient z0z1 on E2 and thereby actually increase EAVG?

In Equation 3, I introduced the variable y to model the penalty for a zilch in a game. I said it should be set to 0 normally, but set to 500 if we are playing a turn where the third consecutive zilch is imminent. If we extend this idea and allow y to become a free variable, we can examine different levels of trade-off between expected score and the probability of zilching. For each y value, we'll find the optimal strategy given that zilch penalty; and then find both the expected number of points per turn and the probability of zilching on the turn for that strategy. EAVG then becomes a function of just two variables y0 and y1. We then need only to find the particular values Y0 and Y1 that maximize EAVG. Piece of cake!

When doing this analysis, it's important to understand that the penalties y0 and y1 are artificial. The true zilch penalty for these turns is of course zero. Accordingly, the values calculated for E(s, n) will not represent the true expected change in points for the turn from state (s, n). But the values E(s, n) do still define a strategy, dictating that you roll if E(s, n) is positive, and that you bank when E(s, n) is negative. Likewise, the E(s, n) values are still used in the normal way to determine which state among the reachable states after a roll is most desirable. To get the actual expected increase in score from state (s, n), you must add back the false zilch penalty times the probability of zilching for the remainder of the turn. Although you could calculate this for all states (s, n); we only really need to know the true expectation for the turn as a whole, which we can get by correcting E(0, 6). This gives rise to the notion of a corrected expectation for the turn:

EC = E(0,6) + yz (10)

Enough analysis! On to the results! Now I am become death, destroyer of Zilch.

Results

The optimal strategies

I wrote a little java program that solves for EBIG6; finds E(s,n) for a supplied zilch penalty, y; for that strategy, calculates the probability of zilching, z; and also outputs the corrected expected points for the turn, EC. Running the software for the case y=0 we get:

EBIG6 = 478.237
EC = E(0, 6) = 623.017
z =.193326

So the best you can do for a single turn is to rack up an average of about 623 points, and zilch about 1 time in 5. I'll get to the actual strategy tables shortly, but first let's solve for the optimal strategies required for the three zilch rule for turn types T0, T1 and T2.

Finding the best strategy for T2 is easy: just set y=500 and you get these results:

E2 = E(0, 6) = 547.157
z2 = .132148

You don't use EC here since the 500 point zilch penalty is not artificial but real. This penalty reduces the maximum expected points per turn by about 12%. The more conservative play required here also reduces the zilch probability by about a third.

To find the best strategies for T0 and T1 we need to let the zilch penalty for those two turn types (y0 and y1) vary and then maximize EAVG as given by Equation 9. Table 1 shows how varying the penalty for zilching (y) affects the probability of zilching (z) and the corrected expected points per turn (EC). Due to the integral nature of the problem, there are fairly large ranges of y that have no affect on the strategy. I'm only listing y values among those tried that produced a strategy change:

Table 1. Probability of zilching for the turn, z, and corrected expected score, EC, as a function of the zilch penalty, y.

yzEC
00.193326623.017489
100.193326623.017488
150.193302623.017141
170.193296623.017049
220.190399622.955542
240.182110622.759187
260.178151622.657753
270.177759622.647306
300.177757622.647238
380.177723622.645977
420.177619622.641662
440.174575622.509618
650.174551622.508057
670.174543622.507569
680.170991622.268940
720.170988622.268745
770.170631622.241338
800.170620622.240487
880.170484622.228569
920.170389622.219825
1150.170387622.219696
1170.170383622.219130
1220.157678620.678963
1270.157507620.657322
1300.157498620.656168
1380.157427620.646349
1420.157364620.637441
1650.157362620.637123
1670.157357620.636297
1720.157356620.636150
1770.157286620.623706
1800.157271620.620945
1880.157239620.615023
1920.157171620.602036
2030.144131617.962533
2150.144129617.962108
2170.144120617.960165
2220.143469617.816023
2270.143448617.811242
2300.143424617.805798
2310.142245617.534058
2350.140672617.165031
2380.140661617.162252
2420.140573617.141121
2650.140572617.140733
2670.140558617.137106
2720.140556617.136678
2770.140553617.135694
2800.140521617.126870
2880.140519617.126208
2920.140413617.095273
3150.140411617.094663
3170.140401617.091542
3220.140391617.088225
3270.140390617.088121
3300.140376617.083493
3380.140376617.083407
3400.140343617.072035
3420.140031616.965512
3650.140029616.964776
3670.139995616.952543
3720.139981616.947224
3800.139967616.942009
3920.139576616.788919
4150.139575616.788296
4170.139555616.780056
4220.139544616.775513
4300.139522616.765914
4420.139326616.679483
4650.139325616.678925
4670.139318616.675611
4720.139308616.670956
4800.139279616.657114
4810.132230613.270797
4920.132148613.230640

Pumping this table through a little awk script (which I hacked out at a command prompt and didn't save for you), I found that EAVG is maximized when Y0 = 0 and Y1 = 72. Here are the summary statistics:

y0 =0
z0 =.193326
E0 =623.017
 
y1 =72
z1 =.170988
E1 =622.269
 
y2 =500
z2 =.132148
E2 =547.157
This gives
EAVG = 620.855

For turn type T0, you're best off just going for the maximum expected points possible: trying to play more conservatively doesn't reduce your zilch probability (or the probability of entering state T2) enough to offset the corresponding loss in expected points for turns of type T0.

For turn type T1 (when you've got one consecutive zilch) you're best off pretending you will be penalized an extra 72 points if you zilch. This reduces your expected score by only 0.2% but reduces your probability of zilching by about 10%. This little extra protection against your third consecutive zilch slightly increases your overall average turn scores.

Let's move on to the actual strategies.

Strategy T0: playing with no consecutive zilches

Table 2 below gives E(s, n) for all s ≤ 3200 for the case y = 0. This is the strategy achieving the maximum expected points for a turn and is the best strategy to use if you didn't zilch on your previous turn. The first table entry is EBIG6 = 478.237. The last table entry gives the total expected points for the turn: E0 = 623.017. The probability of zilching for the entire turn (not shown in the table) is z0 = .193326.

Table 2. E(s,n) for turn type T0.

n
s654321
3200478.237-6.608-340.997-775.515-1319.085-1948.921
3150478.237-2.750-333.126-761.626-1296.863-1915.588
3100478.2371.108-325.256-747.737-1274.640-1882.254
3050478.3234.966-317.386-733.848-1252.418-1848.921
3000478.7068.824-309.515-719.959-1230.196-1815.573
2950479.30112.682-301.645-706.070-1207.971-1782.162
2900479.89716.540-293.774-692.181-1185.734-1748.665
2850480.49220.398-285.904-678.291-1163.471-1715.134
2800481.08824.256-278.033-664.394-1141.189-1681.602
2750481.68328.114-270.161-650.488-1118.900-1648.070
2700482.27831.973-262.286-636.578-1096.612-1614.538
2650482.87435.833-254.407-622.667-1074.324-1581.006
2600483.47039.694-246.527-608.754-1052.035-1547.475
2550484.06943.558-238.645-594.840-1029.747-1513.943
2500484.67747.423-230.761-580.924-1007.458-1480.410
2450485.29051.290-222.876-567.008 -985.170-1446.876
2400485.97555.157-214.989-553.089 -962.881-1413.339
2350486.94959.026-207.101-539.170 -940.591-1379.789
2300488.22262.896-199.211-525.251 -918.299-1346.179
2250489.49666.767-191.320-511.331 -895.995-1312.472
2200490.77170.640-183.429-497.410 -873.664-1278.714
2150492.04874.513-175.538-483.482 -851.309-1244.955
2100493.32678.386-167.645-469.545 -828.945-1211.197
2050494.60482.260-159.748-455.601 -806.581-1177.438
2000495.88486.136-151.848-441.655 -784.217-1143.678
1950497.16490.013-143.944-427.706 -761.853-1109.919
1900498.44893.894-136.037-413.755 -739.488-1076.159
1850499.74097.776-128.128-399.802 -717.124-1042.398
1800501.041101.661-120.218-385.848 -694.759-1008.635
1750502.344105.547-112.306-371.893 -672.394 -974.870
1700503.867109.434-104.392-357.936 -650.029 -941.102
1650505.684113.323-96.476-343.979 -627.662 -907.298
1600507.502117.213-88.558-330.022 -605.289 -873.408
1550509.327121.105-80.641-316.064 -582.895 -839.469
1500511.172124.998-72.723-302.102 -560.480 -805.529
1450513.033128.891-64.805-288.132 -538.055 -771.583
1400514.894132.784-56.883-274.156 -515.630 -737.633
1350516.756136.679-48.958-260.177 -493.203 -703.679
1300518.619140.575-41.030-246.196 -470.774 -669.725
1250520.484144.474-33.100-232.212 -448.345 -635.771
1200522.356148.374-25.167-218.227 -425.916 -601.816
1150524.236152.277-17.233-204.240 -403.487 -567.860
1100526.119156.180-9.297-190.252 -381.057 -533.901
1050528.180160.085-1.360-176.263 -358.627 -499.941
1000530.368163.9926.579-162.273 -336.196 -465.950
950532.560168.76314.520-148.283 -313.760 -431.909
900534.870174.57722.461-134.293 -291.310 -397.845
850537.684180.57030.403-120.299 -268.848 -363.762
800540.959186.56438.345-106.301 -246.379 -329.574
750544.307192.55946.289-92.299 -223.889 -295.226
700547.655198.55554.235-78.294 -201.356 -260.789
650551.006204.87962.183-64.276 -178.780 -226.340
600554.457212.14670.136-50.240 -156.188 -191.890
550558.365219.98978.096-36.194 -133.594 -157.423
500562.820227.83886.062-22.143 -110.997 -122.863
450567.530235.69494.033-8.089-88.381-88.136
400572.248243.557102.0105.970-65.722-53.275
350576.985251.428---43.013-18.370
300581.746--34.134-20.27416.539
250---48.2436.14851.455
200--149.23264.64540.331-
150--163.98191.507--
100-306.667184.939---
50-322.318----
0623.017-----

Using this table, you can easily figure out what to do in any turn play situation. Consider these examples.

  • With 300 points and 3 dice to roll, you should roll.
  • With 300 points and 2 dice to roll, you should bank.
  • With 300 points and 1 die to roll, you should roll.
  • With an opening roll of (3, 3, 3, 5, 2, 6) you should take the 5 and roll five dice.
  • With an opening roll of (1, 1, 1, 1, 4, 4), you should score it as three pair for 1500 and take a free roll.
  • If you already have 500 points and then roll (1, 1, 1, 1, 4, 4), you should score it as a set of four 1s for 2000 and bank.

Strategy T1: playing with one consecutive zilch

Table 3 below gives E(s, n) for all s ≤ 3200 for the case y = 72. This is the optimal strategy for turns of type T1 (when you're playing with one consecutive zilch). The corrected expected points for the turn is: E1 = 622.269. The probability of zilching for the entire turn is z1 = .170988.

Table 3. E(s,n) for turn type T1.

n
s654321
3200478.237-12.164-352.330-795.515-1351.085-1996.921
3150478.237-8.306-344.460-781.626-1328.863-1963.588
3100478.237-4.448-336.589-767.737-1306.640-1930.254
3050478.237-0.590-328.719-753.848-1284.418-1896.921
3000478.2373.268-320.848-739.959-1262.196-1863.588
2950478.4907.126-312.978-726.070-1239.974-1830.254
2900479.03910.984-305.108-712.181-1217.751-1796.879
2850479.63514.842-297.237-698.292-1195.522-1763.412
2800480.23018.700-289.367-684.403-1173.271-1729.888
2750480.82622.558-281.497-670.510-1150.994-1696.356
2700481.42126.416-273.625-656.607-1128.707-1662.824
2650482.01630.275-265.751-642.699-1106.419-1629.292
2600482.61234.134-257.874-628.788-1084.130-1595.760
2550483.20837.995-249.995-614.876-1061.842-1562.229
2500483.80441.858-242.113-600.962-1039.554-1528.697
2450484.40845.722-234.230-587.047-1017.265-1495.165
2400485.02049.588-226.345-573.131-994.977-1461.631
2350485.63453.456-218.460-559.214-972.688-1428.095
2300486.43657.324-210.572-545.295-950.399-1394.558
2250487.66261.193-202.683-531.375-928.109-1360.988
2200488.93565.064-194.792-517.456-905.813-1327.317
2150490.21068.936-186.901-503.536-883.495-1293.567
2100491.48672.808-179.010-489.612-861.147-1259.809
2050492.76476.682-171.118-475.678-838.785-1226.051
2000494.04280.555-163.224-461.737-816.421-1192.292
1950495.32184.430-155.325-447.791-794.057-1158.532
1900496.60088.307-147.422-433.843-771.693-1124.773
1850497.88292.186-139.516-419.893-749.329-1091.013
1800499.16996.067-131.608-405.942-726.964-1057.253
1750500.46899.951-123.698-391.988-704.600-1023.492
1700501.770103.837-115.788-378.034-682.235-989.727
1650503.075107.723-107.874-364.077-659.870-955.960
1600504.884111.611-99.959-350.120-637.503-922.192
1550506.702115.501-92.042-336.163-615.137-888.340
1500508.520119.393-84.125-322.206-592.755-854.402
1450510.357123.285-76.207-308.248-570.346-820.463
1400512.214127.178-68.289-294.281-547.922-786.520
1350514.075131.071-60.370-280.306-525.497-752.572
1300515.936134.965-52.446-266.328-503.071-718.619
1250517.799138.861-44.519-252.348-480.643-684.665
1200519.663142.758-36.590-238.365-458.214-650.711
1150521.529146.658-28.658-224.381-435.785-616.756
1100523.408150.559-20.724-210.394-413.356-582.801
1050525.290154.463-12.789-196.408-390.926-548.844
1000527.217158.367-4.853-182.418-368.496-514.884
950529.405162.2733.086-168.429-346.066-480.915
900531.595166.58511.026-154.439-323.633-446.896
850533.840171.94018.967-140.449-301.191-412.833
800536.398177.93326.908-126.458-278.733-378.761
750539.486183.92734.850-112.461-256.266-344.627
700542.833189.92142.793-98.460-233.787-310.353
650546.182195.91750.738-84.457-211.274-275.947
600549.531201.97058.685-70.445-188.717-241.498
550552.913208.69666.637-56.417-166.130-207.048
500556.531216.53774.593-42.375-143.535-172.593
450560.750224.38482.556-28.326-120.940-138.093
400565.457232.23790.525-14.273-98.336-103.453
350570.171240.097---75.702-68.632
300574.899--13.848-53.014-33.729
250---27.930-30.2821.178
200--130.18935.303-7.274-
150--141.07447.867--
100-288.116151.530---
50-298.518----
0609.958-----

Strategy T2: playing with two consecutive zilches

Table 4 below gives E(s, n) for all s ≤ 3200 for the case y = 500. This is the optimal strategy for turns of type T2 (when you're playing with two consecutive zilches). The expected points for the turn is: E2 = 547.157. The probability of zilching for the entire turn is z2 = .132148.

Table 4. E(s,n) for turn type T2.

n
s654321
3200478.237-45.189-419.700-914.403-1541.307-2282.254
3150478.237-41.331-411.830-900.515-1519.085-2248.921
3100478.237-37.472-403.960-886.626-1496.863-2215.588
3050478.237-33.614-396.089-872.737-1474.640-2182.254
3000478.237-29.756-388.219-858.848-1452.418-2148.921
2950478.237-25.898-380.348-844.959-1430.196-2115.588
2900478.237-22.040-372.478-831.070-1407.974-2082.254
2850478.237-18.182-364.608-817.181-1385.751-2048.921
2800478.237-14.324-356.737-803.292-1363.529-2015.588
2750478.237-10.466-348.867-789.403-1341.307-1982.254
2700478.237-6.608-340.997-775.515-1319.085-1948.921
2650478.237-2.750-333.126-761.626-1296.863-1915.588
2600478.2371.108-325.256-747.737-1274.640-1882.254
2550478.3234.966-317.386-733.848-1252.418-1848.921
2500478.7068.824-309.515-719.959-1230.196-1815.573
2450479.30112.682-301.645-706.070-1207.971-1782.162
2400479.89716.540-293.774-692.181-1185.734-1748.665
2350480.49220.398-285.904-678.291-1163.471-1715.134
2300481.08824.256-278.033-664.394-1141.189-1681.602
2250481.68328.114-270.161-650.488-1118.900-1648.070
2200482.27831.973-262.286-636.578-1096.612-1614.538
2150482.87435.833-254.407-622.667-1074.324-1581.006
2100483.47039.694-246.527-608.754-1052.035-1547.475
2050484.06943.558-238.645-594.840-1029.747-1513.943
2000484.67747.423-230.761-580.924-1007.458-1480.410
1950485.29051.290-222.876-567.008-985.170-1446.876
1900485.97555.157-214.989-553.089-962.881-1413.339
1850486.94959.026-207.101-539.170-940.591-1379.789
1800488.22262.896-199.211-525.251-918.299-1346.179
1750489.49666.767-191.320-511.331-895.995-1312.472
1700490.77170.640-183.429-497.410-873.664-1278.714
1650492.04874.513-175.538-483.482-851.309-1244.955
1600493.32678.386-167.645-469.545-828.945-1211.197
1550494.60482.260-159.748-455.601-806.581-1177.438
1500495.88486.136-151.848-441.655-784.217-1143.678
1450497.16490.013-143.944-427.706-761.853-1109.919
1400498.44893.894-136.037-413.755-739.488-1076.159
1350499.74097.776-128.128-399.802-717.124-1042.398
1300501.041101.661-120.218-385.848-694.759-1008.635
1250502.344105.547-112.306-371.893-672.394-974.870
1200503.867109.434-104.392-357.936-650.029-941.102
1150505.684113.323-96.476-343.979-627.662-907.298
1100507.502117.213-88.558-330.022-605.289-873.408
1050509.327121.105-80.641-316.064-582.895-839.469
1000511.172124.998-72.723-302.102-560.480-805.529
950513.033128.891-64.805-288.132-538.055-771.583
900514.894132.784-56.883-274.156-515.630-737.633
850516.756136.679-48.958-260.177-493.203-703.679
800518.619140.575-41.030-246.196-470.774-669.725
750520.484144.474-33.100-232.212-448.345-635.771
700522.356148.374-25.167-218.227-425.916-601.816
650524.236152.277-17.233-204.240-403.487-567.860
600526.119156.180-9.297-190.252-381.057-533.901
550528.180160.085-1.360-176.263-358.627-499.941
500530.368163.9926.579-162.273-336.196-465.950
450532.560168.76314.520-148.283-313.760-431.909
400534.870174.57722.461-134.293-291.310-397.845
350537.684180.570---268.848-363.762
300540.959---106.301-246.379-329.574
250----92.299-223.889-295.226
200--37.142-128.047-266.961-
150--8.190-189.755--
100-196.017-32.853---
50-167.775----
0547.157-----

Comparing Table 4 with Table 2 you can see that playing with two consecutive zilches is almost identical to playing without any consecutive zilches while pretending you have 500 more points for the turn than you really do. To see this compare the 500 point line in Table 4 with the 1000 point line in the Table 2. They are identical. This remains true until you get down to point values below 300 at which time the 300 point minimum bank rule forces you to roll even though rolling gives a negative expected change in your score.

Software

The software I wrote to find optimized Zilch strategies is 718 lines of java code (or 322 lines comments stripped). Please observe the GNU public license copyright protection or I may have to introduce you to my friend Guido. You can download with either zip or tgz compression as convenient:

Downloads: zilch.zip OR zilch.tgz

The compile command is simply:

javac Zilch.java

Then to run it type:

java Zilch

You can optionally add a zilch penalty to the command line. For example, to run the program with y = 500 type:

java Zilch 500

To find the best strategy for variations of the game that use different scoring rules, just change the scoring constants at the top of the file. If you set a score to zero, then that score combination is effectively eliminated from the game and is instead treated as a zilch. So if in your Farkle variant, the six-die nothing roll is just a zilch, you need only set NOTHING_SCORE = 0. The software will then interpret this as a zilching roll.

EBIG6 is calculated for you. If you set the NOTHING_SCORE to 0, (giving you a non-zero chance of zilching on a 6 die roll) then EBIG6 will be correctly initialized to 0. There's a chicken-and-egg problem associated with the calculation of EBIG6 which required a bit of finger work to resolve reliably in the face of various possible scoring changes. Check out the comments for method initEBIG6 if you're interested.

The smallest valid value for SBIG is also determined through a binary search, so you need not worry about changing that for different scoring options.

On my 10 year old home computer, the strategy for Zilch is determined in about 7 seconds. Farkle strategies take about 30 seconds. (Farkle is much slower because SBIG has to be set big enough that the chance of a 6 die farkle out-weighs the potential gains of a 6 die roll.) No doubt you could solve these same problems in a tiny fraction of a second with appropriate optimizations, but I personally don't have a need for better performance.

Conclusions

This was a fun problem. The trick is to work the problem backwards: finding the expected scores for high point states first, and then working your way back down to lower and lower scores until finally you get the expected score from the starting state. Everything else is just details (which hopefully I've gotten correct).

One thing I found surprising about the results is just how incredibly insensitive the corrected expected turn score is to the zilch penalty. The optimal strategy for the case of an infinite zilch penalty drops the probability of zilching from .193326 down to .126959 (the minimum zilch probability you can achieve for a turn). Playing that same strategy on a turn where the zilch penalty is actually zero drops your expected score from 623.017 down to 605.851 — it only costs you 17 points per turn! That's less than 300 points over the course of a typical game, and that's nothing in a game of Zilch. I think this is true because almost all the big points in Zilch come from 6 die rolls where there's no chance to zilch. So, playing to reach 300 points as reliably as you can and then banking as soon as you face a roll of less than six dice reduces your expected scores very little compared to playing for maximum expected points. I found this very surprising and somehow unsatisfying.

I'd be pleased to know if you found this document comprehensible; or if you found any errors in the analysis or the software. Leave a comment or send me an email. If you're lucky, you might even meet me masquerading as pips in a game of Zilch, just don't expect to win.

References

  1. FARKLE, Wikipedia.
  2. Multinomial Coefficients and Farkle, Cap Khoury, Jul. 2009.
  3. Farkle Odds, Gregory Graham, August 2009.
  4. Study of the game Zilch part 1, Leadhyena Inrandomtan, November 2008.
  5. FARKLE, Expectation, and Knowing What You Want, Cap Khoury, August 2009.

About matt

I live in Lakewood, Colorado with my wonderful wife Tammy and three fine children Aaron, Becky and Cate. I'm an electrical engineer by education, but worked as a software developer for about 20 years. I recently took a promotion to full time care giver, but will likely return to the grind once the kids are a little older. I coach basketball, sing in two different church choirs, tutor mathematics and physics at a local high school, and spend what other time I can find pursuing home improvement projects and several pet software projects.
This entry was posted in Uncategorized. Bookmark the permalink.

10 Responses to Maximizing Expected Scores in the Game of Zilch

  1. matt says:

    I’ve discovered a very tiny error: because I was only printing out zilch probabilities and corrected expected scores to six decimal places, the script I ran the data through picked the wrong strategy for turn type T0: it turns out that you should really play a turn when you have no consecutive zilches as if you’ll lose an extra 10 points. This corresponds to the second strategy in Table 1. The error is only on the order of a millionth of a point per turn played and so is perhaps not worth mentioning, but in the interest of correctness I mention it anyway! I’m not going to bother modifying this document to correct it. The search algorithm I use in the Farkle Strategy Generator does not suffer from this rounding error.

  2. mh says:

    Thats quite a nice article. The Math behind let u proof the sense for your strategy :-)

  3. Lebossle says:

    Are you sure that that’s right? On conclusions you say that if when you zilch you get an infinite penalty your average roll remains positive: isn’t that impossible since there is always a chance not infinitely small of zilching, so your average score should be negative infinite?

  4. matt says:

    Hello Lebossle,

    Thank you for your comment. The only thing I’m sure of is death and taxes.

    In that paragraph of my conclusions, I was talking about the corrected expected score, but I can definitely see how it was confusing especially if you didn’t read the entirety of the article. I’ve taken liberty to rewrite that paragraph to make it (hopefully) more clear. For that discussion, the zilch penalty is zero, but I’m telling the equations that the zilch penalty is infinite to trick them into working very very hard to avoid zilching. By doing this I produce the most conservative strategy you can possibly play. (I.e., the strategy that gets you to 300 points with the smallest probability of zilching.) If you play THAT strategy when there is no zilch penalty at all, you will find yourself getting on average 17 points per turn LESS than you would if you play the strategy that simply maximizes expected score.

    I purposefully glossed over some of my claims in the section “Maximizing expected scores across all turns”, because I thought the mathematics behind them too tedious (or perhaps it is my limited mathematical skill that makes them too tedious) for a blog entry. But I’ll say a little more here as it pertains to your comment.

    By setting the zilch penalty to some value y, equation (3) will produce a particular strategy G(y) that produces the highest possible expected score given that the zilch penalty is y. Now here’s the funny part: what happens if you play strategy G(y) when in actuality the zilch penalty is zero? It may not be obvious why you’d ever want to do that, but the interesting thing is that if you use G(y) for a turn where there is no zilch penalty, then you will be playing the strategy that gives the best possible expected score with the constraint that you are not allowed to zilch with higher probability than the probability of zilching with strategy G(y). If this were not the case, then it’s easy to show that G(y) isn’t actually the best strategy for the situation where the zilch penalty is y, but we know that it is the best. So, if you consider all other possible strategies having a zilch probability the same or less than the zilch probability of G(y), none of them will give a better expected score than G(y). That’s very useful because for purposes of finding the strategies that maximize expected scores across all turns, the only thing we care about is their expected score and their zilch probability.

    So in the section “Maximizing expected scores across all turns”, the zilch penalty y is fictitious for turn types T0 and T1. I only introduce it as a means of producing strategies G(y) that maximize expectation for various inferred zilch probabilities. It turns out that from the infinitude of possible strategies, there are only a few hundred strategies G(y) for 0 ≤ y < ∞; and it becomes quite possible then, to find the two particular strategies that are best to use for turn types T0 and T1.

    If you plot the expected scores E(G(y)) vs. the zilch probabilities z(G(y)); you’ll see that E(G(y)) is strictly increasing in z(G(y)). Furthermore, if you connect the data points in this plot with straight line segments; you’ll see the slope of these segments is strictly decreasing. It is perhaps noteworthy that between any two neighboring strategies G(yi) and G(yi+1), there could exist other strategies with intermediate zilch probabilities and intermediate expected scores, but such strategies will always appear below (or conceivably on) the straight line joining G(yi) and G(yi+1) and are never a superior strategy to play for any possible zilch penalty.

    As a notable aside, you can set the minimum bank threshold to, say, 1000 points and again let the zilch penalty go to infinity and produce the strategy that gets you to 1000 points with the minimum probability of zilching.

    I hope that helps.

    Matt

  5. Stef says:

    Lovely article about Zilch, really. I didn’t know it came from Farkle. Thanks!

  6. Tom says:

    This was an excellent article – I very much appreciated all the effort put into this! In particular, I was trying to formulate an optimal Farkle strategy for myself, until I came across your analysis. Having read everything very thoroughly, and played with your equations myself, I do have a query regarding your estimate of E(BIG6) for use in Farkle – not Zilch. I think one of the biggest differences between the two games appears to be the non-zero probability of getting a non-scoring roll with 6 dice. As I understand the two games, this is not possible with Zilch, whereas it is with Farkle. I have spent a lot of time trying to come up with an estimate of E(BIG6) for Farkle, because Equation (7) does not apply. When I changed the settings in your model to Facebook Farkle and generated the corresponding strategy, I noticed that the possibilities ran to scores of over 16,000! Yet, I doubt if any Farkle player would risk a 16,000 point score with a 2.3% chance of losing it all. I believe the “stopping score” would be much lower, but I’m having difficulty formulating the equation for this. I have not looked at your java code (I am not a programmer in java), but I suspect that my issues arise from what you describe as your chicken-and-egg problem for initializing E(BIG6). I would love to get your feedback and to extend discussion on this issue.

  7. matt says:

    Tom,

    Let me first tackle the insanity of rolling when you have 16,000 points. As I stated in Limitations, the strategy that maximizes expected score is NOT always the same strategy that maximizes your chance of winning the game. This is one of those situations. If you’re out to win, then yeah, you’d definitely bank the 16,000 points since that assures the win. But if you’re trying to maximize expected score, then (surprisingly enough) it’s actually better to roll 6 dice into 16,000 points. I’ll calculate that by hand here.

    There are 66 = 46656 different ways to roll six dice. Of these 1080 are farkles. So, as you noted, the chance of farkling = 1080/46656 = 1 / 43.2 = 2.3%. Then the negative expectation component in our sum is just -16,000 / 43.2 = -370.3703. Now the other 45576 rolls are not farkles and yield points. If you add up all the highest scoring combos from each of these rolls you get 17,709,000 points. So the average score (given that you don’t farkle) is just 17,709,000 / 45576 = 388.5598 points. Just as we multiplied the -16,000 by the chance of farkling, we need to multiply this average score by the chance of NOT farkling; so our positive expectation component is 388.5598 * (1 – 1/43.2) = 379.5656. And our net expectation is 379.5656 – 370.3703 = 9.1953. So on average if you roll 6 dice into 16,000 points, you’ll gain 9.1953 points. Now run the Farkle Strategy Generator for Facebook Farkle scoring, flip to the Expected Score table for turn type T0, and examine the table entry corresponding to 16000 turn points with 6 dice to roll. You’ll see the final expected turn score of 16009.195 points. Voila!

    You are right that for Facebook Farkle scoring rules there is always a non-zero probability of farkling, whereas in Zilch a throw of 6 dice always yields positive points. In zilch, you always throw 6 dice when you get the chance, no matter how high your score. This leads to an infinite series of increasingly unlikely game states which must be added to the total expectation of turn score. EBIG6 is introduced to deal specifically with this infinite series. Things are actually simpler in Facebook Farkle since rolling 6 dice into anything more than 16350 points always yields negative expectation to your score. So you must simply bank 16400 or more points. There is no infinite series to sum and accordingly EBIG6 doesn’t enter into the equations for Facebook Farkle at all. You shouldn’t be trying to calculate it. The software just sets EBIG6 to zero for Facebook Farkle scoring.

    For Facebook Farkle, all you need worry about is finding SBIG. To find it, you just make a guess, start running your calculations down from your chosen value of SBIG, and verify that E(SBIG-50, 6) is negative. If it is, then you’ve picked an SBIG that is big enough. If not, increase it. In the software, I use a binary search to zero in on the minimum value for SBIG. (Well, actually it picks a value for SBIG that is 50 points bigger than it needs to be, but that results in the last row of produced strategy tables being all banking states — which I think rather nice anyway.)

    I hope that helps.

    Matt

  8. Kayen Davenport says:

    To what are referring when you say ‘strategy finding software’?

    • matt says:

      Kayen,

      In the Software section of this blog post is a link to my original java software used to find the strategies that maximize expected scores in the game of Zilch. This software is open-source and is protected by GPL 3.

      Subsequently, I rewrote the strategy generation tool in C++. The new version is perhaps 3 orders of magnitude faster, solves for 3 turn strategies, and is in general far more flexible. The C++ version of the strategy finder is not shared, but you can run it through use of the Farkle Strategy Generator.

      Matt

  9. Pingback: Analysis of Farkle | Possibly Wrong

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

 

Your comments will not appear until I've had a chance to screen them. This usually takes a day or less, but could be longer if I'm canoeing or camping or am otherwise beyond the reach of the internet. I respond to all questions.