diff options
Diffstat (limited to 'apps/plugins/puzzles/src/towers.c')
-rw-r--r-- | apps/plugins/puzzles/src/towers.c | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/apps/plugins/puzzles/src/towers.c b/apps/plugins/puzzles/src/towers.c index a72cae680d..aee088fb54 100644 --- a/apps/plugins/puzzles/src/towers.c +++ b/apps/plugins/puzzles/src/towers.c | |||
@@ -574,6 +574,38 @@ static int solver_hard(struct latin_solver *solver, void *vctx) | |||
574 | #define SOLVER(upper,title,func,lower) func, | 574 | #define SOLVER(upper,title,func,lower) func, |
575 | static usersolver_t const towers_solvers[] = { DIFFLIST(SOLVER) }; | 575 | static usersolver_t const towers_solvers[] = { DIFFLIST(SOLVER) }; |
576 | 576 | ||
577 | static bool towers_valid(struct latin_solver *solver, void *vctx) | ||
578 | { | ||
579 | struct solver_ctx *ctx = (struct solver_ctx *)vctx; | ||
580 | int w = ctx->w; | ||
581 | int c, i, n, best, clue, start, step; | ||
582 | for (c = 0; c < 4*w; c++) { | ||
583 | clue = ctx->clues[c]; | ||
584 | if (!clue) | ||
585 | continue; | ||
586 | |||
587 | STARTSTEP(start, step, c, w); | ||
588 | n = best = 0; | ||
589 | for (i = 0; i < w; i++) { | ||
590 | if (solver->grid[start+i*step] > best) { | ||
591 | best = solver->grid[start+i*step]; | ||
592 | n++; | ||
593 | } | ||
594 | } | ||
595 | |||
596 | if (n != clue) { | ||
597 | #ifdef STANDALONE_SOLVER | ||
598 | if (solver_show_working) | ||
599 | printf("%*sclue %s %d is violated\n", | ||
600 | solver_recurse_depth*4, "", | ||
601 | cluepos[c/w], c%w+1); | ||
602 | #endif | ||
603 | return false; | ||
604 | } | ||
605 | } | ||
606 | return true; | ||
607 | } | ||
608 | |||
577 | static int solver(int w, int *clues, digit *soln, int maxdiff) | 609 | static int solver(int w, int *clues, digit *soln, int maxdiff) |
578 | { | 610 | { |
579 | int ret; | 611 | int ret; |
@@ -589,7 +621,7 @@ static int solver(int w, int *clues, digit *soln, int maxdiff) | |||
589 | ret = latin_solver(soln, w, maxdiff, | 621 | ret = latin_solver(soln, w, maxdiff, |
590 | DIFF_EASY, DIFF_HARD, DIFF_EXTREME, | 622 | DIFF_EASY, DIFF_HARD, DIFF_EXTREME, |
591 | DIFF_EXTREME, DIFF_UNREASONABLE, | 623 | DIFF_EXTREME, DIFF_UNREASONABLE, |
592 | towers_solvers, &ctx, NULL, NULL); | 624 | towers_solvers, towers_valid, &ctx, NULL, NULL); |
593 | 625 | ||
594 | sfree(ctx.iscratch); | 626 | sfree(ctx.iscratch); |
595 | sfree(ctx.dscratch); | 627 | sfree(ctx.dscratch); |