From d85ae5a4a80cf34c1bd9e71a99bdc152b65b5e01 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Thu, 6 Jan 2011 01:52:51 +0100 Subject: [PATCH] 2lib: Introduce miaisafe, def_no_hopeless knobs, twiddle by respective Moggy flags It seems that the benefit of these is questionable on some board sizes. --- playout/moggy.c | 17 ++++++++++++++--- tactics/2lib.c | 13 +++++++------ tactics/2lib.h | 2 +- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/playout/moggy.c b/playout/moggy.c index bd75bcc..c3fd5ba 100644 --- a/playout/moggy.c +++ b/playout/moggy.c @@ -61,6 +61,9 @@ struct moggy_policy { /* Whether to always pick from moves capturing all groups in * global_atari_check(). */ bool capcheckall; + /* 2lib settings: */ + bool atari_def_no_hopeless; + bool atari_miaisafe; struct joseki_dict *jdict; struct pattern3s patterns; @@ -271,9 +274,11 @@ local_atari_check(struct playout_policy *p, struct board *b, struct move *m, str static void local_2lib_check(struct playout_policy *p, struct board *b, struct move *m, struct move_queue *q) { + struct moggy_policy *pp = p->data; + /* Does the opponent have just two liberties? */ if (board_group_info(b, group_at(b, m->coord)).libs == 2) { - group_2lib_check(b, group_at(b, m->coord), stone_other(m->color), q, 1<coord), stone_other(m->color), q, 1<atari_miaisafe, pp->atari_def_no_hopeless); #if 0 /* We always prefer to take off an enemy chain liberty * before pulling out ourselves. */ @@ -289,7 +294,7 @@ local_2lib_check(struct playout_policy *p, struct board *b, struct move *m, stru group_t g = group_at(b, c); if (!g || board_group_info(b, g).libs != 2) continue; - group_2lib_check(b, g, stone_other(m->color), q, 1<color), q, 1<atari_miaisafe, pp->atari_def_no_hopeless); }); if (PLDEBUGL(5)) @@ -522,7 +527,7 @@ playout_moggy_assess_group(struct playout_policy *p, struct prior_map *map, grou if (board_group_info(b, g).libs == 2) { if (!pp->atarirate) return; - group_2lib_check(b, g, map->to_play, &q, 0); + group_2lib_check(b, g, map->to_play, &q, 0, pp->atari_miaisafe, pp->atari_def_no_hopeless); while (q.moves--) { coord_t coord = q.move[q.moves]; if (PLDEBUGL(5)) @@ -685,6 +690,8 @@ playout_moggy_init(char *arg, struct board *b, struct joseki_dict *jdict) pp->korate = 20; pp->koage = 4; pp->alwaysccaprate = 20; pp->selfatari_other = true; + pp->atari_def_no_hopeless = true; + pp->atari_miaisafe = true; /* C is stupid. */ double mq_prob_default[MQ_MAX] = { @@ -738,6 +745,10 @@ playout_moggy_init(char *arg, struct board *b, struct joseki_dict *jdict) pp->selfatari_other = optval && *optval == '0' ? false : true; } else if (!strcasecmp(optname, "capcheckall")) { pp->capcheckall = optval && *optval == '0' ? false : true; + } else if (!strcasecmp(optname, "atari_miaisafe")) { + pp->atari_miaisafe = optval && *optval == '0' ? false : true; + } else if (!strcasecmp(optname, "atari_def_no_hopeless")) { + pp->atari_def_no_hopeless = optval && *optval == '0' ? false : true; } else if (!strcasecmp(optname, "fullchoose")) { p->choose = optval && *optval == '0' ? playout_moggy_seqchoose : playout_moggy_fullchoose; } else if (!strcasecmp(optname, "mqprob") && optval) { diff --git a/tactics/2lib.c b/tactics/2lib.c index 5bb8ec9..fa0136b 100644 --- a/tactics/2lib.c +++ b/tactics/2lib.c @@ -58,7 +58,8 @@ miai_2lib(struct board *b, group_t group, enum stone color) void check_group_atari(struct board *b, group_t group, enum stone owner, - enum stone to_play, struct move_queue *q, int tag) + enum stone to_play, struct move_queue *q, + int tag, bool use_def_no_hopeless) { for (int i = 0; i < 2; i++) { coord_t lib = board_group_info(b, group).lib[i]; @@ -93,7 +94,7 @@ check_group_atari(struct board *b, group_t group, enum stone owner, * liberty, or the "gained" liberties are shared. */ /* XXX: We do not check connecting to a short-on-liberty * group (e.g. ourselves). */ - if (to_play == owner && neighbor_count_at(b, lib, owner) == 1) { + if (use_def_no_hopeless && to_play == owner && neighbor_count_at(b, lib, owner) == 1) { if (immediate_liberty_count(b, lib) == 1) continue; if (immediate_liberty_count(b, lib) == 2 @@ -124,7 +125,7 @@ check_group_atari(struct board *b, group_t group, enum stone owner, } void -group_2lib_check(struct board *b, group_t group, enum stone to_play, struct move_queue *q, int tag) +group_2lib_check(struct board *b, group_t group, enum stone to_play, struct move_queue *q, int tag, bool use_miaisafe, bool use_def_no_hopeless) { enum stone color = board_at(b, group_base(group)); assert(color != S_OFFBOARD && color != S_NONE); @@ -134,10 +135,10 @@ group_2lib_check(struct board *b, group_t group, enum stone to_play, struct move coord2sstr(group, b), color); /* Do not try to atari groups that cannot be harmed. */ - if (miai_2lib(b, group, color)) + if (use_miaisafe && miai_2lib(b, group, color)) return; - check_group_atari(b, group, color, to_play, q, tag); + check_group_atari(b, group, color, to_play, q, tag, use_def_no_hopeless); /* Can we counter-atari another group, if we are the defender? */ if (to_play != color) @@ -155,7 +156,7 @@ group_2lib_check(struct board *b, group_t group, enum stone to_play, struct move } if (board_group_info(b, g2).libs != 2) continue; - check_group_atari(b, g2, color, to_play, q, tag); + check_group_atari(b, g2, color, to_play, q, tag, use_def_no_hopeless); }); } foreach_in_group_end; } diff --git a/tactics/2lib.h b/tactics/2lib.h index 9619c00..5ab46fb 100644 --- a/tactics/2lib.h +++ b/tactics/2lib.h @@ -9,6 +9,6 @@ struct move_queue; -void group_2lib_check(struct board *b, group_t group, enum stone to_play, struct move_queue *q, int tag); +void group_2lib_check(struct board *b, group_t group, enum stone to_play, struct move_queue *q, int tag, bool use_miaisafe, bool use_def_no_hopeless); #endif -- 2.11.4.GIT