X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/puzzles/blobdiff_plain/ae8290c655dec864db8ef0dc6b59891d6434c71f..5c9f61fd500f6fd53a9f33721a1e66b9d5e1d9cc:/netslide.c diff --git a/netslide.c b/netslide.c index b2b50e8..236491a 100644 --- a/netslide.c +++ b/netslide.c @@ -82,11 +82,6 @@ struct game_params { int movetarget; }; -struct game_aux_info { - int width, height; - unsigned char *tiles; -}; - struct game_state { int width, height, cx, cy, wrapping, completed; int used_solve, just_used_solve; @@ -330,7 +325,7 @@ static char *validate_params(game_params *params) */ static char *new_game_desc(game_params *params, random_state *rs, - game_aux_info **aux, int interactive) + char **aux, int interactive) { tree234 *possibilities, *barriertree; int w, h, x, y, cx, cy, nbarriers; @@ -535,19 +530,22 @@ static char *new_game_desc(game_params *params, random_state *rs, } /* - * Save the unshuffled grid. We do this using a separate - * reference-counted structure since it's a large chunk of - * memory which we don't want to have to replicate in every - * game state while playing. + * Save the unshuffled grid in aux. */ { - game_aux_info *solution; + char *solution; + int i; + + /* + * String format is exactly the same as a solve move, so we + * can just dupstr this in solve_game(). + */ - solution = snew(game_aux_info); - solution->width = w; - solution->height = h; - solution->tiles = snewn(w * h, unsigned char); - memcpy(solution->tiles, tiles, w * h); + solution = snewn(w * h + 2, char); + solution[0] = 'S'; + for (i = 0; i < w * h; i++) + solution[i+1] = "0123456789abcdef"[tiles[i] & 0xF]; + solution[w*h+1] = '\0'; *aux = solution; } @@ -698,12 +696,6 @@ static char *new_game_desc(game_params *params, random_state *rs, return desc; } -static void game_free_aux_info(game_aux_info *aux) -{ - sfree(aux->tiles); - sfree(aux); -} - static char *validate_desc(game_params *params, char *desc) { int w = params->width, h = params->height; @@ -894,24 +886,14 @@ static void free_game(game_state *state) } static char *solve_game(game_state *state, game_state *currstate, - game_aux_info *aux, char **error) + char *aux, char **error) { - char *ret; - int i; - if (!aux) { *error = "Solution not known for this puzzle"; return NULL; } - assert(aux->width == state->width); - assert(aux->height == state->height); - ret = snewn(aux->width * aux->height + 2, char); - ret[0] = 'S'; - for (i = 0; i < aux->width * aux->height; i++) - ret[i+1] = "0123456789abcdef"[aux->tiles[i] & 0xF]; - ret[i+1] = '\0'; - return ret; + return dupstr(aux); } static char *game_text_format(game_state *state) @@ -1005,12 +987,12 @@ static void free_ui(game_ui *ui) sfree(ui); } -char *encode_ui(game_ui *ui) +static char *encode_ui(game_ui *ui) { return NULL; } -void decode_ui(game_ui *ui, char *encoding) +static void decode_ui(game_ui *ui, char *encoding) { } @@ -1822,7 +1804,6 @@ const struct game thegame = { TRUE, game_configure, custom_params, validate_params, new_game_desc, - game_free_aux_info, validate_desc, new_game, dup_game,