mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 08:01:30 -07:00
The game IDs for Net (and Netslide) have always been random seeds
rather than literal grid descriptions, which has always faintly annoyed me because it makes it impossible to type in a grid from another source. However, Gareth pointed out that short random-seed game descriptions are useful, because you can read one out to someone else without having to master the technology of cross- machine cut and paste, or you can have two people enter the same random seed simultaneously in order to race against each other to complete the same puzzle. So both types of game ID seem to have their uses. Therefore, here's a reorganisation of the whole game ID concept. There are now two types of game ID: one has a parameter string then a hash then a piece of arbitrary random seed text, and the other has a parameter string then a colon then a literal game description. For most games, the latter is identical to the game IDs that were previously valid; for Net and Netslide, old game IDs must be translated into new ones by turning the colon into a hash, and there's a new descriptive game ID format. Random seed IDs are not guaranteed to be portable between software versions (this is a major reason why I added version reporting yesterday). Descriptive game IDs have a longer lifespan. As an added bonus, I've removed the sections of documentation dealing with game parameter encodings not shown in the game ID (Rectangles expansion factor, Solo symmetry and difficulty settings etc), because _all_ parameters must be specified in a random seed ID and therefore users can easily find out the appropriate parameter string for any settings they have configured. [originally from svn r5788]
This commit is contained in:
34
twiddle.c
34
twiddle.c
@ -103,10 +103,8 @@ static int game_fetch_preset(int i, char **name, game_params **params)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static game_params *decode_params(char const *string)
|
||||
static void decode_params(game_params *ret, char const *string)
|
||||
{
|
||||
game_params *ret = snew(game_params);
|
||||
|
||||
ret->w = ret->h = atoi(string);
|
||||
ret->n = 2;
|
||||
ret->rowsonly = ret->orientable = FALSE;
|
||||
@ -134,16 +132,18 @@ static game_params *decode_params(char const *string)
|
||||
}
|
||||
string++;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static char *encode_params(game_params *params)
|
||||
static char *encode_params(game_params *params, int full)
|
||||
{
|
||||
char buf[256];
|
||||
sprintf(buf, "%dx%dn%d%s%s", params->w, params->h, params->n,
|
||||
params->rowsonly ? "r" : "",
|
||||
params->orientable ? "o" : "");
|
||||
/* Shuffle limit is part of the limited parameters, because we have to
|
||||
* supply the target move count. */
|
||||
if (params->movetarget)
|
||||
sprintf(buf + strlen(buf), "m%d", params->movetarget);
|
||||
return dupstr(buf);
|
||||
}
|
||||
|
||||
@ -307,7 +307,7 @@ static int grid_complete(int *grid, int wh, int orientable)
|
||||
return ok;
|
||||
}
|
||||
|
||||
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 *grid;
|
||||
@ -368,10 +368,10 @@ static char *new_game_seed(game_params *params, random_state *rs,
|
||||
} while (grid_complete(grid, wh, params->orientable));
|
||||
|
||||
/*
|
||||
* Now construct the game seed, by describing the grid as a
|
||||
* simple sequence of integers. They're comma-separated, unless
|
||||
* the puzzle is orientable in which case they're separated by
|
||||
* orientation letters `u', `d', `l' and `r'.
|
||||
* Now construct the game description, by describing the grid
|
||||
* as a simple sequence of integers. They're comma-separated,
|
||||
* unless the puzzle is orientable in which case they're
|
||||
* separated by orientation letters `u', `d', `l' and `r'.
|
||||
*/
|
||||
ret = NULL;
|
||||
retlen = 0;
|
||||
@ -398,13 +398,13 @@ static void game_free_aux_info(game_aux_info *aux)
|
||||
assert(!"Shouldn't happen");
|
||||
}
|
||||
|
||||
static char *validate_seed(game_params *params, char *seed)
|
||||
static char *validate_desc(game_params *params, char *desc)
|
||||
{
|
||||
char *p, *err;
|
||||
int w = params->w, h = params->h, wh = w*h;
|
||||
int i;
|
||||
|
||||
p = seed;
|
||||
p = desc;
|
||||
err = NULL;
|
||||
|
||||
for (i = 0; i < wh; i++) {
|
||||
@ -428,7 +428,7 @@ static char *validate_seed(game_params *params, char *seed)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
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 w = params->w, h = params->h, n = params->n, wh = w*h;
|
||||
@ -447,7 +447,7 @@ static game_state *new_game(game_params *params, char *seed)
|
||||
|
||||
state->grid = snewn(wh, int);
|
||||
|
||||
p = seed;
|
||||
p = desc;
|
||||
|
||||
for (i = 0; i < wh; i++) {
|
||||
state->grid[i] = 4 * atoi(p);
|
||||
@ -1087,9 +1087,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,
|
||||
|
Reference in New Issue
Block a user