expectedTurnScore
public static BigFraction expectedTurnScore(int holdAt)
expectedTurnScore - Returns the expected score gain in the game of Pig assuming that a player holds at a turn total of holdAt or more.
The algorithm can be described as follows: Create an array e indexed by turn total t for computing e[t], the expected turn score given that one has reached a turn total of t. Initially, e[t] = t, for holdAt ≤ t ≤ holdAt + 5. Then, working from t=holdAt-1 down to t=0, you can compute each e[t] = e[t+2]/6 + e[t+3]/6 + e[t+4]/6 + e[t+5]/6 + e[t+6]/6. (In other words, a non-1 roll with probability 1/6 will contribute to the current expected score by 1/6 times the expected score at the next turn total reached by the roll.) This calculation working backwards is called retrograde analysis, and you'll be working with BigFraction objects for exact computation.
Example: To compute the probability of reaching a target of 3, array e contains BigFraction values for {0, 0, 0, 3, 4, 5, 6, 7, 8}.
Working backwards from t = 2 down to 0:
e[2] = e[2+2]/6 + e[2+3]/6 + e[2+4]/6 + e[2+5]/6 + e[2+6]/6 = 4/6 + 5/6 + 6/6 + 7/6 + 8/6 = 30/6 = 5/1.
e[1] = e[1+2]/6 + e[1+3]/6 + e[1+4]/6 + e[1+5]/6 + e[1+6]/6 = 3/6 + 4/6 + 5/6 + 6/6 + 7/6 = 25/6.
e[0] = e[0+2]/6 + e[0+3]/6 + e[0+4]/6 + e[0+5]/6 + e[0+6]/6 = (5/1)/6 + 3/6 + 4/6 + 5/6 + 6/6 = 23/6.
- Parameters:
holdAt
- the turn total to hold at or above
- Returns:
- the expected score gain in the game of Pig assuming that a player holds at a turn total of holdAt or more