struct game_state {
int w, h, n, dead, won;
struct mine_layout *layout; /* real mine positions */
- char *grid; /* player knowledge */
+ signed char *grid; /* player knowledge */
/*
* Each item in the `grid' array is one of the following values:
*
std->next[i] = -1;
}
-static void known_squares(int w, int h, struct squaretodo *std, char *grid,
+static void known_squares(int w, int h, struct squaretodo *std,
+ signed char *grid,
int (*open)(void *ctx, int x, int y), void *openctx,
int x, int y, int mask, int mine)
{
* steps were required; the exact return value is the number of
* perturb calls.
*/
-static int minesolve(int w, int h, int n, char *grid,
+static int minesolve(int w, int h, int n, signed char *grid,
int (*open)(void *ctx, int x, int y),
- struct perturbations *(*perturb)(void *ctx, char *grid,
+ struct perturbations *(*perturb)(void *ctx,
+ signed char *grid,
int x, int y, int mask),
void *ctx, random_state *rs)
{
*/
struct minectx {
- char *grid;
+ signed char *grid;
int w, h;
int sx, sy;
random_state *rs;
return 0;
}
-static struct perturbations *mineperturb(void *vctx, char *grid,
+static struct perturbations *mineperturb(void *vctx, signed char *grid,
int setx, int sety, int mask)
{
struct minectx *ctx = (struct minectx *)vctx;
* We bypass this bit if we're not after a unique grid.
*/
if (unique) {
- char *solvegrid = snewn(w*h, char);
+ signed char *solvegrid = snewn(w*h, char);
struct minectx actx, *ctx = &actx;
int solveret, prevret = -2;
static char *new_mine_layout(int w, int h, int n, int x, int y, int unique,
random_state *rs, char **game_desc)
{
- char *grid, *ret, *p;
+ signed char *grid, *ret, *p;
unsigned char *bmp;
int i, area;
}
static char *new_game_desc(game_params *params, random_state *rs,
- game_aux_info **aux)
+ game_aux_info **aux, int interactive)
{
-#ifdef PREOPENED
- int x = random_upto(rs, params->w);
- int y = random_upto(rs, params->h);
- char *grid, *desc;
+ if (!interactive) {
+ /*
+ * For batch-generated grids, pre-open one square.
+ */
+ int x = random_upto(rs, params->w);
+ int y = random_upto(rs, params->h);
+ signed char *grid;
+ char *desc;
- grid = new_mine_layout(params->w, params->h, params->n,
- x, y, params->unique, rs);
-#else
- char *rsdesc, *desc;
+ grid = new_mine_layout(params->w, params->h, params->n,
+ x, y, params->unique, rs, &desc);
+ sfree(grid);
+ return desc;
+ } else {
+ char *rsdesc, *desc;
- rsdesc = random_state_encode(rs);
- desc = snewn(strlen(rsdesc) + 100, char);
- sprintf(desc, "r%d,%c,%s", params->n, params->unique ? 'u' : 'a', rsdesc);
- sfree(rsdesc);
- return desc;
-#endif
+ rsdesc = random_state_encode(rs);
+ desc = snewn(strlen(rsdesc) + 100, char);
+ sprintf(desc, "r%d,%c,%s", params->n, params->unique ? 'u' : 'a', rsdesc);
+ sfree(rsdesc);
+ return desc;
+ }
}
static void game_free_aux_info(game_aux_info *aux)
state->layout->me = me;
} else {
+ state->layout->rs = NULL;
+ state->layout->me = NULL;
state->layout->mines = snewn(wh, char);
x = atoi(desc);
struct game_drawstate {
int w, h, started;
- char *grid;
+ signed char *grid;
/*
* Items in this `grid' array have all the same values as in
* the game_state grid, and in addition: