Better test-mode diagnostics.
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Sat, 18 Aug 2007 11:19:29 +0000 (11:19 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Sat, 18 Aug 2007 11:19:29 +0000 (11:19 +0000)
git-svn-id: svn://svn.tartarus.org/sgt/puzzles@7691 cda61777-01e9-0310-a592-d414129be87e

unfinished/divvy.c

index 9e6805d..f35afc8 100644 (file)
@@ -201,6 +201,9 @@ int *divvy_rectangle(int w, int h, int k, random_state *rs)
        if (j == 0)
            break;                     /* all ominoes are complete! */
        j = tmp[random_upto(rs, j)];
+#ifdef DIVVY_DIAGNOSTICS
+       printf("Trying to extend %d\n", j);
+#endif
 
        /*
         * So we're trying to expand omino j. We breadth-first
@@ -263,7 +266,7 @@ int *divvy_rectangle(int w, int h, int k, random_state *rs)
                         * addable to this omino when the omino is
                         * missing a square. To do this it's only
                         * necessary to re-check addremcommon.
-~|~                     */
+                        */
                        if (!addremcommon(w, h, order[i]%w, order[i]/w,
                                          own, j))
                            continue;
@@ -282,13 +285,25 @@ int *divvy_rectangle(int w, int h, int k, random_state *rs)
                 * moving squares between ominoes, ending up
                 * expanding our starting omino by one.
                 */
+#ifdef DIVVY_DIAGNOSTICS
+               printf("(%d,%d)", i%w, i/w);
+#endif
                while (1) {
                    own[i] = j;
+#ifdef DIVVY_DIAGNOSTICS
+                   printf(" -> %d", j);
+#endif
                    if (tmp[2*j] == -2)
                        break;
                    i = tmp[2*j+1];
                    j = tmp[2*j];
+#ifdef DIVVY_DIAGNOSTICS
+                   printf("; (%d,%d)", i%w, i/w);
+#endif
                }
+#ifdef DIVVY_DIAGNOSTICS
+               printf("\n");
+#endif
 
                /*
                 * Increment the size of the starting omino.
@@ -365,11 +380,26 @@ int *divvy_rectangle(int w, int h, int k, random_state *rs)
             * FIXME: or should we loop over all ominoes before we
             * give up?
             */
+#ifdef DIVVY_DIAGNOSTICS
+           printf("FAIL!\n");
+#endif
            retdsf = NULL;
            goto cleanup;
        }
     }
 
+#ifdef DIVVY_DIAGNOSTICS
+    {
+       int x, y;
+       printf("SUCCESS! Final grid:\n");
+       for (y = 0; y < h; y++) {
+           for (x = 0; x < w; x++)
+               printf("%3d", own[y*w+x]);
+           printf("\n");
+       }
+    }
+#endif
+
     /*
      * Construct the output dsf.
      */