## Class PigSolitaireSolver

• java.lang.Object
• PigSolitaireSolver

• ```public class PigSolitaireSolver
extends java.lang.Object```
PigSolitaireSolver.java - Solver for Pig Solitaire with JUnit testing interface. See http://cs.gettysburg.edu/~tneller/nsf/pig/ for details.
• ### Constructor Summary

Constructors
Constructor and Description
```PigSolitaireSolver(int goal, int turns)```
Solve Pig Solitaire for a given goal score and maximum number of turns using dynamic programming.
• ### 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, number of turns completed, and current turn total.
`boolean` ```shouldRoll(int i, int j, int k)```
Return whether or not an optimal player should roll given the current score, number of turns completed, and current turn total.
• ### Methods inherited from class java.lang.Object

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

• #### PigSolitaireSolver

```public PigSolitaireSolver(int goal,
int turns)```
Solve Pig Solitaire for a given goal score and maximum number of turns using dynamic programming. A solution maximizes the probability of reaching the goal score within the given number of turns.
Parameters:
`goal` - goal score to reach within the given number of turns
`turns` - maximum number of turns to reach the goal score
• ### Method Detail

• #### pWin

```public double pWin(int i,
int j,
int k)```
Return the probability of winning with optimal play given the current score, number of turns completed, and current turn total. If j ≥ turns, the player has lost. If i + k ≥ goal, the player has won. Otherwise, return the non-terminal state's probability for winning with optimal play.
Parameters:
`i` - player score
`j` - number of completed turns
`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 score, number of turns completed, and current turn total. Assume j < turns and i + k < goal.
Parameters:
`i` - player score
`j` - number of completed turns
`k` - current turn total
Returns:
whether or not an optimal player should roll in the current state