aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2020-05-23 10:03:57 +0100
committerSimon Tatham <anakin@pobox.com>2020-05-23 10:03:57 +0100
commitf2aeda71840ff95371e610b0b6b7371f26351a11 (patch)
tree354349ec8ace09ec03bf268efcd16864a65e9264
parent8110518c33c73ab88838bd537fa085e29b1f7c13 (diff)
downloadpuzzles-f2aeda71840ff95371e610b0b6b7371f26351a11.zip
puzzles-f2aeda71840ff95371e610b0b6b7371f26351a11.tar.gz
puzzles-f2aeda71840ff95371e610b0b6b7371f26351a11.tar.bz2
puzzles-f2aeda71840ff95371e610b0b6b7371f26351a11.tar.xz
Towers: fill in the latin.c validator function.
Again, this seems to have made no difference in a test generation run with the command "towers --generate 100 6du#12345".
-rw-r--r--towers.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/towers.c b/towers.c
index 27d8751..aee088f 100644
--- a/towers.c
+++ b/towers.c
@@ -574,9 +574,36 @@ static int solver_hard(struct latin_solver *solver, void *vctx)
#define SOLVER(upper,title,func,lower) func,
static usersolver_t const towers_solvers[] = { DIFFLIST(SOLVER) };
-static bool towers_valid(struct latin_solver *solver, void *ctx)
+static bool towers_valid(struct latin_solver *solver, void *vctx)
{
- return true; /* FIXME */
+ struct solver_ctx *ctx = (struct solver_ctx *)vctx;
+ int w = ctx->w;
+ int c, i, n, best, clue, start, step;
+ for (c = 0; c < 4*w; c++) {
+ clue = ctx->clues[c];
+ if (!clue)
+ continue;
+
+ STARTSTEP(start, step, c, w);
+ n = best = 0;
+ for (i = 0; i < w; i++) {
+ if (solver->grid[start+i*step] > best) {
+ best = solver->grid[start+i*step];
+ n++;
+ }
+ }
+
+ if (n != clue) {
+#ifdef STANDALONE_SOLVER
+ if (solver_show_working)
+ printf("%*sclue %s %d is violated\n",
+ solver_recurse_depth*4, "",
+ cluepos[c/w], c%w+1);
+#endif
+ return false;
+ }
+ }
+ return true;
}
static int solver(int w, int *clues, digit *soln, int maxdiff)