From f510dd7b3ff696a80d674b67a2fabdd969e845de Mon Sep 17 00:00:00 2001 From: Jean-loup Gailly Date: Sat, 6 Aug 2011 16:35:30 +0200 Subject: [PATCH] uctp_generic_choose(): call expensive uct_pass_is_safe() only if pass is the best move --- uct/policy/generic.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/uct/policy/generic.c b/uct/policy/generic.c index 0f1621b..6784421 100644 --- a/uct/policy/generic.c +++ b/uct/policy/generic.c @@ -15,22 +15,27 @@ struct tree_node * uctp_generic_choose(struct uct_policy *p, struct tree_node *node, struct board *b, enum stone color, coord_t exclude) { - struct tree_node *nbest = NULL; + struct tree_node *nbest = node->children; + if (!nbest) return NULL; + struct tree_node *nbest2 = NULL; + /* This function is called while the tree is updated by other threads. * We rely on node->children being set only after the node has been fully expanded. */ - for (struct tree_node *ni = node->children; ni; ni = ni->sibling) + for (struct tree_node *ni = nbest->sibling; ni; ni = ni->sibling) // we compare playouts and choose the best-explored // child; comparing values is more brittle - if (!nbest || ni->u.playouts > nbest->u.playouts) { + if (ni->u.playouts > nbest->u.playouts) { if (node_coord(ni) == exclude) continue; if (ni->hints & TREE_HINT_INVALID) continue; - /* Play pass only if we can afford scoring */ - if (is_pass(node_coord(ni)) && !uct_pass_is_safe(p->uct, b, color, p->uct->pass_all_alive)) - continue; + nbest2 = nbest; nbest = ni; } + /* Play pass only if we can afford scoring. Call expensive uct_pass_is_safe() only if + * pass is indeed the best move. */ + if (is_pass(node_coord(nbest)) && !uct_pass_is_safe(p->uct, b, color, p->uct->pass_all_alive)) + return nbest2; return nbest; } -- 2.11.4.GIT