summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
3f9d88f)
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]
13 files changed:
-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;
int i, j, k, m, area, facesperclass;
{
struct grid_data data;
int i, j, k, m, area, facesperclass;
+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)
{
game_state *state = (game_state *)ctx;
static void add_grid_square_callback(void *ctx, struct grid_square *sq)
{
game_state *state = (game_state *)ctx;
TRUE, game_configure, custom_params,
validate_params,
new_game_seed,
TRUE, game_configure, custom_params,
validate_params,
new_game_seed,
validate_seed,
new_game,
dup_game,
validate_seed,
new_game,
dup_game,
-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 x1, x2, p1, p2, parity;
{
int gap, n, i, x;
int x1, x2, p1, p2, parity;
+void game_free_aux_info(game_aux_info *aux)
+{
+ assert(!"Shouldn't happen");
+}
+
static char *validate_seed(game_params *params, char *seed)
{
char *p, *err;
static char *validate_seed(game_params *params, char *seed)
{
char *p, *err;
TRUE, game_configure, custom_params,
validate_params,
new_game_seed,
TRUE, game_configure, custom_params,
validate_params,
new_game_seed,
validate_seed,
new_game,
dup_game,
validate_seed,
new_game,
dup_game,
parstr = thegame.encode_params(par);
while (n-- > 0) {
parstr = thegame.encode_params(par);
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);
sfree(seed);
printf("%s:%s\n", parstr, seed);
sfree(seed);
+ if (aux)
+ thegame.free_aux_info(aux);
const game *ourgame;
char *seed;
const game *ourgame;
char *seed;
+ game_aux_info *aux_info;
int fresh_seed;
int nstates, statesize, statepos;
int fresh_seed;
int nstates, statesize, statepos;
me->states = NULL;
me->params = ourgame->default_params();
me->seed = NULL;
me->states = NULL;
me->params = ourgame->default_params();
me->seed = NULL;
me->fresh_seed = FALSE;
me->drawstate = NULL;
me->oldstate = NULL;
me->fresh_seed = FALSE;
me->drawstate = NULL;
me->oldstate = NULL;
{
sfree(me->states);
sfree(me->seed);
{
sfree(me->states);
sfree(me->seed);
+ if (me->aux_info)
+ me->ourgame->free_aux_info(me->aux_info);
me->ourgame->free_params(me->params);
sfree(me);
}
me->ourgame->free_params(me->params);
sfree(me);
}
if (!me->fresh_seed) {
sfree(me->seed);
if (!me->fresh_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
me->fresh_seed = FALSE;
} else
me->fresh_seed = FALSE;
float *ret;
if (me->nstates == 0) {
float *ret;
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);
sfree(seed);
state = me->ourgame->new_game(me->params, seed);
sfree(seed);
+ if (aux)
+ me->ourgame->free_aux_info(aux);
} else
state = me->states[0];
} else
state = me->states[0];
sfree(me->seed);
me->seed = dupstr(seed);
me->fresh_seed = TRUE;
sfree(me->seed);
me->seed = dupstr(seed);
me->fresh_seed = TRUE;
+ if (me->aux_info)
+ me->ourgame->free_aux_info(me->aux_info);
+ me->aux_info = NULL;
* 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
+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)
{
/*
TRUE, game_configure, custom_params,
validate_params,
new_game_seed,
TRUE, game_configure, custom_params,
validate_params,
new_game_seed,
validate_seed,
new_game,
dup_game,
validate_seed,
new_game,
dup_game,
* 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
+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)
{
/*
TRUE, game_configure, custom_params,
validate_params,
new_game_seed,
TRUE, game_configure, custom_params,
validate_params,
new_game_seed,
validate_seed,
new_game,
dup_game,
validate_seed,
new_game,
dup_game,
-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)
{
return NULL;
static char *validate_seed(game_params *params, char *seed)
{
return NULL;
FALSE, game_configure, custom_params,
validate_params,
new_game_seed,
FALSE, game_configure, custom_params,
validate_params,
new_game_seed,
validate_seed,
new_game,
dup_game,
validate_seed,
new_game,
dup_game,
-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;
int i, j, max, rowlen, *rowdata;
{
unsigned char *grid;
int i, j, max, rowlen, *rowdata;
+void game_free_aux_info(game_aux_info *aux)
+{
+ assert(!"Shouldn't happen");
+}
+
static char *validate_seed(game_params *params, char *seed)
{
int i, n, rowspace;
static char *validate_seed(game_params *params, char *seed)
{
int i, n, rowspace;
TRUE, game_configure, custom_params,
validate_params,
new_game_seed,
TRUE, game_configure, custom_params,
validate_params,
new_game_seed,
validate_seed,
new_game,
dup_game,
validate_seed,
new_game,
dup_game,
typedef struct random_state random_state;
typedef struct game_params game_params;
typedef struct game_state game_state;
typedef struct random_state random_state;
typedef struct game_params game_params;
typedef struct game_state game_state;
+typedef struct game_aux_info game_aux_info;
typedef struct game_ui game_ui;
typedef struct game_drawstate game_drawstate;
typedef struct game game;
typedef struct game_ui game_ui;
typedef struct game_drawstate game_drawstate;
typedef struct game game;
config_item *(*configure)(game_params *params);
game_params *(*custom_params)(config_item *cfg);
char *(*validate_params)(game_params *params);
config_item *(*configure)(game_params *params);
game_params *(*custom_params)(config_item *cfg);
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);
game_state *(*new_game)(game_params *params, char *seed);
game_state *(*dup_game)(game_state *state);
char *(*validate_seed)(game_params *params, char *seed);
game_state *(*new_game)(game_params *params, char *seed);
game_state *(*dup_game)(game_state *state);
-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;
struct rectlist *list;
{
int *grid, *numbers;
struct rectlist *list;
+void game_free_aux_info(game_aux_info *aux)
+{
+ assert(!"Shouldn't happen");
+}
+
static char *validate_seed(game_params *params, char *seed)
{
int area = params->w * params->h;
static char *validate_seed(game_params *params, char *seed)
{
int area = params->w * params->h;
TRUE, game_configure, custom_params,
validate_params,
new_game_seed,
TRUE, game_configure, custom_params,
validate_params,
new_game_seed,
validate_seed,
new_game,
dup_game,
validate_seed,
new_game,
dup_game,
-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 x1, x2, p1, p2;
{
int stop, n, i, x;
int x1, x2, p1, p2;
+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)
{
TRUE, game_configure, custom_params,
validate_params,
new_game_seed,
TRUE, game_configure, custom_params,
validate_params,
new_game_seed,
validate_seed,
new_game,
dup_game,
validate_seed,
new_game,
dup_game,
-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 area = cr*cr;
{
int c = params->c, r = params->r, cr = c*r;
int area = cr*cr;
+void game_free_aux_info(game_aux_info *aux)
+{
+ assert(!"Shouldn't happen");
+}
+
static char *validate_seed(game_params *params, char *seed)
{
int area = params->r * params->r * params->c * params->c;
static char *validate_seed(game_params *params, char *seed)
{
int area = params->r * params->r * params->c * params->c;
TRUE, game_configure, custom_params,
validate_params,
new_game_seed,
TRUE, game_configure, custom_params,
validate_params,
new_game_seed,
validate_seed,
new_game,
dup_game,
validate_seed,
new_game,
dup_game,
-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 w = params->w, h = params->h, n = params->n, wh = w*h;
{
int *grid;
int w = params->w, h = params->h, n = params->n, wh = w*h;
+void game_free_aux_info(game_aux_info *aux)
+{
+ assert(!"Shouldn't happen");
+}
+
static char *validate_seed(game_params *params, char *seed)
{
char *p, *err;
static char *validate_seed(game_params *params, char *seed)
{
char *p, *err;
TRUE, game_configure, custom_params,
validate_params,
new_game_seed,
TRUE, game_configure, custom_params,
validate_params,
new_game_seed,
validate_seed,
new_game,
dup_game,
validate_seed,
new_game,
dup_game,