From 6e42ddd31b5ca71f48c6260b01fc49b2451d0a56 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Mon, 3 May 2004 08:51:31 +0000 Subject: Implement selection of game seeds, by reusing the config box mechanism I've just invented (the midend handles the standard game selection configuration). Each game is now required to validate its own seed data before attempting to base a game on it and potentially confusing itself. [originally from svn r4186] --- cube.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'cube.c') diff --git a/cube.c b/cube.c index c867471..6c2658f 100644 --- a/cube.c +++ b/cube.c @@ -285,8 +285,8 @@ static void enum_grid_squares(game_params *params, if (solid->order == 4) { int x, y; - for (x = 0; x < params->d1; x++) - for (y = 0; y < params->d2; y++) { + for (y = 0; y < params->d2; y++) + for (x = 0; x < params->d1; x++) { struct grid_square sq; sq.x = (float)x; @@ -809,6 +809,34 @@ static struct solid *transform_poly(const struct solid *solid, int flip, return ret; } +char *validate_seed(game_params *params, char *seed) +{ + 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]; + 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 */ + } + + if (seed[i] != ':') + return "Expected ':' after hex digits"; + + i++; + do { + if (seed[i] < '0' || seed[i] > '9') + return "Expected decimal integer after ':'"; + i++; + } while (seed[i]); + + return NULL; +} + game_state *new_game(game_params *params, char *seed) { game_state *state = snew(game_state); -- cgit v1.1