public class HPancakeSortNode
extends HSearchNode
Modifier and Type  Field and Description 

int 
cost
The cumulative cost of reaching this node given the sequence of previous flips, i.e.

int 
lastFlip
Last number of flipped pancakes (2 through length), or 0 for the root search node.

int[] 
pancake
Current pancake sequence consisting of a permutation of integers from 0 through length  1.

Constructor and Description 

HPancakeSortNode(int[] pancake)
Create an HPancakeSortNode that is constructed with the given pancake permutation of pancake sizes numbered {0(length1)}, setting
the initial cost to 0.

HPancakeSortNode(int size,
int numShuffleFlips)
Create an HPancakeSortNode that is constructed by creating a sorted sequence of pancake sizes numbered 0 through (length1) and then
performing random reversals of pancakes ranging from 2 to length and initializing this generated root by setting lastFlipped and cost to 0.

Modifier and Type  Method and Description 

HPancakeSortNode 
clone()
Return the result of a deep clone of HPancakeSortNode that has a unique pancake array copy for each cloned node.

java.util.ArrayList<SearchNode> 
expand()
Return a list of HPancakeSortNode children that result from a flip of 2 through (length) flips.

void 
flip(int n)
Flip (that is, reverse the order of) the first n pancakes, increase the node cost by n, and set lastFlip to n.

double 
getG()
Return the total number of pancakes flipped to reach this node from the root node.

static HPancakeSortNode 
getGoalNode(int[] pancake)
Given a pancake index permutation of values from 0 through the array length  1, return an optimal goal node resulting from A* search with an admissible heuristic that is not h(n) = 0.

double 
getH()
Return an admissible heuristic estimate of the cost to a goal node that does not overestimate, nor is the trivial h(n) = 0 heuristic.

int 
getLastFlip()
Return the size of the most recently flipped stack of pancakes, or 0 in the case of the root node.

boolean 
isGoal()
Return whether or not the pancake values are sorted in ascending order.

static void 
main(java.lang.String[] args)
This method will be ignored in JUnit testing, but can serve as a place for your test code.

java.lang.String 
toString()
Return a single line String representation of the current node including node cost (g(n)), the last flip made, and the current pancake sequence.

public int[] pancake
public int lastFlip
public int cost
public HPancakeSortNode(int size, int numShuffleFlips)
size
 number of pancakesnumShuffleFlips
 number of random flips used to shufflepublic HPancakeSortNode(int[] pancake)
pancake
 given permutation of pancake sizes numbered 0 through (length1)public void flip(int n)
n
 number of leading pancakes to be reversed in orderpublic boolean isGoal()
isGoal
in class SearchNode
public java.util.ArrayList<SearchNode> expand()
expand
in class SearchNode
public java.lang.String toString()
toString
in class java.lang.Object
public HPancakeSortNode clone()
clone
in class SearchNode
public int getLastFlip()
public double getG()
getG
in class HSearchNode
public double getH()
getH
in class HSearchNode
public static HPancakeSortNode getGoalNode(int[] pancake)
pancake
 a pancake index permutation of values from 0 through the array length  1public static void main(java.lang.String[] args)
args
 (unused parameter)