From e3c9e042f1dcd2ee2a643bb5b13f15b092185a73 Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 18 Sep 2008 18:19:55 +0000 Subject: [PATCH] Lambros points out that trying to generate a 3x3 Cairo Easy grid spins forever, but observes that raising the limit to 4x4 across all grid types is not good for the complex grids like great-hexagonal. Introduce per-grid minimum sizes using mad macro trickery. (In fact, for each grid type I've put in a minimum size which _both_ dimensions must equal or exceed, plus another minimum size which _at least one_ must equal or exceed; that permits both 3x4 and 4x3 Cairo while disallowing 3x3.) git-svn-id: svn://svn.tartarus.org/sgt/puzzles@8191 cda61777-01e9-0310-a592-d414129be87e --- loopy.c | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/loopy.c b/loopy.c index 33aff51..0cb6921 100644 --- a/loopy.c +++ b/loopy.c @@ -228,22 +228,30 @@ static void check_caches(const solver_state* sstate); /* ------- List of grid generators ------- */ #define GRIDLIST(A) \ - A(Squares,grid_new_square) \ - A(Triangular,grid_new_triangular) \ - A(Honeycomb,grid_new_honeycomb) \ - A(Snub-Square,grid_new_snubsquare) \ - A(Cairo,grid_new_cairo) \ - A(Great-Hexagonal,grid_new_greathexagonal) \ - A(Octagonal,grid_new_octagonal) \ - A(Kites,grid_new_kites) - -#define GRID_NAME(title,fn) #title, -#define GRID_CONFIG(title,fn) ":" #title -#define GRID_FN(title,fn) &fn, + A(Squares,grid_new_square,3,3) \ + A(Triangular,grid_new_triangular,3,3) \ + A(Honeycomb,grid_new_honeycomb,3,3) \ + A(Snub-Square,grid_new_snubsquare,3,3) \ + A(Cairo,grid_new_cairo,3,4) \ + A(Great-Hexagonal,grid_new_greathexagonal,3,3) \ + A(Octagonal,grid_new_octagonal,3,3) \ + A(Kites,grid_new_kites,3,3) + +#define GRID_NAME(title,fn,amin,omin) #title, +#define GRID_CONFIG(title,fn,amin,omin) ":" #title +#define GRID_FN(title,fn,amin,omin) &fn, +#define GRID_SIZES(title,fn,amin,omin) \ + {amin, omin, \ + "Width and height for this grid type must both be at least " #amin, \ + "At least one of width and height for this grid type must be at least " #omin,}, static char const *const gridnames[] = { GRIDLIST(GRID_NAME) }; #define GRID_CONFIGS GRIDLIST(GRID_CONFIG) static grid * (*(grid_fns[]))(int w, int h) = { GRIDLIST(GRID_FN) }; #define NUM_GRID_TYPES (sizeof(grid_fns) / sizeof(grid_fns[0])) +static const struct { + int amin, omin; + char *aerr, *oerr; +} grid_size_limits[] = { GRIDLIST(GRID_SIZES) }; /* Generates a (dynamically allocated) new grid, according to the * type and size requested in params. Does nothing if the grid is already @@ -619,10 +627,14 @@ static game_params *custom_params(config_item *cfg) static char *validate_params(game_params *params, int full) { - if (params->w < 3 || params->h < 3) - return "Width and height must both be at least 3"; if (params->type < 0 || params->type >= NUM_GRID_TYPES) return "Illegal grid type"; + if (params->w < grid_size_limits[params->type].amin || + params->h < grid_size_limits[params->type].amin) + return grid_size_limits[params->type].aerr; + if (params->w < grid_size_limits[params->type].omin && + params->h < grid_size_limits[params->type].omin) + return grid_size_limits[params->type].oerr; /* * This shouldn't be able to happen at all, since decode_params -- 2.11.0