X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/puzzles/blobdiff_plain/149255d7ed0f808783624fcaaf8c3449cf99c851..a4427d1992334226166b12626c2ec196e08a25b6:/unequal.c diff --git a/unequal.c b/unequal.c index 74eba79..c805975 100644 --- a/unequal.c +++ b/unequal.c @@ -631,7 +631,7 @@ static int solver_grid(digit *grid, int o, int maxdiff, void *ctx) game_solver *solver; struct latin_solver *lsolver; struct latin_solver_scratch *scratch; - int ret, diff = DIFF_LATIN, extreme; + int ret, diff = DIFF_LATIN; assert(maxdiff <= DIFF_RECURSIVE); @@ -668,18 +668,28 @@ cont: if (maxdiff <= DIFF_EASY) break; - ret = latin_solver_diff_set(lsolver, scratch, &extreme); + /* Row- and column-wise set elimination */ + ret = latin_solver_diff_set(lsolver, scratch, 0); if (ret < 0) { diff = DIFF_IMPOSSIBLE; goto got_result; } else if (ret > 0) { - diff = max(diff, extreme ? DIFF_EXTREME : DIFF_SET); + diff = max(diff, DIFF_SET); goto cont; } if (maxdiff <= DIFF_SET) break; + ret = latin_solver_diff_set(lsolver, scratch, 1); + if (ret < 0) { + diff = DIFF_IMPOSSIBLE; + goto got_result; + } else if (ret > 0) { + diff = max(diff, DIFF_EXTREME); + goto cont; + } + /* * Forcing chains. */ @@ -870,7 +880,7 @@ static int gg_best_clue(game_state *state, int *scratch, digit *latin) } #endif - for (i = 0; i < ls; i++) { + for (i = ls; i-- > 0 ;) { if (!gg_place_clue(state, scratch[i], latin, 1)) continue; loc = scratch[i] / 5; @@ -961,7 +971,8 @@ static void game_strip(game_state *new, int *scratch, digit *latin, gg_solved++; if (solver_state(copy, difficulty) != 1) { /* put clue back, we can't solve without it. */ - assert(gg_place_clue(new, scratch[i], latin, 0) == 1); + int ret = gg_place_clue(new, scratch[i], latin, 0); + assert(ret == 1); } else { #ifdef STANDALONE_SOLVER if (solver_show_working) @@ -992,7 +1003,8 @@ static char *new_game_desc(game_params *params, random_state *rs, /* Generate a list of 'things to strip' (randomised later) */ scratch = snewn(lscratch, int); - for (i = 0; i < lscratch; i++) scratch[i] = i; + /* Put the numbers (4 mod 5) before the inequalities (0-3 mod 5) */ + for (i = 0; i < lscratch; i++) scratch[i] = (i%o2)*5 + 4 - (i/o2); generate: #ifdef STANDALONE_SOLVER @@ -1003,7 +1015,9 @@ generate: if (sq) sfree(sq); sq = latin_generate(params->order, rs); latin_debug(sq, params->order); - shuffle(scratch, lscratch, sizeof(int), rs); + /* Separately shuffle the numeric and inequality clues */ + shuffle(scratch, lscratch/5, sizeof(int), rs); + shuffle(scratch+lscratch/5, 4*lscratch/5, sizeof(int), rs); memset(state->nums, 0, o2 * sizeof(digit)); memset(state->flags, 0, o2 * sizeof(unsigned int)); @@ -1309,7 +1323,7 @@ static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds, static game_state *execute_move(game_state *state, char *move) { game_state *ret = NULL; - int x, y, n, i; + int x, y, n, i, rc; debug(("execute_move: %s", move)); @@ -1345,7 +1359,8 @@ static game_state *execute_move(game_state *state, char *move) p++; } if (*p) goto badmove; - assert(check_complete(ret->nums, ret, 1) > 0); + rc = check_complete(ret->nums, ret, 1); + assert(rc > 0); return ret; } else if (move[0] == 'H') { return solver_hint(state, NULL, DIFF_EASY, DIFF_EASY); @@ -1738,7 +1753,7 @@ const struct game thegame = { TRUE, FALSE, game_print_size, game_print, FALSE, /* wants_statusbar */ FALSE, game_timing_state, - 0, /* flags */ + REQUIRE_RBUTTON | REQUIRE_NUMPAD, /* flags */ }; /* ----------------------------------------------------------------------