X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/puzzles/blobdiff_plain/818752113d2ba0ab8661365c5e81665e8fc6d15f..b498c53924c571d997f97c7ff3dd81c3e66894a1:/sixteen.c diff --git a/sixteen.c b/sixteen.c index 2751be4..e7eb7bd 100644 --- a/sixteen.c +++ b/sixteen.c @@ -95,11 +95,10 @@ static game_params *dup_params(game_params *params) return ret; } -static game_params *decode_params(char const *string) +static void decode_params(game_params *ret, char const *string) { - game_params *ret = default_params(); - ret->w = ret->h = atoi(string); + ret->movetarget = 0; while (*string && isdigit(*string)) string++; if (*string == 'x') { string++; @@ -113,15 +112,17 @@ static game_params *decode_params(char const *string) while (*string && isdigit((unsigned char)*string)) string++; } - - return ret; } -static char *encode_params(game_params *params) +static char *encode_params(game_params *params, int full) { char data[256]; sprintf(data, "%dx%d", params->w, params->h); + /* Shuffle limit is part of the limited parameters, because we have to + * supply the target move count. */ + if (params->movetarget) + sprintf(data + strlen(data), "m%d", params->movetarget); return dupstr(data); } @@ -192,7 +193,7 @@ static int perm_parity(int *perm, int n) return ret; } -static char *new_game_seed(game_params *params, random_state *rs, +static char *new_game_desc(game_params *params, random_state *rs, game_aux_info **aux) { int stop, n, i, x; @@ -362,8 +363,8 @@ static char *new_game_seed(game_params *params, random_state *rs, } /* - * Now construct the game seed, by describing the tile array as - * a simple sequence of comma-separated integers. + * Now construct the game description, by describing the tile + * array as a simple sequence of comma-separated integers. */ ret = NULL; retlen = 0; @@ -390,14 +391,14 @@ static void game_free_aux_info(game_aux_info *aux) } -static char *validate_seed(game_params *params, char *seed) +static char *validate_desc(game_params *params, char *desc) { char *p, *err; int i, area; int *used; area = params->w * params->h; - p = seed; + p = desc; err = NULL; used = snewn(area, int); @@ -441,7 +442,7 @@ static char *validate_seed(game_params *params, char *seed) return err; } -static game_state *new_game(game_params *params, char *seed) +static game_state *new_game(game_params *params, char *desc) { game_state *state = snew(game_state); int i; @@ -452,7 +453,7 @@ static game_state *new_game(game_params *params, char *seed) state->n = params->w * params->h; state->tiles = snewn(state->n, int); - p = seed; + p = desc; i = 0; for (i = 0; i < state->n; i++) { assert(*p); @@ -571,6 +572,7 @@ static game_state *make_move(game_state *from, game_ui *ui, int dx, dy, tx, ty, n; game_state *ret; + button &= ~MOD_MASK; if (button != LEFT_BUTTON && button != RIGHT_BUTTON) return NULL; @@ -935,7 +937,7 @@ static void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate, } static float game_anim_length(game_state *oldstate, - game_state *newstate, int dir) + game_state *newstate, int dir, game_ui *ui) { if ((dir > 0 && newstate->just_used_solve) || (dir < 0 && oldstate->just_used_solve)) @@ -945,7 +947,7 @@ static float game_anim_length(game_state *oldstate, } static float game_flash_length(game_state *oldstate, - game_state *newstate, int dir) + game_state *newstate, int dir, game_ui *ui) { if (!oldstate->completed && newstate->completed && !oldstate->used_solve && !newstate->used_solve) @@ -973,9 +975,9 @@ const struct game thegame = { dup_params, TRUE, game_configure, custom_params, validate_params, - new_game_seed, + new_game_desc, game_free_aux_info, - validate_seed, + validate_desc, new_game, dup_game, free_game,