aboutsummaryrefslogtreecommitdiff
path: root/unfinished
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2023-02-05 10:29:42 +0000
committerSimon Tatham <anakin@pobox.com>2023-02-05 10:41:17 +0000
commit5030d87903191d581586ecda2382ad5bcd70f63d (patch)
tree16723a72976b9b1699b923d1c991e8cf7b9f9eec /unfinished
parent517b14e666b0b71fc0bcd5da1b22cdc90d3434c9 (diff)
downloadpuzzles-5030d87903191d581586ecda2382ad5bcd70f63d.zip
puzzles-5030d87903191d581586ecda2382ad5bcd70f63d.tar.gz
puzzles-5030d87903191d581586ecda2382ad5bcd70f63d.tar.bz2
puzzles-5030d87903191d581586ecda2382ad5bcd70f63d.tar.xz
latin_solver_alloc: handle clashing numbers in input grid.
In the setup phase of the centralised latin.c solver, we start by going over the input grid containing already-placed clue numbers, and calling latin_solver_place to enter each on into the solver's data structure. This has the side effect of ruling out each number from the rest of the row and column, and _also_ checking by assertion that the number being placed is not ruled out. Those are a bad combination, because it means that if you give an obviously inconsistent input grid to latin_solver_alloc (e.g. with two identical numbers in a row already), it will fail an assertion. In that situation, you want the solver run as a whole to return diff_impossible so that the error is reported cleanly. This assertion failure could be provoked by giving either Towers or Group a manually-constructed game description inconsistent in that way, and hitting Solve. Worse, it could be provoked during live play in Unequal, by filling in a number clashing with a clue and then pressing 'h' to get hints.
Diffstat (limited to 'unfinished')
-rw-r--r--unfinished/group.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/unfinished/group.c b/unfinished/group.c
index e72e3ce..2eca7c4 100644
--- a/unfinished/group.c
+++ b/unfinished/group.c
@@ -580,13 +580,11 @@ static int solver(const game_params *params, digit *grid, int maxdiff)
int w = params->w;
int ret;
struct latin_solver solver;
+
#ifdef STANDALONE_SOLVER
char *p, text[100], *names[50];
int i;
-#endif
- latin_solver_alloc(&solver, grid, w);
-#ifdef STANDALONE_SOLVER
for (i = 0, p = text; i < w; i++) {
names[i] = p;
*p++ = TOCHAR(i+1, params->id);
@@ -595,10 +593,13 @@ static int solver(const game_params *params, digit *grid, int maxdiff)
solver.names = names;
#endif
- ret = latin_solver_main(&solver, maxdiff,
- DIFF_TRIVIAL, DIFF_HARD, DIFF_EXTREME,
- DIFF_EXTREME, DIFF_UNREASONABLE,
- group_solvers, group_valid, NULL, NULL, NULL);
+ if (latin_solver_alloc(&solver, grid, w))
+ ret = latin_solver_main(&solver, maxdiff,
+ DIFF_TRIVIAL, DIFF_HARD, DIFF_EXTREME,
+ DIFF_EXTREME, DIFF_UNREASONABLE,
+ group_solvers, group_valid, NULL, NULL, NULL);
+ else
+ ret = diff_impossible;
latin_solver_free(&solver);