gnugo-devel
[Top][All Lists]
Advanced

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

Re: [gnugo-devel] Reading patch


From: Gunnar Farnebäck
Subject: Re: [gnugo-devel] Reading patch
Date: Thu, 08 Sep 2005 22:08:33 +0200
User-agent: EMH/1.14.1 SEMI/1.14.3 (Ushinoya) FLIM/1.14.2 (Yagi-Nishiguchi) APEL/10.3 Emacs/21.3 (sparc-sun-solaris2.9) MULE/5.0 (SAKAKI)

I wrote:
> Time for a refreshing reading patch. This adds the static function
> squeeze_moves() in reading.c, which looks for moves to squeeze out
> liberties from superstrings. Typical examples are reading:203,204.

And here is the actual patch.

/Gunnar

Index: engine/reading.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/reading.c,v
retrieving revision 1.156
diff -u -r1.156 reading.c
--- engine/reading.c    7 Dec 2004 04:50:02 -0000       1.156
+++ engine/reading.c    7 Mar 2005 14:04:51 -0000
@@ -302,6 +302,7 @@
                               int be_aggressive);
 static void superstring_moves(int str, struct reading_moves *moves, 
                              int liberty_cap, int does_attack);
+static void squeeze_moves(int str, struct reading_moves *moves);
 static void superstring_break_chain_moves(int str, int liberty_cap,
                                         struct reading_moves *moves);
 static void double_atari_chain2_moves(int str,
@@ -1556,8 +1557,10 @@
   /* If nothing else works, we try playing a liberty of the
    * super_string.
    */
-  if (stackp <= superstring_depth)
+  if (stackp <= superstring_depth) {
     superstring_moves(str, &moves, 3, 0);
+    squeeze_moves(str, &moves);
+  }
 
   break_chain2_defense_moves(str, &moves, be_aggressive);
 
@@ -1728,8 +1731,10 @@
   /* If nothing else works, we try playing a liberty of the
    * super_string.
    */
-  if (level >= 8 && stackp <= backfill2_depth)
+  if (level >= 8 && stackp <= backfill2_depth) {
     superstring_moves(str, &moves, 3, 0);
+    squeeze_moves(str, &moves);
+  }
 
   if (stackp <= break_chain_depth)
     break_chain3_moves(str, &moves, 0);
@@ -1799,6 +1804,7 @@
 #endif
   if (stackp <= superstring_depth)
     superstring_moves(str, &moves, 4, 0);
+    squeeze_moves(str, &moves);
   }
 
   order_moves(str, &moves, color, read_function_name, *move);
@@ -2436,6 +2444,82 @@
 }
 
 
+/* This function is somewhat related to superstring_moves() but tries
+ * to find moves to squeeze out liberties from the superstring, aiming
+ * to capture the main string in a shortage of liberties.
+ *
+ * For a typical example, see the move E9 in reading:203,204. It is
+ * assumed that the same move is effective both for attack and
+ * defense.
+ */
+static void
+squeeze_moves(int str, struct reading_moves *moves)
+{
+  int color = board[str];
+  int other = OTHER_COLOR(color);
+  int libs[4];
+  int num_libs;
+  int libs2[4];
+  int num_libs2;
+  int k;
+  int r;
+  int potential_move;
+  int previous_liberty;
+
+  num_libs = findlib(str, 4, libs);
+  gg_assert(num_libs <= 4);
+
+  for (k = 0; k < num_libs; k++) {
+    if (!is_suicide(libs[k], other))
+      continue;
+
+    num_libs2 = approxlib(libs[k], color, 4, libs2);
+    if (num_libs2 != num_libs)
+      continue;
+
+    for (r = 0; r < num_libs2; r++)
+      if (!liberty_of_string(libs2[r], str)) {
+       potential_move = libs2[r];
+       break;
+      }
+
+    previous_liberty = libs[k];
+
+    while (is_suicide(potential_move, other)) {
+      num_libs2 = approxlib(potential_move, color, 3, libs2);
+      if (num_libs2 != 2) {
+       potential_move = NO_MOVE;
+       break;
+      }
+      if (libs2[0] == previous_liberty) {
+       previous_liberty = potential_move;
+       potential_move = libs2[1];
+      }
+      else {
+       previous_liberty = potential_move;
+       potential_move = libs2[0];
+      }
+      if (liberty_of_string(potential_move, str)) {
+       potential_move = NO_MOVE;
+       break;
+      }
+    }
+    
+    if (potential_move == NO_MOVE
+       || !is_self_atari(potential_move, other))
+      continue;
+
+    approxlib(potential_move, other, 1, libs2);
+
+    num_libs2 = approxlib(libs2[0], color, MAXLIBS, NULL);
+    
+    if (num_libs2 < 3
+       && num_libs2 < approxlib(potential_move, color, MAXLIBS, NULL))
+      ADD_CANDIDATE_MOVE(potential_move, 0, *moves, "squeeze move");
+  }
+}
+
+
 /* In positions like
  *
  * |.XXOO.
@@ -3515,6 +3599,7 @@
        if (stackp <= backfill2_depth)
          liberty_cap = 3;
        superstring_moves(str, &moves, liberty_cap, 1);
+       squeeze_moves(str, &moves);
       }
       break;
 
@@ -3655,8 +3740,10 @@
       /* If nothing else works, we try filling a liberty of the
        * super_string.
        */
-      if (level >= 8 && stackp <= backfill2_depth)
+      if (level >= 8 && stackp <= backfill2_depth) {
        superstring_moves(str, &moves, 3, 1);
+       squeeze_moves(str, &moves);
+      }
       break;
 
     default:




reply via email to

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