[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [gnugo-devel] my beloved bamboo joins again
From: |
Martin Holters |
Subject: |
Re: [gnugo-devel] my beloved bamboo joins again |
Date: |
Wed, 31 Dec 2003 17:23:07 +0100 |
ons 2003-12-31 klockan 18.04 skrev Paul Pogonyshev:
> Martin wrote:
> > 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.
>
> Sounds good.
>
> If you want to continue contributing to GNU Go, we'll ask you to assign
> copyright on your changes to Free Software Foundation. Are you willing to
> do this?
Yes, of course. It's an honour to do so.
> Below are some style related comments on your patch. Please don't consider
> them as an offence, everybody have seen them regarding his first patches,
> including me ;)
No offence taken.
[...]
> > + 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;
> > ...
>
> Another point: i don't quite like these case labels, they are go to deep
> into board internals, i'd say. You could have just written
>
> if (libs[l1] == WEST(libs[l2]) || libs[l1] == EAST(libs[l2])) {
> ...
> }
> else if (libs[l1] == SOUTH(libs[l2] || libs[l1] == NORTH(libs[l2])) {
> ...
> }
>
> This seems cleaner to me.
One could also use e.g. WEST(0) instead of 1 as case labels. This still
makes some assumptions about the board internals, but less so. I have
adopted the if .. else if now, anyway.
I hope the following is now style-accepted:
Index: engine/reading.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/reading.c,v
retrieving revision 1.130
diff -u -b -B -r1.130 reading.c
--- engine/reading.c 24 Nov 2003 21:15:20 -0000 1.130
+++ engine/reading.c 31 Dec 2003 16:16:31 -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,52 @@
}
}
+/*
+ * 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;
+
+ if (libs[l1] == WEST(libs[l2]) || libs[l1] == EAST(libs[l2]) ) {
+ 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");
+ }
+ else if (libs[l1] == NORTH(libs[l2]) || libs[l1] ==
SOUTH(libs[l2]) ) {
+ 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");
+ }
+ }
+}
+
/* In a situation like this:
*