From 1d8a09b41aca700c530e2cee947c07a6ff2e7dce Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Mon, 16 Jan 2012 21:16:00 +0100 Subject: [PATCH] Moggy middle_ladder: Support for turning off middle ladder reading We plan to switch to a completely different (much more expensive but more accurate) ladder reading algorithm, which will not be really usable in playouts. So how much will we hurt ourselves by removing this from playouts? --- pattern.c | 6 +++--- playout/moggy.c | 20 +++++++++++++------- tactics/1lib.c | 4 ++-- tactics/1lib.h | 2 +- tactics/ladder.h | 6 +++--- 5 files changed, 22 insertions(+), 16 deletions(-) diff --git a/pattern.c b/pattern.c index 12f6d77..4bfe66c 100644 --- a/pattern.c +++ b/pattern.c @@ -222,7 +222,7 @@ pattern_match_capture(struct pattern_config *pc, pattern_spec ps, captures++; if (PS_PF(CAPTURE, LADDER)) - f->payload |= is_ladder(b, m->coord, g) << PF_CAPTURE_LADDER; + f->payload |= is_ladder(b, m->coord, g, true) << PF_CAPTURE_LADDER; /* TODO: is_ladder() is too conservative in some * very obvious situations, look at complete.gtp. */ @@ -334,7 +334,7 @@ pattern_match_aescape(struct pattern_config *pc, pattern_spec ps, in_atari = g; if (PS_PF(AESCAPE, LADDER)) - f->payload |= is_ladder(b, m->coord, g) << PF_AESCAPE_LADDER; + f->payload |= is_ladder(b, m->coord, g, true) << PF_AESCAPE_LADDER; /* TODO: is_ladder() is too conservative in some * very obvious situations, look at complete.gtp. */ @@ -376,7 +376,7 @@ pattern_match_atari(struct pattern_config *pc, pattern_spec ps, coord_t lib = board_group_other_lib(b, g, m->coord); /* TODO: is_ladder() is too conservative in some * very obvious situations, look at complete.gtp. */ - f->payload |= is_ladder(b, lib, g) << PF_ATARI_LADDER; + f->payload |= is_ladder(b, lib, g, true) << PF_ATARI_LADDER; } if (PS_PF(ATARI, KO) && !is_pass(b->ko.coord)) diff --git a/playout/moggy.c b/playout/moggy.c index 2e21839..ec51d87 100644 --- a/playout/moggy.c +++ b/playout/moggy.c @@ -63,6 +63,9 @@ struct moggy_policy { /* Whether, when self-atari attempt is detected, to play the other * group's liberty if that is non-self-atari. */ bool selfatari_other; + /* Whether to read out ladders elsewhere than near the board + * in the playouts. */ + bool middle_ladder; /* 1lib settings: */ /* Whether to always pick from moves capturing all groups in @@ -177,7 +180,7 @@ test_pattern3_here(struct playout_policy *p, struct board *b, struct move *m) return false; /* Ladder moves are stupid. */ group_t atari_neighbor = board_get_atari_neighbor(b, m->coord, m->color); - if (atari_neighbor && is_ladder(b, m->coord, atari_neighbor) + if (atari_neighbor && is_ladder(b, m->coord, atari_neighbor, pp->middle_ladder) && !can_countercapture(b, board_at(b, group_base(atari_neighbor)), atari_neighbor, m->color, NULL, 0)) return false; @@ -248,7 +251,7 @@ global_atari_check(struct playout_policy *p, struct board *b, enum stone to_play struct moggy_policy *pp = p->data; if (pp->capcheckall) { for (int g = 0; g < b->clen; g++) - group_atari_check(pp->alwaysccaprate, b, group_at(b, group_base(b->c[g])), to_play, q, NULL, 1<alwaysccaprate, b, group_at(b, group_base(b->c[g])), to_play, q, NULL, pp->middle_ladder, 1<clen); for (int g = g_base; g < b->clen; g++) { - group_atari_check(pp->alwaysccaprate, b, group_at(b, group_base(b->c[g])), to_play, q, NULL, 1<alwaysccaprate, b, group_at(b, group_base(b->c[g])), to_play, q, NULL, pp->middle_ladder, 1<moves > 0) { /* XXX: Try carrying on. */ if (PLDEBUGL(5)) @@ -265,7 +268,7 @@ global_atari_check(struct playout_policy *p, struct board *b, enum stone to_play } } for (int g = 0; g < g_base; g++) { - group_atari_check(pp->alwaysccaprate, b, group_at(b, group_base(b->c[g])), to_play, q, NULL, 1<alwaysccaprate, b, group_at(b, group_base(b->c[g])), to_play, q, NULL, pp->middle_ladder, 1<moves > 0) { /* XXX: Try carrying on. */ if (PLDEBUGL(5)) @@ -283,14 +286,14 @@ local_atari_check(struct playout_policy *p, struct board *b, struct move *m, str /* Did the opponent play a self-atari? */ if (board_group_info(b, group_at(b, m->coord)).libs == 1) { - group_atari_check(pp->alwaysccaprate, b, group_at(b, m->coord), stone_other(m->color), q, NULL, 1<alwaysccaprate, b, group_at(b, m->coord), stone_other(m->color), q, NULL, pp->middle_ladder, 1<coord, { group_t g = group_at(b, c); if (!g || board_group_info(b, g).libs != 1) continue; - group_atari_check(pp->alwaysccaprate, b, g, stone_other(m->color), q, NULL, 1<alwaysccaprate, b, g, stone_other(m->color), q, NULL, pp->middle_ladder, 1<alwaysccaprate, b, g, map->to_play, &q, &ladder, 0); + group_atari_check(pp->alwaysccaprate, b, g, map->to_play, &q, &ladder, true, 0); while (q.moves--) { coord_t coord = q.move[q.moves]; @@ -937,6 +940,7 @@ 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->middle_ladder = true; pp->cap_stone_min = 2; pp->cap_stone_max = 15; @@ -1020,6 +1024,8 @@ playout_moggy_init(char *arg, struct board *b, struct joseki_dict *jdict) pp->atari_def_no_hopeless = optval && *optval == '0' ? false : true; } else if (!strcasecmp(optname, "nlib_count") && optval) { pp->nlib_count = atoi(optval); + } else if (!strcasecmp(optname, "middle_ladder")) { + pp->middle_ladder = 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/1lib.c b/tactics/1lib.c index efb0df4..4ad1b49 100644 --- a/tactics/1lib.c +++ b/tactics/1lib.c @@ -90,7 +90,7 @@ can_be_rescued(struct board *b, group_t group, enum stone color, int tag) void group_atari_check(unsigned int alwaysccaprate, struct board *b, group_t group, enum stone to_play, - struct move_queue *q, coord_t *ladder, int tag) + struct move_queue *q, coord_t *ladder, bool middle_ladder, int tag) { enum stone color = board_at(b, group_base(group)); coord_t lib = board_group_info(b, group).lib[0]; @@ -134,7 +134,7 @@ group_atari_check(unsigned int alwaysccaprate, struct board *b, group_t group, e /* ...or play out ladders (unless we can counter-capture anytime). */ if (!ccap) { - if (is_ladder(b, lib, group)) { + if (is_ladder(b, lib, group, middle_ladder)) { /* Sometimes we want to keep the ladder move in the * queue in order to discourage it. */ if (!ladder) diff --git a/tactics/1lib.h b/tactics/1lib.h index 9899caa..a9a0024 100644 --- a/tactics/1lib.h +++ b/tactics/1lib.h @@ -19,6 +19,6 @@ bool can_countercapture(struct board *b, enum stone owner, group_t g, * @to_play to deal with it (rescuing or capturing it). */ /* ladder != NULL implies to always enqueue all relevant moves. */ void group_atari_check(unsigned int alwaysccaprate, struct board *b, group_t group, enum stone to_play, - struct move_queue *q, coord_t *ladder, int tag); + struct move_queue *q, coord_t *ladder, bool middle_ladder, int tag); #endif diff --git a/tactics/ladder.h b/tactics/ladder.h index 870b383..dc5d66a 100644 --- a/tactics/ladder.h +++ b/tactics/ladder.h @@ -10,7 +10,7 @@ * a simple ladder. */ /* Two ways of ladder reading can be enabled separately; simple first-line * ladders and trivial middle-board ladders. */ -static bool is_ladder(struct board *b, coord_t coord, group_t laddered); +static bool is_ladder(struct board *b, coord_t coord, group_t laddered, bool test_middle); /* Check if a 2-lib group of color @lcolor escaping at @escapelib would be * caught in a ladder given opponent stone at @chaselib. */ @@ -20,7 +20,7 @@ bool wouldbe_ladder(struct board *b, coord_t escapelib, coord_t chaselib, enum s bool is_border_ladder(struct board *b, coord_t coord, enum stone lcolor); bool is_middle_ladder(struct board *b, coord_t coord, enum stone lcolor); static inline bool -is_ladder(struct board *b, coord_t coord, group_t laddered) +is_ladder(struct board *b, coord_t coord, group_t laddered, bool test_middle) { enum stone lcolor = board_at(b, group_base(laddered)); @@ -37,7 +37,7 @@ is_ladder(struct board *b, coord_t coord, group_t laddered) return l; } - bool l = is_middle_ladder(b, coord, lcolor); + bool l = test_middle && is_middle_ladder(b, coord, lcolor); if (DEBUGL(6)) fprintf(stderr, "middle ladder solution: %d\n", l); return l; } -- 2.11.4.GIT