X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/puzzles/blobdiff_plain/df11cd4e43b66b17df44a1e933f5c71361dc13a4..de3b0e332712c81307a7800808b6d13d2c5cec93:/netslide.c diff --git a/netslide.c b/netslide.c index b329d8d..206535b 100644 --- a/netslide.c +++ b/netslide.c @@ -82,11 +82,6 @@ struct game_params { int movetarget; }; -struct game_aux_info { - int width, height; - unsigned char *tiles; -}; - struct game_state { int width, height, cx, cy, wrapping, completed; int used_solve, just_used_solve; @@ -218,16 +213,16 @@ static void decode_params(game_params *ret, char const *string) ret->movetarget = 0; ret->width = atoi(p); - while (*p && isdigit(*p)) p++; + while (*p && isdigit((unsigned char)*p)) p++; if (*p == 'x') { p++; ret->height = atoi(p); - while (*p && isdigit(*p)) p++; + while (*p && isdigit((unsigned char)*p)) p++; if ( (ret->wrapping = (*p == 'w')) != 0 ) p++; if (*p == 'b') { ret->barrier_probability = atof(++p); - while (*p && (isdigit(*p) || *p == '.')) p++; + while (*p && (isdigit((unsigned char)*p) || *p == '.')) p++; } if (*p == 'm') { ret->movetarget = atoi(++p); @@ -314,7 +309,7 @@ static game_params *custom_params(config_item *cfg) return ret; } -static char *validate_params(game_params *params) +static char *validate_params(game_params *params, int full) { if (params->width <= 1 || params->height <= 1) return "Width and height must both be greater than one"; @@ -330,7 +325,7 @@ static char *validate_params(game_params *params) */ 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; @@ -535,19 +530,22 @@ static char *new_game_desc(game_params *params, random_state *rs, } /* - * Save the unshuffled grid. We do this using a separate - * reference-counted structure since it's a large chunk of - * memory which we don't want to have to replicate in every - * game state while playing. + * Save the unshuffled grid in aux. */ { - game_aux_info *solution; + char *solution; + int i; + + /* + * String format is exactly the same as a solve move, so we + * can just dupstr this in solve_game(). + */ - 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 + 2, char); + solution[0] = 'S'; + for (i = 0; i < w * h; i++) + solution[i+1] = "0123456789abcdef"[tiles[i] & 0xF]; + solution[w*h+1] = '\0'; *aux = solution; } @@ -698,12 +696,6 @@ static char *new_game_desc(game_params *params, random_state *rs, 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; @@ -894,24 +886,14 @@ static void free_game(game_state *state) } static char *solve_game(game_state *state, game_state *currstate, - game_aux_info *aux, char **error) + char *aux, char **error) { - char *ret; - int i; - if (!aux) { *error = "Solution not known for this puzzle"; return NULL; } - assert(aux->width == state->width); - assert(aux->height == state->height); - ret = snewn(aux->width * aux->height + 2, char); - ret[0] = 'S'; - for (i = 0; i < aux->width * aux->height; i++) - ret[i+1] = "0123456789abcdef"[aux->tiles[i] & 0xF]; - ret[i+1] = '\0'; - return ret; + return dupstr(aux); } static char *game_text_format(game_state *state) @@ -1005,6 +987,15 @@ static void free_ui(game_ui *ui) sfree(ui); } +static char *encode_ui(game_ui *ui) +{ + return NULL; +} + +static void decode_ui(game_ui *ui, char *encoding) +{ +} + /* ---------------------------------------------------------------------- * Process a move. */ @@ -1203,29 +1194,23 @@ static void game_free_drawstate(game_drawstate *ds) 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 two more - * than the grid dimension (the border containing the arrows is - * the same width as the tiles), plus TILE_BORDER, plus twice - * WINDOW_OFFSET. - */ - tsx = (*x - 2*WINDOW_OFFSET - TILE_BORDER) / (params->width + 2); - tsy = (*y - 2*WINDOW_OFFSET - TILE_BORDER) / (params->height + 2); - ts = min(tsx, tsy); - - if (expand) - ds->tilesize = ts; - else - ds->tilesize = min(ts, PREFERRED_TILE_SIZE); + /* Ick: fake up `ds->tilesize' for macro expansion purposes */ + struct { int tilesize; } ads, *ds = &ads; + ads.tilesize = tilesize; *x = BORDER * 2 + WINDOW_OFFSET * 2 + TILE_SIZE * params->width + TILE_BORDER; *y = BORDER * 2 + 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) { float *ret; @@ -1445,8 +1430,7 @@ static void draw_tile(frontend *fe, game_drawstate *ds, game_state *state, points[i+1] = by+(int)(cy+ey); } - draw_polygon(fe, points, 4, TRUE, col); - draw_polygon(fe, points, 4, FALSE, COL_WIRE); + draw_polygon(fe, points, 4, col, COL_WIRE); } /* @@ -1542,8 +1526,7 @@ static void draw_arrow(frontend *fe, game_drawstate *ds, POINT(5, 3 * TILE_SIZE / 8, TILE_SIZE / 2); /* left concave */ POINT(6, TILE_SIZE / 4, TILE_SIZE / 2); /* left corner */ - draw_polygon(fe, coords, 7, TRUE, COL_LOWLIGHT); - draw_polygon(fe, coords, 7, FALSE, COL_TEXT); + draw_polygon(fe, coords, 7, COL_LOWLIGHT, COL_TEXT); } static void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate, @@ -1793,7 +1776,7 @@ static int game_wants_statusbar(void) return TRUE; } -static int game_timing_state(game_state *state) +static int game_timing_state(game_state *state, game_ui *ui) { return FALSE; } @@ -1813,7 +1796,6 @@ const struct game thegame = { TRUE, game_configure, custom_params, validate_params, new_game_desc, - game_free_aux_info, validate_desc, new_game, dup_game, @@ -1822,10 +1804,12 @@ const struct game thegame = { FALSE, game_text_format, new_ui, free_ui, + encode_ui, + decode_ui, 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,