From 7ec040a08b1d474983c0f50a154ca60c40fbd313 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Sat, 8 Mar 2008 12:23:59 +0100 Subject: [PATCH] UCT: Play pass only when we are ready to score --- uct/tree.c | 16 +++++++++++++--- uct/tree.h | 2 +- uct/uct.c | 5 +++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/uct/tree.c b/uct/tree.c index 59a40f8..7097987 100644 --- a/uct/tree.c +++ b/uct/tree.c @@ -142,14 +142,24 @@ tree_leaf_node(struct tree_node *node) } struct tree_node * -tree_best_child(struct tree_node *node) +tree_best_child(struct tree_node *node, struct board *b, enum stone color) { - struct tree_node *nbest = node->children; + struct tree_node *nbest = NULL; for (struct tree_node *ni = node->children; ni; ni = ni->sibling) // we compare playouts and choose the best-explored // child; comparing values is more brittle - if (ni->playouts > nbest->playouts) + if (!nbest || ni->playouts > nbest->playouts) { + /* Play pass only if we can afford scoring */ + if (is_pass(ni->coord)) { + float score = board_fast_score(b); + if (color == S_BLACK) + score = -score; + //fprintf(stderr, "%d score %f\n", b->last_move.color, score); + if (score <= 0) + continue; + } nbest = ni; + } return nbest; } diff --git a/uct/tree.h b/uct/tree.h index 895622d..8da33f4 100644 --- a/uct/tree.h +++ b/uct/tree.h @@ -47,7 +47,7 @@ void tree_expand_node(struct tree *tree, struct tree_node *node, struct board *b void tree_delete_node(struct tree_node *node); void tree_promote_node(struct tree *tree, struct tree_node *node); bool tree_leaf_node(struct tree_node *node); -struct tree_node *tree_best_child(struct tree_node *node); +struct tree_node *tree_best_child(struct tree_node *node, struct board *b, enum stone color); struct tree_node *tree_uct_descend(struct tree *tree, struct tree_node *node, int parity, bool allow_pass); void tree_uct_update(struct tree_node *node, int result); diff --git a/uct/uct.c b/uct/uct.c index 7ef5591..d227aeb 100644 --- a/uct/uct.c +++ b/uct/uct.c @@ -114,6 +114,7 @@ uct_genmove(struct engine *e, struct board *b, enum stone color) if (!u->t) { tree_init: u->t = tree_init(b); + //board_print(b, stderr); u->t->explore_p = u->explore_p; } else { /* XXX: We hope that the opponent didn't suddenly play @@ -138,7 +139,7 @@ promoted:; } if (i > 0 && !(i % 1000)) { - struct tree_node *best = tree_best_child(u->t->root); + struct tree_node *best = tree_best_child(u->t->root, b, color); if (best && best->playouts >= 500 && ((is_pass(best->coord) && best->value == 1.0) || best->value >= u->loss_threshold)) @@ -149,7 +150,7 @@ promoted:; if (UDEBUGL(2)) tree_dump(u->t); - struct tree_node *best = tree_best_child(u->t->root); + struct tree_node *best = tree_best_child(u->t->root, b, color); if (!best) { tree_done(u->t); u->t = NULL; return coord_copy(pass); -- 2.11.4.GIT