diff options
| author | Simon Tatham <anakin@pobox.com> | 2021-10-21 20:40:36 +0100 |
|---|---|---|
| committer | Simon Tatham <anakin@pobox.com> | 2021-10-21 20:40:36 +0100 |
| commit | ad1c6ade2af0e681fb964a17cc3a031951047068 (patch) | |
| tree | 20954223466efd77a601e4c96b079c2b9591034b | |
| parent | 49d28f2204dfbb21156d98b0313399c8126b59e0 (diff) | |
| download | puzzles-ad1c6ade2af0e681fb964a17cc3a031951047068.zip puzzles-ad1c6ade2af0e681fb964a17cc3a031951047068.tar.gz puzzles-ad1c6ade2af0e681fb964a17cc3a031951047068.tar.bz2 puzzles-ad1c6ade2af0e681fb964a17cc3a031951047068.tar.xz | |
Galaxies: store game solution in the aux string.
Most games store a string in 'aux' during new_game_desc() that saves
solve_game() during gameplay from having to reconstruct the solution
from scratch. Galaxies had all the facilities available to do that,
but apparently just forgot to use them.
(Reindents existing code: diff best viewed with whitespace ignored.)
| -rw-r--r-- | galaxies.c | 34 |
1 files changed, 22 insertions, 12 deletions
@@ -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; |