shithub: puzzles

Download patch

ref: 333d57bf6ec7def6fa78215a71a2d05476167fc1
parent: cc54c09413a08ea150fd8cc6706ed61ccc8ce47e
author: Simon Tatham <anakin@pobox.com>
date: Sat Aug 18 07:19:29 EDT 2007

Better test-mode diagnostics.

[originally from svn r7691]

--- a/unfinished/divvy.c
+++ b/unfinished/divvy.c
@@ -201,6 +201,9 @@
 	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 @@
 			 * 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 @@
 		 * 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,10 +380,25 @@
 	     * 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.