gnugo-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnugo-devel] mkpat constraint_diagram checking


From: Teun Burgers
Subject: [gnugo-devel] mkpat constraint_diagram checking
Date: Wed, 23 Jan 2002 22:20:23 +0100

Gunnar wrote:

> Teun wrote (on January 7):
> > This patch makes mkpat.c even more complex than it already is...
> >
> > The aim is to improve consistency checking between diagram and
> > constraint diagram. This initial version checks
> > for every xXoO in the constraint diagram whether there is a
> > corresponding
> > one in the diagram.
> 
> Does this work? It seems to me it should have barfed at pattern A1100
> in owl_attackpats.db at least.

It should have and it does after applying this patch.
It used the wrong value of patno

- constraint diagram checking moved to new function
  check_constraint_diagram
- Invoke check_constraint_diagram *before* incrementing
  the pattern number.

Teun
Index: mkpat.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/patterns/mkpat.c,v
retrieving revision 1.44
diff -u -r1.44 mkpat.c
--- mkpat.c     22 Jan 2002 14:57:04 -0000      1.44
+++ mkpat.c     23 Jan 2002 21:11:56 -0000
@@ -321,51 +321,64 @@
 int dfa_c_output = 0; /* if 1 the dfa is saved as a c file */
 dfa_t dfa;
 
-
 /**************************
  *
- * stuff to parse the input
+ * stuff to check the constraint diagram
  *
  **************************/
 
-/* reset state of all pattern variables */
 #define CHECK_CHARS "xXoO"
 static void
-reset_pattern(void)
+check_constraint_diagram(void)
 {
   int i, j, ino = 0, iso = 0, jwo = 0, jeo = 0;
 
-  if (patno > 0) {
-    int have_constraint = (pattern[patno].autohelper_flag & HAVE_CONSTRAINT);
+  int have_constraint = (pattern[patno].autohelper_flag & HAVE_CONSTRAINT);
+  /* fprintf(stderr, "patno: %d\n", patno); */
     
-    if (where & NORTH_EDGE)
-      ino = 1;
-    if (where & SOUTH_EDGE)
-      iso = 1;
-    if (where & WEST_EDGE)
-      jwo = 1;
-    if (where & EAST_EDGE)
-      jeo = 1;
+  if (where & NORTH_EDGE)
+    ino = 1;
+  if (where & SOUTH_EDGE)
+    iso = 1;
+  if (where & WEST_EDGE)
+    jwo = 1;
+  if (where & EAST_EDGE)
+    jeo = 1;
     
-    if (verbose) {
-      for (i = ino; i <= maxi+ino+iso; i++)
-        fprintf(stderr, "%02d %s\n", i, diagram[i]);
-      for (i = ino; i <= maxi+ino+iso; i++)
-        fprintf(stderr, "%02d %s\n", i, constraint_diagram[i]);
-    }
+  if (verbose) {
+    for (i = ino; i <= maxi+ino+iso; i++)
+      fprintf(stderr, "%02d %s\n", i, diagram[i]);
+    for (i = ino; i <= maxi+ino+iso; i++)
+      fprintf(stderr, "%02d %s\n", i, constraint_diagram[i]);
+  }
     
-    if (have_constraint) {
-      for (i = ino; i <= maxi+ino; i++)
-        for (j = jwo; j <= maxj+jwo; j++) {
-          if (strchr(CHECK_CHARS, constraint_diagram[i][j])
+  /* fprintf(stderr, "have_constraint: %d\n", have_constraint); */
+  if (have_constraint) {
+    for (i = ino; i <= maxi+ino; i++)
+      for (j = jwo; j <= maxj+jwo; j++) {
+       /* fprintf(stderr,"%2d %2d %c %c\n", i, j, constraint_diagram[i][j], 
+       diagram[i][j]); */
+       if (strchr(CHECK_CHARS, constraint_diagram[i][j])
              && constraint_diagram[i][j] != diagram[i][j]) {
-           fprintf(stderr, "%s(%d) : Error : xXoO not matched in constraint 
diagram of pattern pattern_names[patno] %s\n",
+         fprintf(stderr, "%s(%d) : Error : xXoO not matched in constraint 
diagram of pattern pattern_names[patno] %s\n",
                    current_file, current_line_number, pattern_names[patno]);
-           fatal_errors++;
-         }
-        }
+         fatal_errors++;
+       }
     }
   }
+}
+
+/**************************
+ *
+ * stuff to parse the input
+ *
+ **************************/
+
+/* reset state of all pattern variables */
+static void
+reset_pattern(void)
+{
+  int i, j;
 
   maxi = 0;
   maxj = 0;
@@ -1662,11 +1675,13 @@
          finish_constraint_and_action(argv[gg_optind]); /* fall through */
        case 0:
        case 4:
+         check_constraint_diagram();
          patno++;
          reset_pattern();
        }
       }
       else {
+       check_constraint_diagram();
        patno++;
        reset_pattern();
       }
@@ -1782,6 +1797,7 @@
       finish_constraint_and_action(argv[gg_optind]); /* fall through */
     case 0:
     case 4:
+      check_constraint_diagram();
       patno++;
       reset_pattern();
     }

reply via email to

[Prev in Thread] Current Thread [Next in Thread]