summaryrefslogtreecommitdiff
path: root/apps/plugins/puzzles/src/unequal.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/puzzles/src/unequal.c')
-rw-r--r--apps/plugins/puzzles/src/unequal.c74
1 files changed, 72 insertions, 2 deletions
diff --git a/apps/plugins/puzzles/src/unequal.c b/apps/plugins/puzzles/src/unequal.c
index 951e9ac80f..556cf01c45 100644
--- a/apps/plugins/puzzles/src/unequal.c
+++ b/apps/plugins/puzzles/src/unequal.c
@@ -816,6 +816,74 @@ static int solver_set(struct latin_solver *solver, void *vctx)
816#define SOLVER(upper,title,func,lower) func, 816#define SOLVER(upper,title,func,lower) func,
817static usersolver_t const unequal_solvers[] = { DIFFLIST(SOLVER) }; 817static usersolver_t const unequal_solvers[] = { DIFFLIST(SOLVER) };
818 818
819static bool unequal_valid(struct latin_solver *solver, void *vctx)
820{
821 struct solver_ctx *ctx = (struct solver_ctx *)vctx;
822 if (ctx->state->mode == MODE_ADJACENT) {
823 int o = solver->o;
824 int x, y, nx, ny, v, nv, i;
825
826 for (x = 0; x+1 < o; x++) {
827 for (y = 0; y+1 < o; y++) {
828 v = grid(x, y);
829 for (i = 0; i < 4; i++) {
830 bool is_adj, should_be_adj;
831
832 should_be_adj =
833 (GRID(ctx->state, flags, x, y) & adjthan[i].f);
834
835 nx = x + adjthan[i].dx, ny = y + adjthan[i].dy;
836 if (nx < 0 || ny < 0 || nx >= o || ny >= o)
837 continue;
838
839 nv = grid(nx, ny);
840 is_adj = (labs(v - nv) == 1);
841
842 if (is_adj && !should_be_adj) {
843#ifdef STANDALONE_SOLVER
844 if (solver_show_working)
845 printf("%*s(%d,%d):%d and (%d,%d):%d have "
846 "adjacent values, but should not\n",
847 solver_recurse_depth*4, "",
848 x+1, y+1, v, nx+1, ny+1, nv);
849#endif
850 return false;
851 }
852
853 if (!is_adj && should_be_adj) {
854#ifdef STANDALONE_SOLVER
855 if (solver_show_working)
856 printf("%*s(%d,%d):%d and (%d,%d):%d do not have "
857 "adjacent values, but should\n",
858 solver_recurse_depth*4, "",
859 x+1, y+1, v, nx+1, ny+1, nv);
860#endif
861 return false;
862 }
863 }
864 }
865 }
866 } else {
867 int i;
868 for (i = 0; i < ctx->nlinks; i++) {
869 struct solver_link *link = &ctx->links[i];
870 int gv = grid(link->gx, link->gy);
871 int lv = grid(link->lx, link->ly);
872 if (gv <= lv) {
873#ifdef STANDALONE_SOLVER
874 if (solver_show_working)
875 printf("%*s(%d,%d):%d should be greater than (%d,%d):%d, "
876 "but is not\n", solver_recurse_depth*4, "",
877 link->gx+1, link->gy+1, gv,
878 link->lx+1, link->ly+1, lv);
879#endif
880 return false;
881 }
882 }
883 }
884 return true;
885}
886
819static int solver_state(game_state *state, int maxdiff) 887static int solver_state(game_state *state, int maxdiff)
820{ 888{
821 struct solver_ctx *ctx = new_ctx(state); 889 struct solver_ctx *ctx = new_ctx(state);
@@ -827,7 +895,8 @@ static int solver_state(game_state *state, int maxdiff)
827 diff = latin_solver_main(&solver, maxdiff, 895 diff = latin_solver_main(&solver, maxdiff,
828 DIFF_LATIN, DIFF_SET, DIFF_EXTREME, 896 DIFF_LATIN, DIFF_SET, DIFF_EXTREME,
829 DIFF_EXTREME, DIFF_RECURSIVE, 897 DIFF_EXTREME, DIFF_RECURSIVE,
830 unequal_solvers, ctx, clone_ctx, free_ctx); 898 unequal_solvers, unequal_valid, ctx,
899 clone_ctx, free_ctx);
831 900
832 memcpy(state->hints, solver.cube, state->order*state->order*state->order); 901 memcpy(state->hints, solver.cube, state->order*state->order*state->order);
833 902
@@ -2155,7 +2224,8 @@ static int solve(game_params *p, char *desc, int debug)
2155 diff = latin_solver_main(&solver, DIFF_RECURSIVE, 2224 diff = latin_solver_main(&solver, DIFF_RECURSIVE,
2156 DIFF_LATIN, DIFF_SET, DIFF_EXTREME, 2225 DIFF_LATIN, DIFF_SET, DIFF_EXTREME,
2157 DIFF_EXTREME, DIFF_RECURSIVE, 2226 DIFF_EXTREME, DIFF_RECURSIVE,
2158 unequal_solvers, ctx, clone_ctx, free_ctx); 2227 unequal_solvers, unequal_valid, ctx,
2228 clone_ctx, free_ctx);
2159 2229
2160 free_ctx(ctx); 2230 free_ctx(ctx);
2161 2231