aboutsummaryrefslogtreecommitdiff
path: root/cube.c
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2004-05-03 08:51:31 +0000
committerSimon Tatham <anakin@pobox.com>2004-05-03 08:51:31 +0000
commit6e42ddd31b5ca71f48c6260b01fc49b2451d0a56 (patch)
treedce426839c0855f7726366e51034282538819ff7 /cube.c
parenteb88ee0973c9a19b14e2e0e1579ee17625d73e05 (diff)
downloadpuzzles-6e42ddd31b5ca71f48c6260b01fc49b2451d0a56.zip
puzzles-6e42ddd31b5ca71f48c6260b01fc49b2451d0a56.tar.gz
puzzles-6e42ddd31b5ca71f48c6260b01fc49b2451d0a56.tar.bz2
puzzles-6e42ddd31b5ca71f48c6260b01fc49b2451d0a56.tar.xz
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]
Diffstat (limited to 'cube.c')
-rw-r--r--cube.c32
1 files changed, 30 insertions, 2 deletions
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);