gnugo-devel
[Top][All Lists]
Advanced

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

Re: [gnugo-devel] paul_3_13.8 and paul_3_13.9


From: bump
Subject: Re: [gnugo-devel] paul_3_13.8 and paul_3_13.9
Date: Fri, 20 Dec 2002 09:33:24 -0800

> uhm, sorry, i should have waited for paul_3_13.8 to come into cvs.
> from a quick review of the patches it seems to me that merging
> them must be pretty simple:
> 
>   paul_3_13.9 changes the calling convention of write_elements()
>   paul_3_13.8 changes write_elements() itself.
> 
> if you want to merge paul_3_13.8 yourself, remove the `name'
> parameter from write_elements() and change each reference to
> it with a reference to `prefix'.

I did this resulting in the following patch. However, it crashes.

My current thinking is that it is best to back out paul_3_13.9,
merge paul_3_13.8 and arend_3_13.8, and ask Paul to resubmit
paul_3_13.9. I won't do this until I hear from Paul and Arend.

Dan

Index: patterns/mkpat.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/patterns/mkpat.c,v
retrieving revision 1.97
diff -u -r1.97 mkpat.c
--- patterns/mkpat.c    20 Dec 2002 02:06:59 -0000      1.97
+++ patterns/mkpat.c    20 Dec 2002 17:28:24 -0000
@@ -595,7 +595,7 @@
 {
 #if GRID_OPT
   /*                              element: .  X  O  x  o  ,  a  ! */
-  static const unsigned int and_mask[] = { 3, 3, 3, 1, 2, 3, 3, 1 };
+  static const unsigned int and_mask[] = { 3, 3, 3, 1, 2, 3, 3, 3 };
   static const unsigned int val_mask[] = { 0, 2, 1, 0, 0, 0, 0, 0 };
 
   int ll;  /* iterate over rotations */
@@ -1570,35 +1570,76 @@
 write_elements(FILE *outfile)
 {
   int node;
+  int used_nodes = 0;
 
   assert(ci != -1 && cj != -1);
 
   /* sort the elements so that least-likely elements are tested first. */
   gg_sort(elements, el, sizeof(struct patval_b), compare_elements);
 
-  fprintf(outfile, "static struct patval %s%d[] = {\n", prefix, patno);
-
-  /* This may happen for fullboard patterns. */
-  if (el == 0) {
-    fprintf(outfile, "  {0,-1}}; /* Dummy element, not used. */\n\n");
-    return;
-  }
+  fprintf(outfile, "static struct patval %s%d[] = {", prefix, patno);
   
-  for (node = 0;node < el; node++) {
-    assert(elements[node].x >= mini && elements[node].y >= minj);
-    if (!(elements[node].x <= maxi && elements[node].y <= maxj)) {
+  for (node = 0; node < el; node++) {
+    int x = elements[node].x;
+    int y = elements[node].y;
+    int att = elements[node].att;
+
+    assert(x >= mini && y >= minj);
+    if (!(x <= maxi && y <= maxj)) {
       fprintf(stderr, 
              "%s(%d) : error : Maximum number of elements exceeded in %s.\n",
              current_file, current_line_number, prefix);
       fatal_errors++;
+
     }
 
-    fprintf(outfile, "  {%d,%d}%s",
-           OFFSET(elements[node].x - ci, elements[node].y - cj),
-           elements[node].att,
-            node < el-1 ?  ((node + 1) % 4 ? ",\t" : ",\n")  : "};\n\n");
+#if GRID_OPT == 1
+    /* If we do grid optimization, we can avoid matching 9 pattern elements
+     * around its anchor (the 9 elements are the intersection of 16 grid
+     * elements for all possible transformations).
+     */
+    if (database_type != DB_DFA 
+       && ci-1 <= x && x <= ci+1 && cj-1 <= y && y <= cj+1) {
+      /* Unfortunately, callback function might need these elements. We
+       * can only safely discard dots here.
+       *
+       * FIXME: Implement a smarter, pattern class/database based,
+       *       filtering of unneeded elements. It will speed up
+       *       pattern matching and reduce database sizes somewhat.
+       *       E.g. it seems that no databases but aa_attackpat.db
+       *       can have opponent stones in goal etc.
+       */
+      if (att == ATT_dot)
+       continue;
+    }
+#endif /* GRID_OPT == 1 */
+    
+    /* DFA pattern matcher doesn't itself need these elements at all. But
+     * they are needed for goal checking and callback functions (same as
+     * above).
+     */
+    if (database_type != DB_DFA && att == ATT_dot)
+      continue;
+    
+    if (used_nodes)
+      fprintf(outfile, ",");
+    fprintf(outfile, used_nodes % 4 ? "\t" : "\n  ");
+    used_nodes++;
+
+    fprintf(outfile, "{%d,%d}", OFFSET(x - ci, y - cj), att);
+
   }
 
+  /* This may happen for fullboard patterns or if we have discarded all
+   * the elements as unneeded by the matcher.
+   */
+  if (!used_nodes)
+    fprintf(outfile, "{0,-1}}; /* Dummy element, not used. */\n\n");
+  else
+    fprintf(outfile, "\n};\n\n");
+
+  pattern[patno].patlen = used_nodes;
+
 #if EXPERIMENTAL_READING
   if (database_type == DB_TREE)
     tree_push_pattern();
@@ -2457,7 +2498,8 @@
        if (state == 2 || state == 3) {
          finish_pattern(line);
          
-         write_elements(output_FILE);
+         write_elements(output_FILE);
+
          if (database_type == DB_DFA)
            write_to_dfa(patno);
          state = 4;




reply via email to

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