X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/puzzles/blobdiff_plain/6f2d8d7c70f6bbf8bce982ced1fa879e967afbbf..2c93e23bba5ad4f2592cedb685c99585d46e505a:/cube.c diff --git a/cube.c b/cube.c index 33ef6d3..12e3ece 100644 --- a/cube.c +++ b/cube.c @@ -274,10 +274,8 @@ static game_params *dup_params(game_params *params) return ret; } -static game_params *decode_params(char const *string) +static void decode_params(game_params *ret, char const *string) { - game_params *ret = default_params(); - switch (*string) { case 't': ret->solid = TETRAHEDRON; string++; break; case 'c': ret->solid = CUBE; string++; break; @@ -291,11 +289,9 @@ static game_params *decode_params(char const *string) string++; ret->d2 = atoi(string); } - - return ret; } -static char *encode_params(game_params *params) +static char *encode_params(game_params *params, int full) { char data[256]; @@ -589,13 +585,13 @@ static void classify_grid_square_callback(void *ctx, struct grid_square *sq) data->squareindex++; } -static char *new_game_seed(game_params *params, random_state *rs, +static char *new_game_desc(game_params *params, random_state *rs, game_aux_info **aux) { struct grid_data data; int i, j, k, m, area, facesperclass; int *flags; - char *seed, *p; + char *desc, *p; /* * Enumerate the grid squares, dividing them into equivalence @@ -659,8 +655,8 @@ static char *new_game_seed(game_params *params, random_state *rs, * the non-blue squares into a list in the now-unused gridptrs * array. */ - seed = snewn(area / 4 + 40, char); - p = seed; + desc = snewn(area / 4 + 40, char); + p = desc; j = 0; k = 8; m = 0; @@ -688,7 +684,7 @@ static char *new_game_seed(game_params *params, random_state *rs, sfree(data.gridptrs[0]); sfree(flags); - return seed; + return desc; } static void game_free_aux_info(game_aux_info *aux) @@ -844,35 +840,35 @@ static struct solid *transform_poly(const struct solid *solid, int flip, return ret; } -static char *validate_seed(game_params *params, char *seed) +static char *validate_desc(game_params *params, char *desc) { int area = grid_area(params->d1, params->d2, solids[params->solid]->order); int i, j; i = (area + 3) / 4; for (j = 0; j < i; j++) { - int c = seed[j]; + int c = desc[j]; if (c >= '0' && c <= '9') continue; if (c >= 'A' && c <= 'F') continue; if (c >= 'a' && c <= 'f') continue; return "Not enough hex digits at start of string"; - /* NB if seed[j]=='\0' that will also be caught here, so we're safe */ + /* NB if desc[j]=='\0' that will also be caught here, so we're safe */ } - if (seed[i] != ',') + if (desc[i] != ',') return "Expected ',' after hex digits"; i++; do { - if (seed[i] < '0' || seed[i] > '9') + if (desc[i] < '0' || desc[i] > '9') return "Expected decimal integer after ','"; i++; - } while (seed[i]); + } while (desc[i]); return NULL; } -static game_state *new_game(game_params *params, char *seed) +static game_state *new_game(game_params *params, char *desc) { game_state *state = snew(game_state); int area; @@ -891,10 +887,10 @@ static game_state *new_game(game_params *params, char *seed) /* * Set up the blue squares and polyhedron position according to - * the game seed. + * the game description. */ { - char *p = seed; + char *p = desc; int i, j, v; j = 8; @@ -961,6 +957,7 @@ static game_state *dup_game(game_state *state) memcpy(ret->facecolours, state->facecolours, ret->solid->nfaces * sizeof(int)); ret->nsquares = state->nsquares; + ret->current = state->current; ret->squares = snewn(ret->nsquares, struct grid_square); memcpy(ret->squares, state->squares, ret->nsquares * sizeof(struct grid_square)); @@ -985,6 +982,12 @@ static void free_game(game_state *state) sfree(state); } +static game_state *solve_game(game_state *state, game_aux_info *aux, + char **error) +{ + return NULL; +} + static char *game_text_format(game_state *state) { return NULL; @@ -1011,23 +1014,23 @@ static game_state *make_move(game_state *from, game_ui *ui, struct solid *poly; /* - * All moves are made with the cursor keys. + * All moves are made with the cursor keys or numeric keypad. */ - if (button == CURSOR_UP) + if (button == CURSOR_UP || button == (MOD_NUM_KEYPAD | '8')) direction = UP; - else if (button == CURSOR_DOWN) + else if (button == CURSOR_DOWN || button == (MOD_NUM_KEYPAD | '2')) direction = DOWN; - else if (button == CURSOR_LEFT) + else if (button == CURSOR_LEFT || button == (MOD_NUM_KEYPAD | '4')) direction = LEFT; - else if (button == CURSOR_RIGHT) + else if (button == CURSOR_RIGHT || button == (MOD_NUM_KEYPAD | '6')) direction = RIGHT; - else if (button == CURSOR_UP_LEFT) + else if (button == (MOD_NUM_KEYPAD | '7')) direction = UP_LEFT; - else if (button == CURSOR_DOWN_LEFT) + else if (button == (MOD_NUM_KEYPAD | '1')) direction = DOWN_LEFT; - else if (button == CURSOR_UP_RIGHT) + else if (button == (MOD_NUM_KEYPAD | '9')) direction = UP_RIGHT; - else if (button == CURSOR_DOWN_RIGHT) + else if (button == (MOD_NUM_KEYPAD | '3')) direction = DOWN_RIGHT; else return NULL; @@ -1551,13 +1554,14 @@ const struct game thegame = { dup_params, TRUE, game_configure, custom_params, validate_params, - new_game_seed, + new_game_desc, game_free_aux_info, - validate_seed, + validate_desc, new_game, dup_game, free_game, - NULL, game_text_format, + FALSE, solve_game, + FALSE, game_text_format, new_ui, free_ui, make_move,