From 6f996b193400195c651c2d5a9cc1b721d979ad39 Mon Sep 17 00:00:00 2001 From: Jean-loup Gailly Date: Sat, 6 Aug 2011 19:05:32 +0200 Subject: [PATCH] uct_pass_is_safe(): force minimum number of playouts This allows pass when it is the only sensible move (all other moves lose). Bug reported by Michael Williams. --- uct/search.c | 25 +++++++++++-------------- uct/uct.c | 5 +++-- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/uct/search.c b/uct/search.c index 7fc035e..c66cc16 100644 --- a/uct/search.c +++ b/uct/search.c @@ -479,20 +479,17 @@ uct_search_result(struct uct *u, struct board *b, enum stone color, } /* If the opponent just passed and we win counting, always - * pass as well. */ - if (b->moves > 1 && is_pass(b->last_move.coord) && b->rules != RULES_STONES_ONLY) { - /* Make sure enough playouts are simulated. */ - while (u->ownermap.playouts < GJ_MINGAMES) - uct_playout(u, b, color, u->t); - if (uct_pass_is_safe(u, b, color, pass_all_alive)) { - if (UDEBUGL(0)) - fprintf(stderr, "\n", - board_official_score(b, NULL) / 2); - *best_coord = pass; - best = u->t->root->children; // pass is the first child - assert(is_pass(node_coord(best))); - return best; - } + * pass as well. For option stones_only, we pass only when there + * there is nothing else to do, to show how to maximize score. */ + if (b->moves > 1 && is_pass(b->last_move.coord) && b->rules != RULES_STONES_ONLY + && uct_pass_is_safe(u, b, color, pass_all_alive)) { + if (UDEBUGL(0)) + fprintf(stderr, "\n", + board_official_score(b, NULL) / 2); + *best_coord = pass; + best = u->t->root->children; // pass is the first child + assert(is_pass(node_coord(best))); + return best; } return best; diff --git a/uct/uct.c b/uct/uct.c index baee743..06f933f 100644 --- a/uct/uct.c +++ b/uct/uct.c @@ -106,8 +106,9 @@ dead_group_list(struct uct *u, struct board *b, struct move_queue *mq) bool uct_pass_is_safe(struct uct *u, struct board *b, enum stone color, bool pass_all_alive) { - if (u->ownermap.playouts < GJ_MINGAMES) - return false; + /* Make sure enough playouts are simulated to get a reasonable dead group list. */ + while (u->ownermap.playouts < GJ_MINGAMES) + uct_playout(u, b, color, u->t); struct move_queue mq = { .moves = 0 }; dead_group_list(u, b, &mq); -- 2.11.4.GIT