Fixes in grid generation for pedantic special cases when one or both
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Thu, 24 Feb 2005 08:13:32 +0000 (08:13 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Thu, 24 Feb 2005 08:13:32 +0000 (08:13 +0000)
grid dimensions are very small.

git-svn-id: svn://svn.tartarus.org/sgt/puzzles@5390 cda61777-01e9-0310-a592-d414129be87e

pattern.c

index 91b1a2f..66ed134 100644 (file)
--- a/pattern.c
+++ b/pattern.c
@@ -281,6 +281,15 @@ static void generate(random_state *rs, int w, int h, unsigned char *retgrid)
                     for (q = -1; q <= +1; q++) {
                         if (i+p < 0 || i+p >= h || j+q < 0 || j+q >= w)
                             continue;
+                       /*
+                        * An additional special case not mentioned
+                        * above: if a grid dimension is 2xn then
+                        * we do not average across that dimension
+                        * at all. Otherwise a 2x2 grid would
+                        * contain four identical squares.
+                        */
+                       if ((h==2 && p!=0) || (w==2 && q!=0))
+                           continue;
                         n++;
                         sx += fgrid[(i+p)*w+(j+q)];
                     }
@@ -303,7 +312,7 @@ static void generate(random_state *rs, int w, int h, unsigned char *retgrid)
 
     for (i = 0; i < h; i++) {
         for (j = 0; j < w; j++) {
-            retgrid[i*w+j] = (fgrid[i*w+j] > threshold ? GRID_FULL :
+            retgrid[i*w+j] = (fgrid[i*w+j] >= threshold ? GRID_FULL :
                               GRID_EMPTY);
         }
     }