Skip to content

Commit

Permalink
goal.c now find all solutions at optimum depth
Browse files Browse the repository at this point in the history
  • Loading branch information
brownan committed Dec 22, 2008
1 parent 7a7c132 commit 3000789
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions goal.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ int goal_solve(const char *scrambled, const char *solved,

int numtables = 0;

int solution_found = 0;

/*
* primitive stack to hold the solution
*/
Expand Down Expand Up @@ -94,6 +96,8 @@ int goal_solve(const char *scrambled, const char *solved,
{
if (stack->length == 0)
{
if (solution_found)
goto solve_cleanup;
stack_push(stack, scrambled, -1, 0);
depth++;
fprintf(stderr, "Searching depth %d, Nodes expanded: %ld,"
Expand Down Expand Up @@ -122,11 +126,14 @@ int goal_solve(const char *scrambled, const char *solved,
/*
* DINGDINGDINGDING We've found a solution
*/
printf("Solution found!\n");
if (!solution_found) {
printf("Solution found!\n");
printf("Continuing to look for more solutions at this depth\n");
solution_found = 1;
}
cube_print_solution(path);

printf("\n");
goto solve_cleanup;

}
} else {
/*
Expand Down

0 comments on commit 3000789

Please sign in to comment.