mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 08:01:30 -07:00
Added an `interactive' flag to new_game_desc(), which toggles Mines
between on the one hand generating indeterminate game descriptions awaiting the initial click, and on the other hand generating concrete ones which have had their initial click. This makes `mines --generate' do something useful. [originally from svn r5869]
This commit is contained in:
2
cube.c
2
cube.c
@ -586,7 +586,7 @@ static void classify_grid_square_callback(void *ctx, struct grid_square *sq)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static char *new_game_desc(game_params *params, random_state *rs,
|
static char *new_game_desc(game_params *params, random_state *rs,
|
||||||
game_aux_info **aux)
|
game_aux_info **aux, int interactive)
|
||||||
{
|
{
|
||||||
struct grid_data data;
|
struct grid_data data;
|
||||||
int i, j, k, m, area, facesperclass;
|
int i, j, k, m, area, facesperclass;
|
||||||
|
@ -151,7 +151,7 @@ static int perm_parity(int *perm, int n)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static char *new_game_desc(game_params *params, random_state *rs,
|
static char *new_game_desc(game_params *params, random_state *rs,
|
||||||
game_aux_info **aux)
|
game_aux_info **aux, int interactive)
|
||||||
{
|
{
|
||||||
int gap, n, i, x;
|
int gap, n, i, x;
|
||||||
int x1, x2, p1, p2, parity;
|
int x1, x2, p1, p2, parity;
|
||||||
|
2
gtk.c
2
gtk.c
@ -1307,7 +1307,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
while (n-- > 0) {
|
while (n-- > 0) {
|
||||||
game_aux_info *aux = NULL;
|
game_aux_info *aux = NULL;
|
||||||
char *desc = thegame.new_desc(par, rs, &aux);
|
char *desc = thegame.new_desc(par, rs, &aux, FALSE);
|
||||||
printf("%s:%s\n", parstr, desc);
|
printf("%s:%s\n", parstr, desc);
|
||||||
sfree(desc);
|
sfree(desc);
|
||||||
if (aux)
|
if (aux)
|
||||||
|
6
midend.c
6
midend.c
@ -178,7 +178,8 @@ void midend_new_game(midend_data *me)
|
|||||||
me->aux_info = NULL;
|
me->aux_info = NULL;
|
||||||
|
|
||||||
rs = random_init(me->seedstr, strlen(me->seedstr));
|
rs = random_init(me->seedstr, strlen(me->seedstr));
|
||||||
me->desc = me->ourgame->new_desc(me->curparams, rs, &me->aux_info);
|
me->desc = me->ourgame->new_desc(me->curparams, rs,
|
||||||
|
&me->aux_info, TRUE);
|
||||||
random_free(rs);
|
random_free(rs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -521,7 +522,8 @@ float *midend_colours(midend_data *me, int *ncolours)
|
|||||||
|
|
||||||
if (me->nstates == 0) {
|
if (me->nstates == 0) {
|
||||||
game_aux_info *aux = NULL;
|
game_aux_info *aux = NULL;
|
||||||
char *desc = me->ourgame->new_desc(me->params, me->random, &aux);
|
char *desc = me->ourgame->new_desc(me->params, me->random,
|
||||||
|
&aux, TRUE);
|
||||||
state = me->ourgame->new_game(me, me->params, desc);
|
state = me->ourgame->new_game(me, me->params, desc);
|
||||||
sfree(desc);
|
sfree(desc);
|
||||||
if (aux)
|
if (aux)
|
||||||
|
35
mines.c
35
mines.c
@ -1847,24 +1847,29 @@ static char *new_mine_layout(int w, int h, int n, int x, int y, int unique,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static char *new_game_desc(game_params *params, random_state *rs,
|
static char *new_game_desc(game_params *params, random_state *rs,
|
||||||
game_aux_info **aux)
|
game_aux_info **aux, int interactive)
|
||||||
{
|
{
|
||||||
#ifdef PREOPENED
|
if (!interactive) {
|
||||||
int x = random_upto(rs, params->w);
|
/*
|
||||||
int y = random_upto(rs, params->h);
|
* For batch-generated grids, pre-open one square.
|
||||||
char *grid, *desc;
|
*/
|
||||||
|
int x = random_upto(rs, params->w);
|
||||||
|
int y = random_upto(rs, params->h);
|
||||||
|
char *grid, *desc;
|
||||||
|
|
||||||
grid = new_mine_layout(params->w, params->h, params->n,
|
grid = new_mine_layout(params->w, params->h, params->n,
|
||||||
x, y, params->unique, rs);
|
x, y, params->unique, rs, &desc);
|
||||||
#else
|
sfree(grid);
|
||||||
char *rsdesc, *desc;
|
return desc;
|
||||||
|
} else {
|
||||||
|
char *rsdesc, *desc;
|
||||||
|
|
||||||
rsdesc = random_state_encode(rs);
|
rsdesc = random_state_encode(rs);
|
||||||
desc = snewn(strlen(rsdesc) + 100, char);
|
desc = snewn(strlen(rsdesc) + 100, char);
|
||||||
sprintf(desc, "r%d,%c,%s", params->n, params->unique ? 'u' : 'a', rsdesc);
|
sprintf(desc, "r%d,%c,%s", params->n, params->unique ? 'u' : 'a', rsdesc);
|
||||||
sfree(rsdesc);
|
sfree(rsdesc);
|
||||||
return desc;
|
return desc;
|
||||||
#endif
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void game_free_aux_info(game_aux_info *aux)
|
static void game_free_aux_info(game_aux_info *aux)
|
||||||
|
2
net.c
2
net.c
@ -1146,7 +1146,7 @@ static void perturb(int w, int h, unsigned char *tiles, int wrapping,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static char *new_game_desc(game_params *params, random_state *rs,
|
static char *new_game_desc(game_params *params, random_state *rs,
|
||||||
game_aux_info **aux)
|
game_aux_info **aux, int interactive)
|
||||||
{
|
{
|
||||||
tree234 *possibilities, *barriertree;
|
tree234 *possibilities, *barriertree;
|
||||||
int w, h, x, y, cx, cy, nbarriers;
|
int w, h, x, y, cx, cy, nbarriers;
|
||||||
|
@ -334,7 +334,7 @@ static char *validate_params(game_params *params)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static char *new_game_desc(game_params *params, random_state *rs,
|
static char *new_game_desc(game_params *params, random_state *rs,
|
||||||
game_aux_info **aux)
|
game_aux_info **aux, int interactive)
|
||||||
{
|
{
|
||||||
tree234 *possibilities, *barriertree;
|
tree234 *possibilities, *barriertree;
|
||||||
int w, h, x, y, cx, cy, nbarriers;
|
int w, h, x, y, cx, cy, nbarriers;
|
||||||
|
@ -84,7 +84,7 @@ static char *validate_params(game_params *params)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static char *new_game_desc(game_params *params, random_state *rs,
|
static char *new_game_desc(game_params *params, random_state *rs,
|
||||||
game_aux_info **aux)
|
game_aux_info **aux, int interactive)
|
||||||
{
|
{
|
||||||
return dupstr("FIXME");
|
return dupstr("FIXME");
|
||||||
}
|
}
|
||||||
|
@ -475,7 +475,7 @@ struct game_aux_info {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static char *new_game_desc(game_params *params, random_state *rs,
|
static char *new_game_desc(game_params *params, random_state *rs,
|
||||||
game_aux_info **aux)
|
game_aux_info **aux, int interactive)
|
||||||
{
|
{
|
||||||
unsigned char *grid;
|
unsigned char *grid;
|
||||||
int i, j, max, rowlen, *rowdata;
|
int i, j, max, rowlen, *rowdata;
|
||||||
|
@ -214,7 +214,7 @@ struct game {
|
|||||||
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_desc)(game_params *params, random_state *rs,
|
char *(*new_desc)(game_params *params, random_state *rs,
|
||||||
game_aux_info **aux);
|
game_aux_info **aux, int interactive);
|
||||||
void (*free_aux_info)(game_aux_info *aux);
|
void (*free_aux_info)(game_aux_info *aux);
|
||||||
char *(*validate_desc)(game_params *params, char *desc);
|
char *(*validate_desc)(game_params *params, char *desc);
|
||||||
game_state *(*new_game)(midend_data *me, game_params *params, char *desc);
|
game_state *(*new_game)(midend_data *me, game_params *params, char *desc);
|
||||||
|
2
rect.c
2
rect.c
@ -1054,7 +1054,7 @@ struct game_aux_info {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static char *new_game_desc(game_params *params, random_state *rs,
|
static char *new_game_desc(game_params *params, random_state *rs,
|
||||||
game_aux_info **aux)
|
game_aux_info **aux, int interactive)
|
||||||
{
|
{
|
||||||
int *grid, *numbers = NULL;
|
int *grid, *numbers = NULL;
|
||||||
struct rectlist *list;
|
struct rectlist *list;
|
||||||
|
@ -194,7 +194,7 @@ static int perm_parity(int *perm, int n)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static char *new_game_desc(game_params *params, random_state *rs,
|
static char *new_game_desc(game_params *params, random_state *rs,
|
||||||
game_aux_info **aux)
|
game_aux_info **aux, int interactive)
|
||||||
{
|
{
|
||||||
int stop, n, i, x;
|
int stop, n, i, x;
|
||||||
int x1, x2, p1, p2;
|
int x1, x2, p1, p2;
|
||||||
|
2
solo.c
2
solo.c
@ -1397,7 +1397,7 @@ struct game_aux_info {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static char *new_game_desc(game_params *params, random_state *rs,
|
static char *new_game_desc(game_params *params, random_state *rs,
|
||||||
game_aux_info **aux)
|
game_aux_info **aux, int interactive)
|
||||||
{
|
{
|
||||||
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;
|
||||||
|
@ -308,7 +308,7 @@ static int grid_complete(int *grid, int wh, int orientable)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static char *new_game_desc(game_params *params, random_state *rs,
|
static char *new_game_desc(game_params *params, random_state *rs,
|
||||||
game_aux_info **aux)
|
game_aux_info **aux, int interactive)
|
||||||
{
|
{
|
||||||
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;
|
||||||
|
Reference in New Issue
Block a user