Apply "103_fix-unequal-digit-h.diff" from the Debian package:
[sgt/puzzles] / unequal.c
index 8006ea1..20fc2d2 100644 (file)
--- a/unequal.c
+++ b/unequal.c
 #include "puzzles.h"
 #include "latin.h" /* contains typedef for digit */
 
-static void assert_f(p)
-{
-    assert(p);
-}
-
 /* ----------------------------------------------------------
  * Constant and structure definitions
  */
@@ -413,6 +408,11 @@ static int c2n(int c, int order) {
     return -1;
 }
 
+static int game_can_format_as_text_now(game_params *params)
+{
+    return TRUE;
+}
+
 static char *game_text_format(game_state *state)
 {
     int x, y, len, n;
@@ -885,7 +885,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;
@@ -901,7 +901,7 @@ static int gg_best_clue(game_state *state, int *scratch, digit *latin)
             best = i; maxposs = nposs; minclues = nclues;
 #ifdef STANDALONE_SOLVER
             if (solver_show_working)
-                printf("gg_best_clue: b%d (%d,%d) new best [%d poss, %d clues].",
+                printf("gg_best_clue: b%d (%d,%d) new best [%d poss, %d clues].\n",
                        best, x, y, nposs, nclues);
 #endif
         }
@@ -976,7 +976,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_f(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)
@@ -1000,14 +1001,15 @@ static char *new_game_desc(game_params *params, random_state *rs,
 {
     digit *sq = NULL;
     int i, x, y, retlen, k, nsol;
-    int o2 = params->order * params->order, ntries = 0;
+    int o2 = params->order * params->order, ntries = 1;
     int *scratch, lscratch = o2*5;
     char *ret, buf[80];
     game_state *state = blank_game(params->order);
 
     /* 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
@@ -1018,7 +1020,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));
@@ -1035,7 +1039,7 @@ generate:
         if (nsol > 0) {
 #ifdef STANDALONE_SOLVER
             if (solver_show_working)
-                printf("game_assemble: puzzle as generated is too easy.");
+                printf("game_assemble: puzzle as generated is too easy.\n");
 #endif
             if (ntries < MAXTRIES) {
                 ntries++;
@@ -1043,7 +1047,7 @@ generate:
             }
 #ifdef STANDALONE_SOLVER
             if (solver_show_working)
-                printf("Unable to generate %s %dx%d after %d attempts.",
+                printf("Unable to generate %s %dx%d after %d attempts.\n",
                        unequal_diffnames[params->diff],
                        params->order, params->order, MAXTRIES);
 #endif
@@ -1052,7 +1056,7 @@ generate:
     }
 #ifdef STANDALONE_SOLVER
     if (solver_show_working)
-        printf("new_game_desc: generated %s puzzle; %d attempts (%d solver).",
+        printf("new_game_desc: generated %s puzzle; %d attempts (%d solver).\n",
                unequal_diffnames[params->diff], ntries, gg_solved);
 #endif
 
@@ -1267,7 +1271,8 @@ static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
 
     button &= ~MOD_MASK;
 
-    if (x >= 0 && x < ds->order && y >= 0 && y < ds->order) {
+    if (x >= 0 && x < ds->order && ((ox - COORD(x)) <= TILE_SIZE) &&
+        y >= 0 && y < ds->order && ((oy - COORD(y)) <= TILE_SIZE)) {
         if (button == LEFT_BUTTON) {
             /* normal highlighting for non-immutable squares */
             if (GRID(state, flags, x, y) & F_IMMUTABLE)
@@ -1291,8 +1296,6 @@ static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
             return "";
         }
     }
-    if (button == 'H' || button == 'h')
-        return dupstr("H");
 
     if (ui->hx != -1 && ui->hy != -1) {
         debug(("button %d, cbutton %d", button, (int)((char)button)));
@@ -1318,13 +1321,17 @@ static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
 
         return dupstr(buf);
     }
+
+    if (button == 'H' || button == 'h')
+        return dupstr("H");
+
     return NULL;
 }
 
 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));
 
@@ -1360,7 +1367,8 @@ static game_state *execute_move(game_state *state, char *move)
             p++;
         }
         if (*p) goto badmove;
-       assert_f(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);
@@ -1735,7 +1743,7 @@ const struct game thegame = {
     dup_game,
     free_game,
     TRUE, solve_game,
-    TRUE, game_text_format,
+    TRUE, game_can_format_as_text_now, game_text_format,
     new_ui,
     free_ui,
     encode_ui,