gnugo-devel
[Top][All Lists]
Advanced

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

[gnugo-devel] worm analysis patch


From: Gunnar Farneback
Subject: [gnugo-devel] worm analysis patch
Date: Mon, 02 Sep 2002 22:23:07 +0200
User-agent: EMH/1.14.1 SEMI/1.14.3 (Ushinoya) FLIM/1.14.2 (Yagi-Nishiguchi) APEL/10.3 Emacs/20.7 (sparc-sun-solaris2.7) (with unibyte mode)

This patch fixes a FIXME in find_more_attack_and_defense_moves() and a
related problem in make_worms(). The code to test for additional
worm attack and defense moves has at some places been sloppy with
keeping track of ko results, which this patch corrects.

This can occasionally avoid entirely pointless moves being played. It
does not do well on the regressions though. The total delta is three
unexpected failures of nngs:600, nngs1:40, nngs2:1. All those involve
owl mistakes, however, and should count as accidental.

/Gunnar

Index: engine/value_moves.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/value_moves.c,v
retrieving revision 1.51
diff -u -r1.51 value_moves.c
--- engine/value_moves.c        2 Sep 2002 16:51:02 -0000       1.51
+++ engine/value_moves.c        2 Sep 2002 19:31:50 -0000
@@ -119,8 +119,6 @@
  *
  * FIXME: We would like to see whether an arbitrary move works to cut
  *        or connect something else too.
- *
- * FIXME: Keep track of ko results.
  */
 
 static void
@@ -191,22 +189,26 @@
           * unless we already know the move works as defense move.
           */
          if (board[aa] == color
-             && !defense_move_reason_known(ii, unstable_worms[k]))
-           if (!attack(aa, NULL)) {
+             && !defense_move_reason_known(ii, unstable_worms[k])) {
+           int acode = attack(aa, NULL);
+           if (acode < worm[aa].attack_codes[0]) {
              if (!cursor_at_start_of_line)
                TRACE("\n");
-             TRACE("%ofound extra point of defense of %1m at %1m\n", 
-                   aa, ii);
+             TRACE("%ofound extra point of defense of %1m at %1m code %d\n",
+                   aa, ii, REVERSE_RESULT(acode));
              cursor_at_start_of_line = 1;
-             add_defense_move(ii, aa, WIN);
+             add_defense_move(ii, aa, REVERSE_RESULT(acode));
            }
+         }
            
          /* string of opponent color, see if there still is a defense,
           * unless we already know the move works as attack move.
           */
          if (board[aa] == other
-             && !attack_move_reason_known(ii, unstable_worms[k]))
-           if (!find_defense(aa, NULL)) {
+             && !attack_move_reason_known(ii, unstable_worms[k])) {
+           
+           int dcode = find_defense(aa, NULL);
+           if (dcode < worm[aa].defend_codes[0]) {
              /* Maybe find_defense() doesn't find the defense. Try to
               * defend with the stored defense move.
               */
@@ -215,20 +217,25 @@
              if (trymove(worm[aa].defense_points[0], other, 
                          "find_more_attack_and_defense_moves", 0,
                          EMPTY, 0)) {
-               if (!attack(aa, NULL))
-                 attack_works = 0;
+               int this_dcode = REVERSE_RESULT(attack(aa, NULL));
+               if (this_dcode > dcode) {
+                 dcode = this_dcode;
+                 if (dcode >= worm[aa].defend_codes[0])
+                   attack_works = 0;
+               }
                popgo();
              }
                
              if (attack_works) {
                if (!cursor_at_start_of_line)
                  TRACE("\n");
-               TRACE("%ofound extra point of attack of %1m at %1m\n",
-                     aa, ii);
+               TRACE("%ofound extra point of attack of %1m at %1m code %d\n",
+                     aa, ii, REVERSE_RESULT(dcode));
                cursor_at_start_of_line = 1;
-               add_attack_move(ii, aa, WIN);
+               add_attack_move(ii, aa, REVERSE_RESULT(dcode));
              }
            }
+         }
        }
        popgo();
       }
Index: engine/worm.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/worm.c,v
retrieving revision 1.37
diff -u -r1.37 worm.c
--- engine/worm.c       28 Apr 2002 14:46:43 -0000      1.37
+++ engine/worm.c       2 Sep 2002 19:32:00 -0000
@@ -293,10 +293,12 @@
             * initial determination of worm.attack and worm.defend
             * to avoid horizon effect. Since stackp has been
             * incremented we must also increment depth and
-            * backfill_depth. */
+            * backfill_depth.
+            */
            
            /* Now we try to find a group which is saved or attacked as well
-              by this move. */
+            * by this move.
+            */
            DEBUG(DEBUG_WORMS, "trying %1m\n", aa);
            increase_depth_values();
            
@@ -326,8 +328,12 @@
                      if (worm[pos2].defend_codes[0] != 0
                          && trymove(worm[pos2].defense_points[0],
                                     color, "make_worms", 0, EMPTY, 0)) {
-                       if (!attack(pos2, NULL))
-                         attack_works = 0;
+                       int this_dcode = REVERSE_RESULT(attack(pos2, NULL));
+                       if (this_dcode > dcode) {
+                         dcode = this_dcode;
+                         if (dcode >= worm[pos2].defend_codes[0])
+                           attack_works = 0;
+                       }
                        popgo();
                      }
                    
@@ -407,8 +413,12 @@
                      if (trymove(worm[pos2].defense_points[0],
                                  other, "make_worms",
                                  NO_MOVE, EMPTY, NO_MOVE)) {
-                       if (!attack(pos2, NULL))
-                         attack_works = 0;
+                       int this_dcode = REVERSE_RESULT(attack(pos2, NULL));
+                       if (this_dcode > dcode) {
+                         dcode = this_dcode;
+                         if (dcode >= worm[pos2].defend_codes[0])
+                           attack_works = 0;
+                       }
                        popgo();
                      }
                      




reply via email to

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