From b9b6110301878213ea11319471085c5eba6257ee Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Thu, 14 Oct 2010 18:07:27 +0200 Subject: [PATCH] Move selfatari_cousin() from Moggy to tactics/selfatari.c --- playout/moggy.c | 22 ---------------------- tactics/selfatari.c | 24 ++++++++++++++++++++++++ tactics/selfatari.h | 7 +++++++ 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/playout/moggy.c b/playout/moggy.c index 333638e..69e6ee3 100644 --- a/playout/moggy.c +++ b/playout/moggy.c @@ -506,28 +506,6 @@ playout_moggy_fullchoose(struct playout_policy *p, struct board *b, enum stone t } -static coord_t -selfatari_cousin(struct board *b, enum stone color, coord_t coord) -{ - group_t groups[4]; int groups_n = 0; - 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) - groups[groups_n++] = g; - }); - - if (!groups_n) - return pass; - group_t group = groups[fast_random(groups_n)]; - - coord_t lib2 = board_group_other_lib(b, group, coord); - if (is_bad_selfatari(b, color, lib2)) - return pass; - return lib2; -} - void playout_moggy_assess_group(struct playout_policy *p, struct prior_map *map, group_t g, int games) { diff --git a/tactics/selfatari.c b/tactics/selfatari.c index 0bc2540..45ab224 100644 --- a/tactics/selfatari.c +++ b/tactics/selfatari.c @@ -5,6 +5,7 @@ #define DEBUG #include "board.h" #include "debug.h" +#include "random.h" #include "tactics/selfatari.h" @@ -355,3 +356,26 @@ is_bad_selfatari_slow(struct board *b, enum stone color, coord_t to) * is a bad self-atari! */ return true; } + + +coord_t +selfatari_cousin(struct board *b, enum stone color, coord_t coord) +{ + group_t groups[4]; int groups_n = 0; + 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) + groups[groups_n++] = g; + }); + + if (!groups_n) + return pass; + group_t group = groups[fast_random(groups_n)]; + + coord_t lib2 = board_group_other_lib(b, group, coord); + if (is_bad_selfatari(b, color, lib2)) + return pass; + return lib2; +} diff --git a/tactics/selfatari.h b/tactics/selfatari.h index a061f13..b9cb111 100644 --- a/tactics/selfatari.h +++ b/tactics/selfatari.h @@ -13,6 +13,13 @@ * or throw-ins. */ static bool is_bad_selfatari(struct board *b, enum stone color, coord_t to); +/* Move (color, coord) is a selfatari; this means that it puts a group of + * ours in atari; i.e., the group has two liberties now. Return the other + * liberty of such a troublesome group if that one is not a self-atari. + * (In case (color, coord) is a multi-selfatari, consider a randomly chosen + * candidate.) */ +coord_t selfatari_cousin(struct board *b, enum stone color, coord_t coord); + bool is_bad_selfatari_slow(struct board *b, enum stone color, coord_t to); static inline bool -- 2.11.4.GIT