shithub: puzzles

Download patch

ref: f3ba6f8bcefde0ff75971e662841ecef6be56b5a
parent: 862e25c90b8f62fd1cab270b13f5d57f86bff82f
author: Simon Tatham <anakin@pobox.com>
date: Sat May 21 09:39:23 EDT 2005

Cleanups:
 - fix documentation of Net's unique solution option (should have
   tested before last checkin)
 - make unique solutions optional in Rectangles too (same reasons)
 - tidy up various issues in parameter encoding in both games.

[originally from svn r5818]

--- a/net.c
+++ b/net.c
@@ -201,11 +201,11 @@
     char const *p = string;
 
     ret->width = atoi(p);
-    while (*p && isdigit(*p)) p++;
+    while (*p && isdigit((unsigned char)*p)) p++;
     if (*p == 'x') {
         p++;
         ret->height = atoi(p);
-        while (*p && isdigit(*p)) p++;
+        while (*p && isdigit((unsigned char)*p)) p++;
     } else {
         ret->height = ret->width;
     }
@@ -217,11 +217,12 @@
 	} else if (*p == 'b') {
 	    p++;
             ret->barrier_probability = atof(p);
-	    while (*p && isdigit(*p)) p++;
+	    while (*p && (*p == '.' || isdigit((unsigned char)*p))) p++;
 	} else if (*p == 'a') {
             p++;
 	    ret->unique = FALSE;
-	}
+	} else
+	    p++;		       /* skip any other gunk */
     }
 }
 
@@ -235,7 +236,7 @@
         ret[len++] = 'w';
     if (full && params->barrier_probability)
         len += sprintf(ret+len, "b%g", params->barrier_probability);
-    if (!params->unique)
+    if (full && !params->unique)
         ret[len++] = 'a';
     assert(len < lenof(ret));
     ret[len] = '\0';
--- a/puzzles.but
+++ b/puzzles.but
@@ -346,15 +346,6 @@
 higher number gives more barriers). Since barriers are immovable, they
 act as constraints on the solution (i.e., hints).
 
-\dt \e{Ensure unique solution}
-
-\dd Normally, Net will make sure that the puzzles it presents have
-only one solution. Puzzles with ambiguous sections can be more
-difficult and more subtle, so if you like you can turn off this
-feature and risk having ambiguous puzzles. (Also, finding \e{all}
-the possible solutions can be an additional challenge for an
-advanced player.)
-
 \lcont{
 
 The grid generation in Net has been carefully arranged so that the
@@ -370,6 +361,15 @@
 
 }
 
+\dt \e{Ensure unique solution}
+
+\dd Normally, Net will make sure that the puzzles it presents have
+only one solution. Puzzles with ambiguous sections can be more
+difficult and more subtle, so if you like you can turn off this
+feature and risk having ambiguous puzzles. (Also, finding \e{all}
+the possible solutions can be an additional challenge for an
+advanced player.)
+
 \C{cube} \i{Cube}
 
 \cfg{winhelp-topic}{games.cube}
@@ -613,15 +613,23 @@
 
 \H{rectangles-params} \I{parameters, for Rectangles}Rectangles parameters
 
-The \q{Custom...} option on the \q{Type} menu offers you \e{Width}
-and \e{Height} parameters, which are self-explanatory.
+These parameters are available from the \q{Custom...} option on the
+\q{Type} menu.
 
-\q{Expansion factor} is a mechanism for changing the type of grids
-generated by the program. Some people prefer a grid containing a few
-large rectangles to one containing many small ones. So you can ask
+\dt \e{Width}, \e{Height}
+
+\dd Size of grid, in squares.
+
+\dt \e{Expansion factor}
+
+\dd This is a mechanism for changing the type of grids generated by
+the program. Some people prefer a grid containing a few large
+rectangles to one containing many small ones. So you can ask
 Rectangles to essentially generate a \e{smaller} grid than the size
 you specified, and then to expand it by adding rows and columns.
 
+\lcont{
+
 The default expansion factor of zero means that Rectangles will
 simply generate a grid of the size you ask for, and do nothing
 further. If you set an expansion factor of (say) 0.5, it means that
@@ -635,6 +643,17 @@
 and more intuitive playing style. If you set it \e{too} high,
 though, the game simply cannot generate more than a few rectangles
 to cover the entire grid, and the game becomes trivial.
+
+}
+
+\dt \e{Ensure unique solution}
+
+\dd Normally, Rectangles will make sure that the puzzles it presents
+have only one solution. Puzzles with ambiguous sections can be more
+difficult and more subtle, so if you like you can turn off this
+feature and risk having ambiguous puzzles. Also, finding \e{all} the
+possible solutions can be an additional challenge for an advanced
+player. Turning off this option can also speed up puzzle generation.
 
 
 \C{netslide} \i{Netslide}
--- a/rect.c
+++ b/rect.c
@@ -45,6 +45,7 @@
 struct game_params {
     int w, h;
     float expandfactor;
+    int unique;
 };
 
 #define INDEX(state, x, y)    (((y) * (state)->w) + (x))
@@ -84,6 +85,7 @@
 
     ret->w = ret->h = 7;
     ret->expandfactor = 0.0F;
+    ret->unique = TRUE;
 
     return ret;
 }
@@ -108,6 +110,7 @@
     ret->w = w;
     ret->h = h;
     ret->expandfactor = 0.0F;
+    ret->unique = TRUE;
     return TRUE;
 }
 
@@ -135,7 +138,13 @@
     if (*string == 'e') {
 	string++;
 	ret->expandfactor = atof(string);
+	while (*string &&
+	       (*string == '.' || isdigit((unsigned char)*string))) string++;
     }
+    if (*string == 'a') {
+	string++;
+	ret->unique = FALSE;
+    }
 }
 
 static char *encode_params(game_params *params, int full)
@@ -145,6 +154,8 @@
     sprintf(data, "%dx%d", params->w, params->h);
     if (full && params->expandfactor)
         sprintf(data + strlen(data), "e%g", params->expandfactor);
+    if (full && !params->unique)
+        strcat(data, "a");
 
     return dupstr(data);
 }
@@ -174,11 +185,16 @@
     ret[2].sval = dupstr(buf);
     ret[2].ival = 0;
 
-    ret[3].name = NULL;
-    ret[3].type = C_END;
+    ret[3].name = "Ensure unique solution";
+    ret[3].type = C_BOOLEAN;
     ret[3].sval = NULL;
-    ret[3].ival = 0;
+    ret[3].ival = params->unique;
 
+    ret[4].name = NULL;
+    ret[4].type = C_END;
+    ret[4].sval = NULL;
+    ret[4].ival = 0;
+
     return ret;
 }
 
@@ -189,6 +205,7 @@
     ret->w = atoi(cfg[0].sval);
     ret->h = atoi(cfg[1].sval);
     ret->expandfactor = atof(cfg[2].sval);
+    ret->unique = cfg[3].ival;
 
     return ret;
 }
@@ -1505,7 +1522,10 @@
                 }
             }
 
-	    ret = rect_solver(params->w, params->h, nnumbers, nd, rs);
+	    if (params->unique)
+		ret = rect_solver(params->w, params->h, nnumbers, nd, rs);
+	    else
+		ret = TRUE;	       /* allow any number placement at all */
 
             if (ret) {
                 /*