mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 16:05:44 -07:00
Introduce the concept of a `game_aux_info' structure. This is
constructed at the same time as an internally generated game seed, so that it can preserve any interesting information known by the program at generation time but not physically contained within the text of the game seed itself. (Such as, for example, the solution.) Currently not used for anything yet, but it will be. [originally from svn r5729]
This commit is contained in:
9
cube.c
9
cube.c
@ -589,7 +589,8 @@ static void classify_grid_square_callback(void *ctx, struct grid_square *sq)
|
|||||||
data->squareindex++;
|
data->squareindex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *new_game_seed(game_params *params, random_state *rs)
|
static char *new_game_seed(game_params *params, random_state *rs,
|
||||||
|
game_aux_info **aux)
|
||||||
{
|
{
|
||||||
struct grid_data data;
|
struct grid_data data;
|
||||||
int i, j, k, m, area, facesperclass;
|
int i, j, k, m, area, facesperclass;
|
||||||
@ -690,6 +691,11 @@ static char *new_game_seed(game_params *params, random_state *rs)
|
|||||||
return seed;
|
return seed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void game_free_aux_info(game_aux_info *aux)
|
||||||
|
{
|
||||||
|
assert(!"Shouldn't happen");
|
||||||
|
}
|
||||||
|
|
||||||
static void add_grid_square_callback(void *ctx, struct grid_square *sq)
|
static void add_grid_square_callback(void *ctx, struct grid_square *sq)
|
||||||
{
|
{
|
||||||
game_state *state = (game_state *)ctx;
|
game_state *state = (game_state *)ctx;
|
||||||
@ -1546,6 +1552,7 @@ const struct game thegame = {
|
|||||||
TRUE, game_configure, custom_params,
|
TRUE, game_configure, custom_params,
|
||||||
validate_params,
|
validate_params,
|
||||||
new_game_seed,
|
new_game_seed,
|
||||||
|
game_free_aux_info,
|
||||||
validate_seed,
|
validate_seed,
|
||||||
new_game,
|
new_game,
|
||||||
dup_game,
|
dup_game,
|
||||||
|
@ -152,7 +152,8 @@ static int perm_parity(int *perm, int n)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *new_game_seed(game_params *params, random_state *rs)
|
static char *new_game_seed(game_params *params, random_state *rs,
|
||||||
|
game_aux_info **aux)
|
||||||
{
|
{
|
||||||
int gap, n, i, x;
|
int gap, n, i, x;
|
||||||
int x1, x2, p1, p2, parity;
|
int x1, x2, p1, p2, parity;
|
||||||
@ -267,6 +268,11 @@ static char *new_game_seed(game_params *params, random_state *rs)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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_seed(game_params *params, char *seed)
|
||||||
{
|
{
|
||||||
char *p, *err;
|
char *p, *err;
|
||||||
@ -776,6 +782,7 @@ const struct game thegame = {
|
|||||||
TRUE, game_configure, custom_params,
|
TRUE, game_configure, custom_params,
|
||||||
validate_params,
|
validate_params,
|
||||||
new_game_seed,
|
new_game_seed,
|
||||||
|
game_free_aux_info,
|
||||||
validate_seed,
|
validate_seed,
|
||||||
new_game,
|
new_game,
|
||||||
dup_game,
|
dup_game,
|
||||||
|
5
gtk.c
5
gtk.c
@ -1203,9 +1203,12 @@ int main(int argc, char **argv)
|
|||||||
parstr = thegame.encode_params(par);
|
parstr = thegame.encode_params(par);
|
||||||
|
|
||||||
while (n-- > 0) {
|
while (n-- > 0) {
|
||||||
char *seed = thegame.new_seed(par, rs);
|
game_aux_info *aux = NULL;
|
||||||
|
char *seed = thegame.new_seed(par, rs, &aux);
|
||||||
printf("%s:%s\n", parstr, seed);
|
printf("%s:%s\n", parstr, seed);
|
||||||
sfree(seed);
|
sfree(seed);
|
||||||
|
if (aux)
|
||||||
|
thegame.free_aux_info(aux);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
18
midend.c
18
midend.c
@ -17,6 +17,7 @@ struct midend_data {
|
|||||||
const game *ourgame;
|
const game *ourgame;
|
||||||
|
|
||||||
char *seed;
|
char *seed;
|
||||||
|
game_aux_info *aux_info;
|
||||||
int fresh_seed;
|
int fresh_seed;
|
||||||
int nstates, statesize, statepos;
|
int nstates, statesize, statepos;
|
||||||
|
|
||||||
@ -58,6 +59,7 @@ midend_data *midend_new(frontend *fe, const game *ourgame)
|
|||||||
me->states = NULL;
|
me->states = NULL;
|
||||||
me->params = ourgame->default_params();
|
me->params = ourgame->default_params();
|
||||||
me->seed = NULL;
|
me->seed = NULL;
|
||||||
|
me->aux_info = NULL;
|
||||||
me->fresh_seed = FALSE;
|
me->fresh_seed = FALSE;
|
||||||
me->drawstate = NULL;
|
me->drawstate = NULL;
|
||||||
me->oldstate = NULL;
|
me->oldstate = NULL;
|
||||||
@ -79,6 +81,8 @@ void midend_free(midend_data *me)
|
|||||||
{
|
{
|
||||||
sfree(me->states);
|
sfree(me->states);
|
||||||
sfree(me->seed);
|
sfree(me->seed);
|
||||||
|
if (me->aux_info)
|
||||||
|
me->ourgame->free_aux_info(me->aux_info);
|
||||||
me->ourgame->free_params(me->params);
|
me->ourgame->free_params(me->params);
|
||||||
sfree(me);
|
sfree(me);
|
||||||
}
|
}
|
||||||
@ -106,7 +110,11 @@ void midend_new_game(midend_data *me)
|
|||||||
|
|
||||||
if (!me->fresh_seed) {
|
if (!me->fresh_seed) {
|
||||||
sfree(me->seed);
|
sfree(me->seed);
|
||||||
me->seed = me->ourgame->new_seed(me->params, me->random);
|
if (me->aux_info)
|
||||||
|
me->ourgame->free_aux_info(me->aux_info);
|
||||||
|
me->aux_info = NULL;
|
||||||
|
me->seed = me->ourgame->new_seed(me->params, me->random,
|
||||||
|
&me->aux_info);
|
||||||
} else
|
} else
|
||||||
me->fresh_seed = FALSE;
|
me->fresh_seed = FALSE;
|
||||||
|
|
||||||
@ -399,9 +407,12 @@ float *midend_colours(midend_data *me, int *ncolours)
|
|||||||
float *ret;
|
float *ret;
|
||||||
|
|
||||||
if (me->nstates == 0) {
|
if (me->nstates == 0) {
|
||||||
char *seed = me->ourgame->new_seed(me->params, me->random);
|
game_aux_info *aux = NULL;
|
||||||
|
char *seed = me->ourgame->new_seed(me->params, me->random, &aux);
|
||||||
state = me->ourgame->new_game(me->params, seed);
|
state = me->ourgame->new_game(me->params, seed);
|
||||||
sfree(seed);
|
sfree(seed);
|
||||||
|
if (aux)
|
||||||
|
me->ourgame->free_aux_info(aux);
|
||||||
} else
|
} else
|
||||||
state = me->states[0];
|
state = me->states[0];
|
||||||
|
|
||||||
@ -540,6 +551,9 @@ char *midend_game_id(midend_data *me, char *id, int def_seed)
|
|||||||
sfree(me->seed);
|
sfree(me->seed);
|
||||||
me->seed = dupstr(seed);
|
me->seed = dupstr(seed);
|
||||||
me->fresh_seed = TRUE;
|
me->fresh_seed = TRUE;
|
||||||
|
if (me->aux_info)
|
||||||
|
me->ourgame->free_aux_info(me->aux_info);
|
||||||
|
me->aux_info = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
9
net.c
9
net.c
@ -290,7 +290,8 @@ static char *validate_params(game_params *params)
|
|||||||
* Randomly select a new game seed.
|
* Randomly select a new game seed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static char *new_game_seed(game_params *params, random_state *rs)
|
static char *new_game_seed(game_params *params, random_state *rs,
|
||||||
|
game_aux_info **aux)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* The full description of a Net game is far too large to
|
* The full description of a Net game is far too large to
|
||||||
@ -308,6 +309,11 @@ static char *new_game_seed(game_params *params, random_state *rs)
|
|||||||
return dupstr(buf);
|
return dupstr(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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_seed(game_params *params, char *seed)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@ -1509,6 +1515,7 @@ const struct game thegame = {
|
|||||||
TRUE, game_configure, custom_params,
|
TRUE, game_configure, custom_params,
|
||||||
validate_params,
|
validate_params,
|
||||||
new_game_seed,
|
new_game_seed,
|
||||||
|
game_free_aux_info,
|
||||||
validate_seed,
|
validate_seed,
|
||||||
new_game,
|
new_game,
|
||||||
dup_game,
|
dup_game,
|
||||||
|
@ -308,7 +308,8 @@ static char *validate_params(game_params *params)
|
|||||||
* Randomly select a new game seed.
|
* Randomly select a new game seed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static char *new_game_seed(game_params *params, random_state *rs)
|
static char *new_game_seed(game_params *params, random_state *rs,
|
||||||
|
game_aux_info **aux)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* The full description of a Net game is far too large to
|
* The full description of a Net game is far too large to
|
||||||
@ -326,6 +327,11 @@ static char *new_game_seed(game_params *params, random_state *rs)
|
|||||||
return dupstr(buf);
|
return dupstr(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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_seed(game_params *params, char *seed)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@ -1533,6 +1539,7 @@ const struct game thegame = {
|
|||||||
TRUE, game_configure, custom_params,
|
TRUE, game_configure, custom_params,
|
||||||
validate_params,
|
validate_params,
|
||||||
new_game_seed,
|
new_game_seed,
|
||||||
|
game_free_aux_info,
|
||||||
validate_seed,
|
validate_seed,
|
||||||
new_game,
|
new_game,
|
||||||
dup_game,
|
dup_game,
|
||||||
|
@ -88,11 +88,17 @@ static char *validate_params(game_params *params)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *new_game_seed(game_params *params, random_state *rs)
|
static char *new_game_seed(game_params *params, random_state *rs,
|
||||||
|
game_aux_info **aux)
|
||||||
{
|
{
|
||||||
return dupstr("FIXME");
|
return dupstr("FIXME");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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_seed(game_params *params, char *seed)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -223,6 +229,7 @@ const struct game thegame = {
|
|||||||
FALSE, game_configure, custom_params,
|
FALSE, game_configure, custom_params,
|
||||||
validate_params,
|
validate_params,
|
||||||
new_game_seed,
|
new_game_seed,
|
||||||
|
game_free_aux_info,
|
||||||
validate_seed,
|
validate_seed,
|
||||||
new_game,
|
new_game,
|
||||||
dup_game,
|
dup_game,
|
||||||
|
@ -476,7 +476,8 @@ static unsigned char *generate_soluble(random_state *rs, int w, int h)
|
|||||||
return grid;
|
return grid;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *new_game_seed(game_params *params, random_state *rs)
|
static char *new_game_seed(game_params *params, random_state *rs,
|
||||||
|
game_aux_info **aux)
|
||||||
{
|
{
|
||||||
unsigned char *grid;
|
unsigned char *grid;
|
||||||
int i, j, max, rowlen, *rowdata;
|
int i, j, max, rowlen, *rowdata;
|
||||||
@ -540,6 +541,11 @@ static char *new_game_seed(game_params *params, random_state *rs)
|
|||||||
return seed;
|
return seed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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_seed(game_params *params, char *seed)
|
||||||
{
|
{
|
||||||
int i, n, rowspace;
|
int i, n, rowspace;
|
||||||
@ -1030,6 +1036,7 @@ const struct game thegame = {
|
|||||||
TRUE, game_configure, custom_params,
|
TRUE, game_configure, custom_params,
|
||||||
validate_params,
|
validate_params,
|
||||||
new_game_seed,
|
new_game_seed,
|
||||||
|
game_free_aux_info,
|
||||||
validate_seed,
|
validate_seed,
|
||||||
new_game,
|
new_game,
|
||||||
dup_game,
|
dup_game,
|
||||||
|
@ -52,6 +52,7 @@ typedef struct midend_data midend_data;
|
|||||||
typedef struct random_state random_state;
|
typedef struct random_state random_state;
|
||||||
typedef struct game_params game_params;
|
typedef struct game_params game_params;
|
||||||
typedef struct game_state game_state;
|
typedef struct game_state game_state;
|
||||||
|
typedef struct game_aux_info game_aux_info;
|
||||||
typedef struct game_ui game_ui;
|
typedef struct game_ui game_ui;
|
||||||
typedef struct game_drawstate game_drawstate;
|
typedef struct game_drawstate game_drawstate;
|
||||||
typedef struct game game;
|
typedef struct game game;
|
||||||
@ -189,7 +190,9 @@ struct game {
|
|||||||
config_item *(*configure)(game_params *params);
|
config_item *(*configure)(game_params *params);
|
||||||
game_params *(*custom_params)(config_item *cfg);
|
game_params *(*custom_params)(config_item *cfg);
|
||||||
char *(*validate_params)(game_params *params);
|
char *(*validate_params)(game_params *params);
|
||||||
char *(*new_seed)(game_params *params, random_state *rs);
|
char *(*new_seed)(game_params *params, random_state *rs,
|
||||||
|
game_aux_info **aux);
|
||||||
|
void (*free_aux_info)(game_aux_info *aux);
|
||||||
char *(*validate_seed)(game_params *params, char *seed);
|
char *(*validate_seed)(game_params *params, char *seed);
|
||||||
game_state *(*new_game)(game_params *params, char *seed);
|
game_state *(*new_game)(game_params *params, char *seed);
|
||||||
game_state *(*dup_game)(game_state *state);
|
game_state *(*dup_game)(game_state *state);
|
||||||
|
9
rect.c
9
rect.c
@ -386,7 +386,8 @@ static void display_grid(game_params *params, int *grid, int *numbers, int all)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static char *new_game_seed(game_params *params, random_state *rs)
|
static char *new_game_seed(game_params *params, random_state *rs,
|
||||||
|
game_aux_info **aux)
|
||||||
{
|
{
|
||||||
int *grid, *numbers;
|
int *grid, *numbers;
|
||||||
struct rectlist *list;
|
struct rectlist *list;
|
||||||
@ -898,6 +899,11 @@ static char *new_game_seed(game_params *params, random_state *rs)
|
|||||||
return seed;
|
return seed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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_seed(game_params *params, char *seed)
|
||||||
{
|
{
|
||||||
int area = params->w * params->h;
|
int area = params->w * params->h;
|
||||||
@ -1703,6 +1709,7 @@ const struct game thegame = {
|
|||||||
TRUE, game_configure, custom_params,
|
TRUE, game_configure, custom_params,
|
||||||
validate_params,
|
validate_params,
|
||||||
new_game_seed,
|
new_game_seed,
|
||||||
|
game_free_aux_info,
|
||||||
validate_seed,
|
validate_seed,
|
||||||
new_game,
|
new_game,
|
||||||
dup_game,
|
dup_game,
|
||||||
|
@ -172,7 +172,8 @@ static int perm_parity(int *perm, int n)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *new_game_seed(game_params *params, random_state *rs)
|
static char *new_game_seed(game_params *params, random_state *rs,
|
||||||
|
game_aux_info **aux)
|
||||||
{
|
{
|
||||||
int stop, n, i, x;
|
int stop, n, i, x;
|
||||||
int x1, x2, p1, p2;
|
int x1, x2, p1, p2;
|
||||||
@ -278,6 +279,11 @@ static char *new_game_seed(game_params *params, random_state *rs)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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_seed(game_params *params, char *seed)
|
||||||
{
|
{
|
||||||
@ -823,6 +829,7 @@ const struct game thegame = {
|
|||||||
TRUE, game_configure, custom_params,
|
TRUE, game_configure, custom_params,
|
||||||
validate_params,
|
validate_params,
|
||||||
new_game_seed,
|
new_game_seed,
|
||||||
|
game_free_aux_info,
|
||||||
validate_seed,
|
validate_seed,
|
||||||
new_game,
|
new_game,
|
||||||
dup_game,
|
dup_game,
|
||||||
|
9
solo.c
9
solo.c
@ -1351,7 +1351,8 @@ static int symmetries(game_params *params, int x, int y, int *output, int s)
|
|||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *new_game_seed(game_params *params, random_state *rs)
|
static char *new_game_seed(game_params *params, random_state *rs,
|
||||||
|
game_aux_info **aux)
|
||||||
{
|
{
|
||||||
int c = params->c, r = params->r, cr = c*r;
|
int c = params->c, r = params->r, cr = c*r;
|
||||||
int area = cr*cr;
|
int area = cr*cr;
|
||||||
@ -1513,6 +1514,11 @@ static char *new_game_seed(game_params *params, random_state *rs)
|
|||||||
return seed;
|
return seed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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_seed(game_params *params, char *seed)
|
||||||
{
|
{
|
||||||
int area = params->r * params->r * params->c * params->c;
|
int area = params->r * params->r * params->c * params->c;
|
||||||
@ -1959,6 +1965,7 @@ const struct game thegame = {
|
|||||||
TRUE, game_configure, custom_params,
|
TRUE, game_configure, custom_params,
|
||||||
validate_params,
|
validate_params,
|
||||||
new_game_seed,
|
new_game_seed,
|
||||||
|
game_free_aux_info,
|
||||||
validate_seed,
|
validate_seed,
|
||||||
new_game,
|
new_game,
|
||||||
dup_game,
|
dup_game,
|
||||||
|
@ -291,7 +291,8 @@ static int grid_complete(int *grid, int wh, int orientable)
|
|||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *new_game_seed(game_params *params, random_state *rs)
|
static char *new_game_seed(game_params *params, random_state *rs,
|
||||||
|
game_aux_info **aux)
|
||||||
{
|
{
|
||||||
int *grid;
|
int *grid;
|
||||||
int w = params->w, h = params->h, n = params->n, wh = w*h;
|
int w = params->w, h = params->h, n = params->n, wh = w*h;
|
||||||
@ -358,6 +359,11 @@ static char *new_game_seed(game_params *params, random_state *rs)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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_seed(game_params *params, char *seed)
|
||||||
{
|
{
|
||||||
char *p, *err;
|
char *p, *err;
|
||||||
@ -985,6 +991,7 @@ const struct game thegame = {
|
|||||||
TRUE, game_configure, custom_params,
|
TRUE, game_configure, custom_params,
|
||||||
validate_params,
|
validate_params,
|
||||||
new_game_seed,
|
new_game_seed,
|
||||||
|
game_free_aux_info,
|
||||||
validate_seed,
|
validate_seed,
|
||||||
new_game,
|
new_game,
|
||||||
dup_game,
|
dup_game,
|
||||||
|
Reference in New Issue
Block a user