mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 08:01:30 -07:00
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.)
This commit is contained in:
10
galaxies.c
10
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,6 +2330,10 @@ static char *solve_game(const game_state *state, const game_state *currstate,
|
||||
int i;
|
||||
int diff;
|
||||
|
||||
if (aux) {
|
||||
tosolve = execute_move(state, aux);
|
||||
goto solved;
|
||||
} else {
|
||||
tosolve = dup_game(currstate);
|
||||
diff = solver_state(tosolve, DIFF_UNREASONABLE);
|
||||
if (diff != DIFF_UNFINISHED && diff != DIFF_IMPOSSIBLE) {
|
||||
@ -2340,6 +2349,7 @@ static char *solve_game(const game_state *state, const game_state *currstate,
|
||||
goto solved;
|
||||
}
|
||||
free_game(tosolve);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
||||
|
Reference in New Issue
Block a user