gnugo-devel
[Top][All Lists]
Advanced

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

[gnugo-devel] my beloved bamboo joins again


From: Martin Holters
Subject: [gnugo-devel] my beloved bamboo joins again
Date: Wed, 31 Dec 2003 12:36:11 +0100

Hi Evan & Gunnar,

thanks for your feed-back, regress.pike is exactly what I was looking
for, not only to justify buying a faster computer.

After some experimenting, I have come up with the following, which seems
a little over-specific, as it only solves 13x13:65 (well, and my initial
example, of course). But on the bright side, it has almost no
performance impact: the totals of regress.pike are within +- 0.05%, some
of the test-suites also run faster.

The patch also includes a minor performance tweak: In
special-rescue-moves(), the "trivial-capture-condition" can be moved
before the loop.

Happy new year
Martin

--- reading.c   24 Nov 2003 21:15:20 -0000      1.130
+++ reading.c   31 Dec 2003 11:09:02 -0000
@@ -257,6 +257,8 @@
 static int defend4(int str, int *move, int komaster, int kom_pos);
 static void special_rescue_moves(int str, int lib,
                                 struct reading_moves *moves);
+static void bamboo_rescue_moves(int str, int num_libs, int libs[], 
+                                struct reading_moves *moves);
 static void special_rescue2_moves(int str, int libs[2],
                                  struct reading_moves *moves);
 static void special_rescue3_moves(int str, int libs[3],
@@ -1464,6 +1466,7 @@
   if (stackp <= depth) {
     for (k = 0; k < liberties; k++)
       special_rescue_moves(str, libs[k], &moves);
+    bamboo_rescue_moves(str, liberties, libs, &moves);
   }
 
   if (stackp <= backfill_depth)
@@ -1666,6 +1669,7 @@
   if (stackp <= depth) {
     for (k = 0; k < liberties; k++)
       special_rescue_moves(str, libs[k], &moves);
+    bamboo_rescue_moves(str, liberties, libs, &moves);
   }
 
   if (level >= 8 && stackp <= backfill2_depth)
@@ -1792,15 +1796,15 @@
   int other = OTHER_COLOR(color);
   int k;
 
+  /* Use approxlib() to test for trivial capture. */
+  if (approxlib(lib, other, 3, NULL) > 2)
+    return;
+
   /* Loop over the four neighbours of the liberty, (lib + d). */
   for (k = 0; k < 4; k++) {
     int d = delta[k];
     if (board[lib + d] == EMPTY) {
 
-      /* Use approxlib() to test for trivial capture. */
-      if (approxlib(lib, other, 3, NULL) > 2)
-       continue;
-
       /* Don't play into a self atari. */
       if (is_self_atari(lib + d, color))
        continue;
@@ -1810,6 +1814,60 @@
   }
 }
 
+/*
+ * In situations like 
+ *
+ * XXXXXO
+ * XO.*.O
+ * XO.O.O
+ * XXXXXO
+ *
+ * playing at * is the correct rescue move, although the opponent
cannot 
+ * be captured at the respective first-order liberty.
+ */
+static void
+bamboo_rescue_moves(int str, int num_libs, int libs[], 
+                    struct reading_moves *moves)
+{
+  int color = board[str];
+  int l1, l2;
+
+  for (l1 = 0; l1 < num_libs; ++l1)
+    for (l2 = 0; l2 < num_libs; ++l2) {
+      if (l1==l2) continue;
+
+      switch (libs[l1]-libs[l2]) {
+       case 1:
+       case -1:
+         if (board[SOUTH(libs[l1])] == EMPTY 
+             && board[SOUTH(libs[l2])] == color
+             && !is_self_atari(SOUTH(libs[l1]), color))
+           ADD_CANDIDATE_MOVE(SOUTH(libs[l1]), 0, *moves, "bamboo_rescue");
+         if (board[NORTH(libs[l1])] == EMPTY 
+             && board[NORTH(libs[l2])] == color
+             && !is_self_atari(NORTH(libs[l1]), color))
+           ADD_CANDIDATE_MOVE(NORTH(libs[l1]), 0, *moves, "bamboo_rescue");
+         break;
+
+       case NS:
+       case -NS:
+         if (board[WEST(libs[l1])] == EMPTY 
+             && board[WEST(libs[l2])] == color
+             && !is_self_atari(WEST(libs[l1]), color))
+           ADD_CANDIDATE_MOVE(WEST(libs[l1]), 0, *moves, "bamboo_rescue");
+         if (board[EAST(libs[l1])] == EMPTY 
+             && board[EAST(libs[l2])] == color
+             && !is_self_atari(EAST(libs[l1]), color))
+           ADD_CANDIDATE_MOVE(EAST(libs[l1]), 0, *moves, "bamboo_rescue");
+         break;
+
+       default:
+         /* liberties are not next to each other */
+         break;
+      }
+    }
+}
+
 
 /* In a situation like this:
  *       






reply via email to

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