#define S 3 // Length of a side #define STACKSIZE 32 // Big enough int nsquared[STACKSIZE][S*S]; // A stack of states int goal_node[S*S]; // The goal state init_first_node() { nsquared[0] = { 1, 2, 3, 6, 4, 5, 7, 8, 0 } ; } initialize_goal() { goal_node = { 1,2,3,4,5,6,7,8,0 } ; } try_moves(int lte) { // lte is the level to examine in the search // First free position on the state stack is lte + 1 int emp_pos; // Find empty position; emp_pos is a storeback parameter find_empty_pos(emp_pos,nsquared[lte]); either {// The empty square can be moved to the right // if its current position is not divisible by S. (emp_pos+1)%S != 0; add_new_state(lte,lte+1,emp_pos,1); } or {// The empty square can be moved to the left // if its current position does not have // remainder 1 when divided by S. (emp_pos + 1)%S != 1; add_new_state(lte,lte+1,emp_pos,-1); } or {// The empty square can be moved down if its // current position is less than or equal to S*S-S emp_pos + 1 <= S*S - S; add_new_state(lte,lte+1,emp_pos,S); } or {// The empty square can be moved up if its // current position is greater than S emp_pos + 1 > S; add_new_state(lte,lte+1,emp_pos,-S); } } find_empty_pos(int & emp_pos, int vector[S*S]) { and(int i=0;i