10 for (
unsigned i = s; i >= 2; i--)
74 std::vector<BurnedPancakePuzzleState> &children)
const
79 for (
unsigned i = 0; i <
operators.size(); i++)
81 children.push_back(parent);
91 for (
unsigned i = 0; i <
operators.size(); i++)
99 unsigned current_action;
100 bool are_equal =
false;
105 for (
unsigned i = 0; i <
operators.size(); i++)
109 if (parentCopy == child)
117 fprintf(stderr,
"ERROR: GetAction called with non-adjacent states\n");
125 assert(action > 1 && action <=
size);
128 int lower = action - 1;
146 assert(a > 1 && a <=
size);
154 fprintf(stderr,
"ERROR: HCost called with a single state and goal is not stored.\n");
159 fprintf(stderr,
"ERROR: HCost called with a single state with wrong size.\n");
196 fprintf(stderr,
"ERROR: HCost called with state with wrong size.\n");
201 fprintf(stderr,
"ERROR: HCost called with goal with wrong size.\n");
207 std::vector<int> goal_locs(
size);
208 for (
unsigned i = 0; i <
size; i++)
210 int theSign = abs(goal_state.
puzzle[i])/goal_state.
puzzle[i];
211 goal_locs[abs(goal_state.
puzzle[i])-1] = (i+1)*theSign;
220 if (state == goal_state)
228 int theSign = abs(state.
puzzle[index])/state.
puzzle[index];
229 int loc = goal_locs[abs(state.
puzzle[index])-1];
237 fprintf(stderr,
"ERROR: HCost called with state with wrong size.\n");
241 double h_count = 0.0;
243 for (; i <
size - 1; i++)
248 int diff = (abs(abs(curr)-abs(next)));
249 if (diff > 1 || diff < - 1)
253 else if ((curr < 0 && next > 0) ||
254 (curr > 0 && next < 0))
261 if (last != (
int)
size)
263 else if (-last == (
int)
size)
277 return (state == theGoal);
284 fprintf(stderr,
"ERROR: GoalTest called with a single state and goal is not stored.\n");
289 fprintf(stderr,
"ERROR: GoalTest called with a single state with wrong size.\n");
297 return (uint64_t) act;
308 for (
unsigned i = 0; i <
size; i++)
318 if (op_order.size() !=
size - 1)
320 fprintf(stderr,
"ERROR: Not enough operators in operator sequence for construction of BurnedPancakePuzzle\n");
324 bool all_ops[op_order.size()];
326 for (
unsigned i = 0; i <
size; i++)
331 for (
unsigned i = 0; i < op_order.size(); i++)
333 if (op_order[i] < 2 || op_order[i] >
size)
335 fprintf(stderr,
"ERROR: Invalid operator included in construction of BurnedPancakePuzzle\n");
338 all_ops[op_order[i] - 2] =
true;
341 for (
unsigned i = 0; i < op_order.size(); i++)
346 if (all_ops[i] ==
false)
348 fprintf(stderr,
"ERROR: Missing operator %u in construction of BurnedPancakePuzzle\n", i+2);
353 for (
unsigned i = 0; i < op_order.size(); i++)
475 std::vector<int> puzzle = s.
puzzle;
476 uint64_t hashVal = 0;
477 int numEntriesLeft = (int)s.
puzzle.size();
478 for (
unsigned int x = 0; x < s.
puzzle.size(); x++)
480 hashVal += puzzle[x]*
Factorial(numEntriesLeft-1);
482 for (
unsigned y = x; y < puzzle.size(); y++)
484 if (puzzle[y] > puzzle[x])