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:
Simon Tatham
2005-05-16 18:57:09 +00:00
parent aa1185f3f5
commit 2534ec5d69
16 changed files with 976 additions and 800 deletions

50
gtk.c
View File

@ -1000,7 +1000,7 @@ static frontend *new_window(char *game_id, char **error)
fe->me = midend_new(fe, &thegame);
if (game_id) {
*error = midend_game_id(fe->me, game_id, FALSE);
*error = midend_game_id(fe->me, game_id);
if (*error) {
midend_free(fe->me);
sfree(fe);
@ -1035,6 +1035,14 @@ static frontend *new_window(char *game_id, char **error)
add_menu_item_with_key(fe, GTK_CONTAINER(menu), "Restart", 'r');
menuitem = gtk_menu_item_new_with_label("Specific...");
gtk_object_set_data(GTK_OBJECT(menuitem), "user-data",
GINT_TO_POINTER(CFG_DESC));
gtk_container_add(GTK_CONTAINER(menu), menuitem);
gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
GTK_SIGNAL_FUNC(menu_config_event), fe);
gtk_widget_show(menuitem);
menuitem = gtk_menu_item_new_with_label("Random Seed...");
gtk_object_set_data(GTK_OBJECT(menuitem), "user-data",
GINT_TO_POINTER(CFG_SEED));
gtk_container_add(GTK_CONTAINER(menu), menuitem);
@ -1239,34 +1247,42 @@ int main(int argc, char **argv)
*/
if (argc > 1 && !strcmp(argv[1], "--generate")) {
int n = 1;
char *params = NULL;
char *params = NULL, *seed = NULL;
game_params *par;
random_state *rs;
char *parstr;
{
void *seed;
int seedlen;
get_random_seed(&seed, &seedlen);
rs = random_init(seed, seedlen);
}
if (argc > 2)
n = atoi(argv[2]);
if (argc > 3)
params = argv[3];
if (params)
par = thegame.decode_params(params);
else
par = thegame.default_params();
parstr = thegame.encode_params(par);
par = thegame.default_params();
if (params) {
if ( (seed = strchr(params, '#')) != NULL )
*seed++ = '\0';
thegame.decode_params(par, params);
} else {
}
parstr = thegame.encode_params(par, FALSE);
{
void *seeddata;
int seedlen;
if (seed) {
seeddata = seed;
seedlen = strlen(seed);
} else {
get_random_seed(&seeddata, &seedlen);
}
rs = random_init(seeddata, seedlen);
}
while (n-- > 0) {
game_aux_info *aux = NULL;
char *seed = thegame.new_seed(par, rs, &aux);
printf("%s:%s\n", parstr, seed);
sfree(seed);
char *desc = thegame.new_desc(par, rs, &aux);
printf("%s:%s\n", parstr, desc);
sfree(desc);
if (aux)
thegame.free_aux_info(aux);
}