gnugo-devel
[Top][All Lists]
Advanced

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

[gnugo-devel] attack1() patch


From: Evan Berggren Daniel
Subject: [gnugo-devel] attack1() patch
Date: Fri, 22 Nov 2002 20:15:21 -0500 (EST)

This patch solves reading:55.  In the testcase, the defender can make a
group with one eye and one liberty in ko.  The reading code does not
understand that the defender cannot win the ko no matter what.  This patch
makes attack1() count such cases as wins by checking whether the defender,
given infinite moves, could actually defend.  (Defender needs more than
one chance for cases like reading:132 where he must win the ko more than
once, but can win eventually.)  Of course, this has a small performance
penalty (reading nodes in reading.tst from 97435 to 97799).

I am running a full regression suite now, and will post results if more
than reading:55 changes.

Thanks

Evan Daniel

Index: engine/reading.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/reading.c,v
retrieving revision 1.85
diff -u -r1.85 reading.c
--- engine/reading.c    18 Nov 2002 15:35:17 -0000      1.85
+++ engine/reading.c    23 Nov 2002 01:08:11 -0000
@@ -2954,6 +2954,8 @@
   int other = OTHER_COLOR(color);
   int xpos;
   int result = -1;
+  int k;
+  int dcode;

   SETUP_TRACE_INFO("attack1", str);
   reading_node_counter++;
@@ -3020,14 +3022,13 @@
   if (result != WIN) {
     int liberties;
     int libs[6];
-    int k;
     liberties = approxlib(xpos, color, 6, libs);
     if (liberties <= 5)
       for (k = 0; k < liberties; k++) {
        int apos = libs[k];
        if (!is_self_atari(apos, other)
            && trymove(apos, other, "attack1-C", str, komaster, kom_pos)) {
-         int dcode = do_find_defense(str, NULL, komaster, kom_pos);
+         dcode = do_find_defense(str, NULL, komaster, kom_pos);
          if (dcode != WIN && do_attack(str, NULL, komaster, kom_pos)) {
            if (dcode == 0) {
              popgo();
@@ -3041,6 +3042,33 @@
        }
       }
   }
+
+  /* If we can attack in ko, but defender cannot defend except in ko,
+   * then that means that all the defender is doing is delaying things,
+   * and in actuality we have a win.  We give defender lots of chances
+   * in case defender needs to win the ko several times.
+   */
+  if (result < WIN && result > 0) {
+    int nmoves = 0;
+    int d_move = 0;
+    do {
+      dcode = find_defense(str, &d_move);
+      if (dcode == 0 || dcode == WIN)
+        break;
+      if (trymove(d_move, color, "attack2-E", str, komaster, kom_pos)) {
+        nmoves++;
+      } else
+       break;
+    } while (1);
+
+    if (dcode == 0)
+      result = WIN;
+
+    while (nmoves > 0) {
+      nmoves--;
+      popgo();
+    }
+  }

   if (result > 0) {
     *move = xpos;





reply via email to

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