## Class PigSolver

• java.lang.Object
• PigSolver
• ### Constructor Summary

Constructors
Constructor and Description
```PigSolver(int goal, double epsilon)```
Solve Pig for a given goal score using value iteration with a given convergence parameter epsilon.
• ### Method Summary

All Methods
Modifier and Type Method and Description
`double` ```pWin(int i, int j, int k)```
Return the probability of winning with optimal play given the current score, opponent score, and current turn total.
`boolean` ```shouldRoll(int i, int j, int k)```
Return whether or not an optimal player should roll given the current player score, opponent score, and current turn total.
• ### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
• ### Constructor Detail

• #### PigSolver

```public PigSolver(int goal,
double epsilon)```
Solve Pig for a given goal score using value iteration with a given convergence parameter epsilon. A solution maximizes the probability of winning.
Parameters:
`goal` - player goal score to win
`epsilon` - minimum magnitude of pWin change in one value iteration for continuation
• ### Method Detail

• #### pWin

```public double pWin(int i,
int j,
int k)```
Return the probability of winning with optimal play given the current score, opponent score, and current turn total. If i + k ≥ goal, the player has won. If j ≥ goal, the player has lost. Otherwise, return the non-terminal state's probability for winning with optimal play.
Parameters:
`i` - current player score
`j` - opponent score
`k` - current turn total
Returns:
probability of winning in the current state with optimal play
• #### shouldRoll

```public boolean shouldRoll(int i,
int j,
int k)```
Return whether or not an optimal player should roll given the current player score, opponent score, and current turn total. Assume j < goal and i + k < goal.
Parameters:
`i` - current player score
`j` - opponent score
`k` - current turn total
Returns:
whether or not an optimal player should roll in the current state