From b043d41e6c1d2fbb32570c36272e3cc83b6b4333 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Sun, 15 Jan 2012 19:21:22 +0100 Subject: [PATCH] selfatari_cousin(): Prefer filling libs of opponent groups This can help solve the false eye filling bug. --- tactics/selfatari.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/tactics/selfatari.c b/tactics/selfatari.c index 8ea1e19..678c762 100644 --- a/tactics/selfatari.c +++ b/tactics/selfatari.c @@ -514,17 +514,35 @@ coord_t selfatari_cousin(struct board *b, enum stone color, coord_t coord, group_t *bygroup) { group_t groups[4]; int groups_n = 0; + int groupsbycolor[4] = {0, 0, 0, 0}; + if (DEBUGL(6)) + fprintf(stderr, "cousin group search: "); foreach_neighbor(b, coord, { enum stone s = board_at(b, c); - if (s != color) continue; group_t g = group_at(b, c); - if (board_group_info(b, g).libs == 2) + if (board_group_info(b, g).libs == 2) { groups[groups_n++] = g; + groupsbycolor[s]++; + if (DEBUGL(6)) + fprintf(stderr, "%s(%s) ", coord2sstr(c, b), stone2str(s)); + } }); + if (DEBUGL(6)) + fprintf(stderr, "\n"); if (!groups_n) return pass; - group_t group = groups[fast_random(groups_n)]; + int gn; + if (groupsbycolor[stone_other(color)]) { + /* Prefer to fill the other liberty of an opponent + * group to filling own approach liberties. */ + for (gn = 0; gn < groups_n; gn++) + if (board_at(b, groups[gn]) == stone_other(color)) + break; + } else { + gn = fast_random(groups_n); + } + group_t group = groups[gn]; coord_t lib2 = board_group_other_lib(b, group, coord); if (is_bad_selfatari(b, color, lib2)) -- 2.11.4.GIT