public class Node { private Puzzle puzzles; private Node puzzle_parent; private Node[] puzzle_children; private int puzzle_numChildren; private int puzzle_number; private int puzzle_pathCost; private int puzzle_nodeCost; public Node(Puzzle p) { puzzles = p; puzzle_number = 0; puzzle_nodeCost = 0; puzzle_numChildren = 0; puzzle_pathCost = 0; puzzle_children = new Node[4];//Max 4 way to move } public void expand() { for (int i = 1; i <= 8; ++i) { if (puzzles.legal(i)) { Puzzle puzzle = new Puzzle(puzzles.number); puzzle.move(i); Node child = new Node(puzzle); child.puzzle_parent = this; child.puzzle_number = i; child.puzzle_pathCost = puzzle_pathCost + 1; // Using A* search,may change to another search child.puzzle_nodeCost = puzzle_pathCost + puzzle.totalCost(); puzzle_children[puzzle_numChildren++] = child; } } } public Puzzle getPuzzle() { return puzzles; } public Node getParent() { return puzzle_parent; } public int getNumChildren() { return puzzle_numChildren; } public Node getChild(int i) { return puzzle_children[i]; } public int getPuzzleNumber() { return puzzle_number; } public int getCost() { return puzzle_nodeCost; } }