gnugo-devel
[Top][All Lists]
Advanced

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

[gnugo-devel] under-the-stones tesuji


From: Paul Pogonyshev
Subject: [gnugo-devel] under-the-stones tesuji
Date: Sat, 9 Apr 2005 22:09:36 +0300
User-agent: KMail/1.4.3

- make fast_defense() aware of under-the-stones tesuji

Solves reading:199.  Other regression impact is not verified.

Paul


--- reading.c   05 Apr 2005 21:04:12 +0300      1.157
+++ reading.c   09 Apr 2005 22:08:31 +0300      
@@ -1231,6 +1231,60 @@ do_find_defense(int str, int *move)
 }
 
 
+/* Determine if a `move' by `color' allows under-the-stones tesuji
+ * a.k.a. "big snapback".  Here is an example:
+ *
+ *     |XXXX...
+ *     |XXOOXXX
+ *     |OOOXOOX
+ *     |..O*OOX
+ *     +-------
+ *
+ * Even though the move at '*' allows black to capture four white
+ * stones, white can later recapture black stones and create a second
+ * eye.  This is very similar to a snapback.
+ *
+ * This function returns true if a move creates a string of with two
+ * liberties, which can, however, be instantly recaptured by opponent.
+ * It is actually not required that the move captures something.  If
+ * the caller needs captures, it should check for them itself.
+ */
+static int
+allows_under_the_stones_tesuji(int move, int color)
+{
+  int result = 0;
+  SGFTree *save_sgf_dumptree;
+  int save_count_variations;
+
+  if (accuratelib(move, color, 3, NULL) != 2)
+    return 0;
+
+  save_sgf_dumptree     = sgf_dumptree;
+  save_count_variations = count_variations;
+
+  sgf_dumptree    = NULL;
+  count_variations = 0;
+
+  if (trymove(move, color, "allows_under_the_stones_tesuji", NO_MOVE)) {
+    int libs[2];
+
+    findlib(move, 2, libs);
+    if ((!is_self_atari(libs[0], color)
+        && accuratelib(libs[1], OTHER_COLOR(color), 3, NULL) <= 2)
+       || (!is_self_atari(libs[1], color)
+           && accuratelib(libs[0], OTHER_COLOR(color), 3, NULL) <= 2))
+      result = 1;
+
+    popgo();
+  }
+
+  sgf_dumptree    = save_sgf_dumptree;
+  count_variations = save_count_variations;
+
+  return result;
+}
+
+
 /* Called by the defendN functions.  Don't think too much if there's
  * an easy way to get enough liberties.
  */
@@ -1334,6 +1388,17 @@ fast_defense(int str, int liberties, int
       total--;
 
     if (total >= goal_liberties) {
+      /* One case when this code can give a false defense is an
+       * under-the-stones tesuji or "big snapback."  See reading:199
+       * for an example.  While this position is probably very rare,
+       * it is nice to make GNU Go understand "neat" tesujis.
+       */
+      if (liberties == 1 && lib == libs[0]
+         && allows_under_the_stones_tesuji(lib, color)) {
+       /* This is a bad "fast defense". */
+       continue;
+      }
+
       *move = lib;
       return 1;
     }





reply via email to

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