 # Hold-at-20 Outcomes (Computation)

Pig is a folk jeopardy dice game with simple rules: Two players race to reach 100 points. Each turn, a player repeatedly rolls a die until either a 1 ("pig") is rolled or the player holds and scores the sum of the rolls (i.e. the turn total). At any time during a player's turn, the player is faced with two decisions:

• roll - If the player rolls a
• 1: the player scores nothing and it becomes the opponent's turn.
• 2 - 6: the number is added to the player's turn total and the player's turn continues.
• hold - The turn total is added to the player's score and it becomes the opponent's turn.

Problem:  Compute and report the probabilities of the possible scoring outcomes from a hold-at-20 Pig turn.

The following is a dynamic programming algorithm that approaches the problem by computing the probability of passing through each score on the way to the final outcome:

• Create a floating-point array score with indices from 0 through 25 (hold value + 5).  Initialize all entries to 0.0, except initialize index 0 to 1.0.
• For each increasing index i from 0 through 19 (hold value - 1):
• Let p be score[i] / 6.
• Set score[i] to 0.0.
• Add p to score, score[i + 2], score[i + 3],  score[i + 4],  score[i + 5],  score[i + 6]

At the beginning of each iteration i,  score[i] is the probability of passing through score i.  After all iterations, the remaining positive values are the probabilities of their respective score outcome probabilities.

Input Format:  (no input)

Output Format:

• On the first line, print "Score" and "Probability" separated by a tab.
• After computing the probabilities of outcomes, print a table line for each possible score outcome in increasing order of score.  For each score outcome, print the score, a tab, and the probability of that score outcome.

Sample Transcript:

```Score   Probability
0       0.624541
20      0.099713
21      0.094991
22      0.074189
23      0.054196
24      0.035198
25      0.017173```

Extra Exercises:

1. What is the expected average score outcome for hold-at-20?
2. Additionally allow the user to specify the hold value.  What is the probability of reaching 100 in a single turn?

Todd Neller