diff --git a/galaxies.c b/galaxies.c index fbcaff2..9a7b363 100644 --- a/galaxies.c +++ b/galaxies.c @@ -155,6 +155,7 @@ static int solver_obvious_dot(game_state *state, space *dot); static space *space_opposite_dot(const game_state *state, const space *sp, const space *dot); static space *tile_opposite(const game_state *state, const space *sp); +static game_state *execute_move(const game_state *state, const char *move); /* ---------------------------------------------------------- * Game parameters and presets @@ -1568,6 +1569,10 @@ generate: dbg_state(state); #endif + game_state *blank = blank_game(params->w, params->h); + *aux = diff_game(blank, state, true, -1); + free_game(blank); + free_game(state); sfree(scratch); @@ -2325,21 +2330,26 @@ static char *solve_game(const game_state *state, const game_state *currstate, int i; int diff; - tosolve = dup_game(currstate); - diff = solver_state(tosolve, DIFF_UNREASONABLE); - if (diff != DIFF_UNFINISHED && diff != DIFF_IMPOSSIBLE) { - debug(("solve_game solved with current state.\n")); + if (aux) { + tosolve = execute_move(state, aux); goto solved; - } - free_game(tosolve); + } else { + tosolve = dup_game(currstate); + diff = solver_state(tosolve, DIFF_UNREASONABLE); + if (diff != DIFF_UNFINISHED && diff != DIFF_IMPOSSIBLE) { + debug(("solve_game solved with current state.\n")); + goto solved; + } + free_game(tosolve); - tosolve = dup_game(state); - diff = solver_state(tosolve, DIFF_UNREASONABLE); - if (diff != DIFF_UNFINISHED && diff != DIFF_IMPOSSIBLE) { - debug(("solve_game solved with original state.\n")); - goto solved; + tosolve = dup_game(state); + diff = solver_state(tosolve, DIFF_UNREASONABLE); + if (diff != DIFF_UNFINISHED && diff != DIFF_IMPOSSIBLE) { + debug(("solve_game solved with original state.\n")); + goto solved; + } + free_game(tosolve); } - free_game(tosolve); return NULL;