gnugo-devel
[Top][All Lists]
Advanced

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

[gnugo-devel] Improved constraint checking


From: Teun Burgers
Subject: [gnugo-devel] Improved constraint checking
Date: Mon, 07 Jan 2002 22:10:43 +0100

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.

It adds to new character arrays diagram and constraint_diagram
to store both diagrams. The extra check is done in reset_pattern.
This is not entirely appropriate, given the name of the function,
but seems the only logical place to hook it in.


Teun


Index: mkpat.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/patterns/mkpat.c,v
retrieving revision 1.38
diff -u -r1.38 mkpat.c
--- mkpat.c     1 Jan 2002 17:15:17 -0000       1.38
+++ mkpat.c     7 Jan 2002 21:03:10 -0000
@@ -126,10 +126,16 @@
 int pats_with_constraints = 0;  /* just out of interest */
 int label_coords[256][2];       /* Coordinates for labeled stones in
the 
                                   autohelper patterns. */
-int current_i;                 /* Counter for the line number of a 
+int current_i;                 /* Counter for the line number of the
+                                  diagram */ 
+int current_c_i;               /* Counter for the line number of a 
                                   constraint diagram. */
 char constraint[MAXCONSTRAINT]; /* Store constraint lines. */
 char action[MAXCONSTRAINT];     /* Store action lines. */
+static char diagram[MAX_BOARD+2][MAX_BOARD+3];
+                               /* store pattern diagram*/
+static char constraint_diagram[MAX_BOARD+2][MAX_BOARD+3];
+                               /* store pattern constraint diagram */
 
 /* stuff to maintain info about patterns while reading */
 struct pattern pattern[MAXPATNO];  /* accumulate the patterns into here
*/
@@ -144,6 +150,7 @@
   const char *code;
 };
 
+
 /*
  * current_* are useful for debugging broken patterns.
  */
@@ -317,10 +324,40 @@
  **************************/
 
 /* reset state of all pattern variables */
+#define CHECK_CHARS "xXoO"
 static void
 reset_pattern(void)
 {
-  int i;
+  int i, j, ino=0, iso=0, jwo=0, jeo=0;
+
+  if (patno > 0) {
+    int have_constraint = (pattern[patno].autohelper_flag &
HAVE_CONSTRAINT);
+    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 (have_constraint) {
+      for(i=ino; i<=maxi+ino; i++)
+        for(j=jwo; j<=maxj+jwo; 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",
+               current_file, current_line_number, pattern_names[patno]);
+              fatal_errors++;
+         }
+        }
+    }
+  }
 
   maxi = 0;
   maxj = 0;
@@ -333,8 +370,15 @@
   for (i = 0; i < 256; i++)
     label_coords[i][0] = -1;
   current_i = 0;
+  current_c_i = 0;
   constraint[0] = 0;
   action[0] = 0;
+  for(i=0; i<MAX_BOARD+2; i++) {
+    for(j=0; j<MAX_BOARD+3; j++) {
+      diagram[i][j] = '\0';
+      constraint_diagram[i][j] = '\0';
+    }
+  }
 }
   
 
@@ -468,8 +512,10 @@
 read_pattern_line(char *p)
 {
   const char *char_offset;
+  char *pcopy = p;
   int j;
   int width;
+  int jwo=0, jeo=0;
 
   if (where & SOUTH_EDGE)
     /* something wrong here : pattern line after a SOUTH_EDGE
constraint */
@@ -617,6 +663,12 @@
   if (j > maxj)
     maxj = j;
 
+
+  if (where & WEST_EDGE)
+    jwo = 1;
+  if (where & EAST_EDGE)
+    jeo = 1;
+  strncpy(diagram[maxi], pcopy, maxj + jwo + jeo);
   maxi++;
 
   return;
@@ -643,6 +695,8 @@
 read_constraint_diagram_line(char *p)
 {
   int j;
+  int jwo=0, jeo=0;
+  const char *pcopy = p;
 
   /* North or south boundary, no letter to be found. */
   if (*p == '+' || *p == '-')
@@ -659,7 +713,7 @@
        && label_coords[(int)*p][0] == -1) {
 
       /* New constraint letter */
-      label_coords[(int)*p][0] = current_i;
+      label_coords[(int)*p][0] = current_c_i;
       label_coords[(int)*p][1] = j;
     }
   }
@@ -676,7 +730,12 @@
     return;
   }
 
-  current_i++;
+  if (where & WEST_EDGE)
+    jwo = 1;
+  if (where & EAST_EDGE)
+    jeo = 1;
+  strncpy(constraint_diagram[current_c_i], pcopy, maxj+jwo+jeo+1);
+  current_c_i++;
 
   return;
 }
@@ -687,7 +746,7 @@
 static void
 check_constraint_diagram_size(void)
 {
-  if (current_i != maxi + 1) {
+  if (current_c_i != maxi + 1) {
     fprintf(stderr, "%s(%d) : error : Mismatching height of constraint
diagram in pattern %s\n", 
            current_file, current_line_number, pattern_names[patno]);
     fatal_errors++;
@@ -1629,6 +1688,7 @@
        state++; /* fall through */
       case 2:
        read_pattern_line(line);
+       current_i++;
        break;
       case 4:
        state++; /* fall through */
@@ -1640,6 +1700,7 @@
     else if (line[0] == ':') {
       if (state == 2 || state == 3) {
        finish_pattern(line);
+
        write_elements(output_FILE, argv[gg_optind]);
        if (dfa_generate)
          write_to_dfa(patno);



reply via email to

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