In the Windows frontend, stop tab navigation from activating buttons.
[sgt/puzzles] / rect.c
diff --git a/rect.c b/rect.c
index 62b678e..1fe873b 100644 (file)
--- a/rect.c
+++ b/rect.c
@@ -60,7 +60,11 @@ struct game_params {
 
 #define PREFERRED_TILE_SIZE 24
 #define TILE_SIZE (ds->tilesize)
+#ifdef SMALL_SCREEN
+#define BORDER (2)
+#else
 #define BORDER (TILE_SIZE * 3 / 4)
+#endif
 
 #define CORNER_TOLERANCE 0.15F
 #define CENTRE_TOLERANCE 0.15F
@@ -102,8 +106,10 @@ static int game_fetch_preset(int i, char **name, game_params **params)
       case 2: w = 11, h = 11; break;
       case 3: w = 13, h = 13; break;
       case 4: w = 15, h = 15; break;
+#ifndef SMALL_SCREEN
       case 5: w = 17, h = 17; break;
       case 6: w = 19, h = 19; break;
+#endif
       default: return FALSE;
     }
 
@@ -323,6 +329,11 @@ static void remove_number_placement(int w, int h, struct numberdata *number,
     number->npoints--;
 }
 
+/*
+ * Returns 0 for failure to solve due to inconsistency; 1 for
+ * success; 2 for failure to complete a solution due to either
+ * ambiguity or it being too difficult.
+ */
 static int rect_solver(int w, int h, int nrects, struct numberdata *numbers,
                        unsigned char *hedge, unsigned char *vedge,
                       random_state *rs)
@@ -428,6 +439,14 @@ static int rect_solver(int w, int h, int nrects, struct numberdata *numbers,
      * Indexing of this array is by the formula
      * 
      *   overlaps[(rectindex * h + y) * w + x]
+     * 
+     * A positive or zero value indicates what it sounds as if it
+     * should; -1 indicates that this square _cannot_ be part of
+     * this rectangle; and -2 indicates that it _definitely_ is
+     * (which is distinct from 1, because one might very well know
+     * that _if_ square S is part of rectangle R then it must be
+     * because R is placed in a certain position without knowing
+     * that it definitely _is_).
      */
     overlaps = snewn(nrects * w * h, int);
     memset(overlaps, 0, nrects * w * h * sizeof(int));
@@ -520,7 +539,10 @@ static int rect_solver(int w, int h, int nrects, struct numberdata *numbers,
                 if (overlaps[(i * h + y) * w + x] >= -1) {
                     int j;
 
-                    assert(overlaps[(i * h + y) * w + x] > 0);
+                    if (overlaps[(i * h + y) * w + x] <= 0) {
+                        ret = 0;       /* inconsistency */
+                        goto cleanup;
+                    }
 #ifdef SOLVER_DIAGNOSTICS
                     printf("marking %d,%d as known for rect %d"
                            " (sole remaining number position)\n", x, y, i);
@@ -562,7 +584,10 @@ static int rect_solver(int w, int h, int nrects, struct numberdata *numbers,
             for (yy = miny; yy < maxy; yy++)
                 for (xx = minx; xx < maxx; xx++)
                     if (overlaps[(i * h + yy) * w + xx] >= -1) {
-                        assert(overlaps[(i * h + yy) * w + xx] > 0);
+                        if (overlaps[(i * h + yy) * w + xx] <= 0) {
+                            ret = 0;   /* inconsistency */
+                            goto cleanup;
+                        }
 #ifdef SOLVER_DIAGNOSTICS
                         printf("marking %d,%d as known for rect %d"
                                " (intersection of all placements)\n",
@@ -841,15 +866,17 @@ static int rect_solver(int w, int h, int nrects, struct numberdata *numbers,
         }
     }
 
-    ret = TRUE;
+    cleanup:
+    ret = 1;
     for (i = 0; i < nrects; i++) {
 #ifdef SOLVER_DIAGNOSTICS
         printf("rect %d has %d possible placements\n",
                i, rectpositions[i].n);
 #endif
-        assert(rectpositions[i].n > 0);
-        if (rectpositions[i].n > 1) {
-            ret = FALSE;
+        if (rectpositions[i].n <= 0) {
+            ret = 0;                   /* inconsistency */
+        } else if (rectpositions[i].n > 1) {
+            ret = 2;                   /* remaining uncertainty */
         } else if (hedge && vedge) {
             /*
              * Place the rectangle in its only possible position.
@@ -1633,9 +1660,9 @@ static char *new_game_desc(game_params *params, random_state *rs,
                ret = rect_solver(params->w, params->h, nnumbers, nd,
                                  NULL, NULL, rs);
            else
-               ret = TRUE;            /* allow any number placement at all */
+               ret = 1;               /* allow any number placement at all */
 
-            if (ret) {
+            if (ret == 1) {
                 /*
                  * Now place the numbers according to the solver's
                  * recommendations.
@@ -1665,7 +1692,7 @@ static char *new_game_desc(game_params *params, random_state *rs,
             /*
              * If we've succeeded, then terminate the loop.
              */
-            if (ret)
+            if (ret == 1)
                 break;
         }
 
@@ -2761,11 +2788,6 @@ static float game_flash_length(game_state *oldstate,
     return 0.0F;
 }
 
-static int game_wants_statusbar(void)
-{
-    return TRUE;
-}
-
 static int game_timing_state(game_state *state, game_ui *ui)
 {
     return TRUE;
@@ -2841,7 +2863,7 @@ static void game_print(drawing *dr, game_state *state, int tilesize)
 #endif
 
 const struct game thegame = {
-    "Rectangles", "games.rectangles",
+    "Rectangles", "games.rectangles", "rectangles",
     default_params,
     game_fetch_preset,
     decode_params,
@@ -2872,7 +2894,7 @@ const struct game thegame = {
     game_anim_length,
     game_flash_length,
     TRUE, FALSE, game_print_size, game_print,
-    game_wants_statusbar,
+    TRUE,                             /* wants_statusbar */
     FALSE, game_timing_state,
     0,                                /* flags */
 };