# Farkle

### How To Play (The Rules)

Farkle is a simple dice game that is fairly similar to "Deal Or No Deal" or "Press Your Luck" in concept. Players take turns rolling dice for points. After every roll, you can either take the points you've earned so far on your turn, or you can re-roll to try to get more points. If you ever fail to score points on a roll, it's called a "farkle" and you lose all your points from that turn. The goal is to try to score 10,000 points total.

Dice are scored as follows:

Dice | Points |
---|---|

6 of a kind | Instant Win! |

1-2-3-4-5-6 | 1000 secure |

3 pairs | 750 |

3 ones | 1000 |

3 of a kind | 100 x face value |

ones | 100 each |

fives | 50 each |

After you score points on a roll, those dice are set aside if you decide to roll again. Dice you've rolled previously do not count on subsequent rolls, so if you roll 1-4-2-2-6-3, keep the 1, and then roll two more 1s, it does not count as three of a kind. If you end up scoring with all dice you've rolled, you can roll all six dice again. Note that the top three scoring combinations require six dice, so these combinations are rarely used.

When you score dice, you must score *something*, but you don't have to score all the dice that are possible to score (in case you want to roll more dice later). So, for example, if you roll 3-4-3-1-5-3, you can keep the 3 threes (for 300 points), the one (for 100 points), the five (for 50 points), or any combination of the three.

This covers the vast majority of the game. There are still a few quirks, though:

- The combination 1-2-3-4-5-6 is unusual in that it scores 1000 "secure" points. These points are yours to keep, even if you farkle. The game enforces this by immediately adding it to your total score instead of the total so far for this roll. Needless to say, it's a very good roll to get.
- You can't begin play (adding to your point total) until you've rolled 1000 points on a turn. After you've crossed the 1000 point threshold, you can stop rolling whenever you want, even if your score so far on that turn is less than 1000 points.
- Once a player has crossed the 10,000 point mark, the other player gets one more turn to try to get a higher score. The game forces you to keep rolling until you either get a farkle or you've scored enough points to at least tie the other player.

If you've played this game before, you probably played by different rules. There's a lot of variations on how to score dice, what the winning point total is, and whether to require an initial scoring threshold. These are just the rules that I've always played by.

### How To Play (Mechanics of the Game)

There are really only three things you can do on your turn:

- Click on rolled (white) dice to select or deselect them for scoring. When dice are selected, they are highlighted in blue.
- Click "Roll Dice" to re-roll any normal, non-selected dice. This adds the point total for the selected dice to your total for this turn and then sets those dice aside by disabling them.
- Click "Done" to end your turn without rolling again. This adds the point total for the selected dice to your total for this turn, and then adds your points on this turn to your point total for the game. Play then proceeds to the other player.

The interaction on the computer's turn is similar, but you are unable to change which dice are selected, and only one of the buttons will be enabled (based on whether the computer wants to re-roll or take the points).

### About the Computer Player

If you're wondering how the computer player makes its decisions, here's a really rough outline of it. Sometimes its decisions seem a little odd, but it's based on cold, hard statistics. WARNING: Boring math stuff ahead.

The decision of which dice to keep is determined as follows:

- It calculates every possible scoring combination of the dice. (Actually, that's not technically true since some combinations it knows to be ideal, such as taking 1-2-3-4-5-6 instead of keeping just the 1 and the 5. But for our purposes, assume it checks them
*all*.) - For each combination, it calculates the score and then adds that to the expected value of rolling the number of dice that would be left. (The expected values are precomputed and stored in tables, but they were done by simple exhaustive enumeration.)
- Whichever has the highest total of [score + E(dice left)] is the combination the computer will count, in most cases.

Next, the computer will decide whether to keep rolling based on how many dice were left. This is done by taking the score so far on this turn and calculating the expected value of the score if it rolls again. It simplifies this calculation by computing (1 - *p*) * [score this turn + E(dice left)], where *p* is the probability of a farkle. (This can be done since the expected value of a farkle is zero points, so it adds nothing to the sum.) If the expected value is lower than the current score from this turn, it's not worth it to roll again, so it stops.

In the not-so-unusual case that originally it didn't select all the dice that can score and still wants to stop, it goes back and selects them all. Hey, why give up free points?

You'll find that the computer plays well. Really well. If it wasn't for the initial 1000 point threshold, it would win just about every time.

### See Any Bugs?

If you see the game doing something really odd, please send me an email about it. However, the following behaviors are NOT bugs:

- Doesn't auto-select six dice combinations, such as 1-2-3-4-5-6 or three pairs. This isn't a bug because it
*never*auto-selects any dice on your turn. Ever. Yes, it gets annoying with the 1-2-3-4-5-6 combination because it tells you that it detected it, but think of it this way: the computer doesn't have to say anything at all - it's doing you a favor since it's such a special combination. - Sometimes you reroll and the dice don't change. It's called probability. It will happen sooner or later. That having been said, I know the random number generator ain't the best in the world, so sometimes you might see this not-changing behavior several times in a short time span, but believe me: it's really rolling the dice randomly.
- Yes, you are forced to select dice to score at every turn (except when you farkle) before you can click "Done". This was by choice.