float barrier_probability;
};
-struct game_aux_info {
- int width, height;
- unsigned char *tiles;
-};
-
struct game_state {
int width, height, wrapping, completed;
int last_rotate_x, last_rotate_y, last_rotate_dir;
}
static char *new_game_desc(game_params *params, random_state *rs,
- game_aux_info **aux, int interactive)
+ char **aux, int interactive)
{
tree234 *possibilities, *barriertree;
int w, h, x, y, cx, cy, nbarriers;
}
/*
- * Save the unshuffled grid in an aux_info.
+ * Save the unshuffled grid in aux.
*/
{
- game_aux_info *solution;
+ char *solution;
+ int i;
- solution = snew(game_aux_info);
- solution->width = w;
- solution->height = h;
- solution->tiles = snewn(w * h, unsigned char);
- memcpy(solution->tiles, tiles, w * h);
+ solution = snewn(w * h + 1, char);
+ for (i = 0; i < w * h; i++)
+ solution[i] = "0123456789abcdef"[tiles[i] & 0xF];
+ solution[w*h] = '\0';
*aux = solution;
}
return desc;
}
-static void game_free_aux_info(game_aux_info *aux)
-{
- sfree(aux->tiles);
- sfree(aux);
-}
-
static char *validate_desc(game_params *params, char *desc)
{
int w = params->width, h = params->height;
}
static char *solve_game(game_state *state, game_state *currstate,
- game_aux_info *aux, char **error)
+ char *aux, char **error)
{
unsigned char *tiles;
char *ret;
int retlen, retsize;
int i;
- int tiles_need_freeing;
+
+ tiles = snewn(state->width * state->height, unsigned char);
if (!aux) {
/*
* Run the internal solver on the provided grid. This might
* not yield a complete solution.
*/
- tiles = snewn(state->width * state->height, unsigned char);
memcpy(tiles, state->tiles, state->width * state->height);
net_solver(state->width, state->height, tiles,
state->barriers, state->wrapping);
- tiles_need_freeing = TRUE;
} else {
- tiles = aux->tiles;
- tiles_need_freeing = FALSE;
+ for (i = 0; i < state->width * state->height; i++) {
+ int c = aux[i];
+
+ if (c >= '0' && c <= '9')
+ tiles[i] = c - '0';
+ else if (c >= 'a' && c <= 'f')
+ tiles[i] = c - 'a' + 10;
+ else if (c >= 'A' && c <= 'F')
+ tiles[i] = c - 'A' + 10;
+ }
}
/*
ret[retlen] = '\0';
ret = sresize(ret, retlen+1, char);
+ sfree(tiles);
+
return ret;
}
sfree(ui);
}
-char *encode_ui(game_ui *ui)
+static char *encode_ui(game_ui *ui)
{
char buf[120];
/*
return dupstr(buf);
}
-void decode_ui(game_ui *ui, char *encoding)
+static void decode_ui(game_ui *ui, char *encoding)
{
sscanf(encoding, "O%d,%d;C%d,%d",
&ui->org_x, &ui->org_y, &ui->cx, &ui->cy);
sprintf(buf, "L%d,%d", tx, ty);
return dupstr(buf);
} else if (button == LEFT_BUTTON || button == RIGHT_BUTTON) {
+ char buf[80];
/*
* The left and right buttons have no effect if clicked on a
* Otherwise, turn the tile one way or the other. Left button
* turns anticlockwise; right button turns clockwise.
*/
- char buf[80];
sprintf(buf, "%c%d,%d", (button == LEFT_BUTTON ? 'A' : 'C'), tx, ty);
return dupstr(buf);
} else if (button == 'J') {
sfree(ds);
}
-static void game_size(game_params *params, game_drawstate *ds, int *x, int *y,
- int expand)
+static void game_compute_size(game_params *params, int tilesize,
+ int *x, int *y)
{
- int tsx, tsy, ts;
- /*
- * Each window dimension equals the tile size times the grid
- * dimension, plus TILE_BORDER, plus twice WINDOW_OFFSET.
- */
- tsx = (*x - 2*WINDOW_OFFSET - TILE_BORDER) / params->width;
- tsy = (*y - 2*WINDOW_OFFSET - TILE_BORDER) / params->height;
- ts = min(tsx, tsy);
-
- if (expand)
- ds->tilesize = ts;
- else
- ds->tilesize = min(ts, PREFERRED_TILE_SIZE);
+ *x = WINDOW_OFFSET * 2 + tilesize * params->width + TILE_BORDER;
+ *y = WINDOW_OFFSET * 2 + tilesize * params->height + TILE_BORDER;
+}
- *x = WINDOW_OFFSET * 2 + TILE_SIZE * params->width + TILE_BORDER;
- *y = WINDOW_OFFSET * 2 + TILE_SIZE * params->height + TILE_BORDER;
+static void game_set_size(game_drawstate *ds, game_params *params,
+ int tilesize)
+{
+ ds->tilesize = tilesize;
}
static float *game_colours(frontend *fe, game_state *state, int *ncolours)
points[i+1] = by+(int)(cy+ty);
}
- draw_polygon(fe, points, 4, TRUE, col);
- draw_polygon(fe, points, 4, FALSE, COL_WIRE);
+ draw_polygon(fe, points, 4, col, COL_WIRE);
}
/*
TRUE, game_configure, custom_params,
validate_params,
new_game_desc,
- game_free_aux_info,
validate_desc,
new_game,
dup_game,
game_changed_state,
interpret_move,
execute_move,
- game_size,
+ PREFERRED_TILE_SIZE, game_compute_size, game_set_size,
game_colours,
game_new_drawstate,
game_free_drawstate,