From 1b27436c39fe35cf57e9c9dd88763120bc3122ca Mon Sep 17 00:00:00 2001 From: Jean-loup Gailly Date: Thu, 30 Dec 2010 20:02:06 +0100 Subject: [PATCH] UCT engine: change virtual_loss from bool to int --- uct/internal.h | 2 +- uct/uct.c | 8 +++++--- uct/walk.c | 8 ++++---- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/uct/internal.h b/uct/internal.h index 64614a4..0afe868 100644 --- a/uct/internal.h +++ b/uct/internal.h @@ -51,7 +51,7 @@ struct uct { TM_TREE, /* Tree parallelization w/o virtual loss. */ TM_TREEVL, /* Tree parallelization with virtual loss. */ } thread_model; - bool virtual_loss; + int virtual_loss; bool pondering_opt; /* User wants pondering */ bool pondering; /* Actually pondering now */ bool slave; /* Act as slave in distributed engine. */ diff --git a/uct/uct.c b/uct/uct.c index b37a749..49820b0 100644 --- a/uct/uct.c +++ b/uct/uct.c @@ -538,7 +538,7 @@ uct_state_init(char *arg, struct board *b) u->threads = 1; u->thread_model = TM_TREEVL; - u->virtual_loss = true; + u->virtual_loss = 1; u->fuseki_end = 20; // max time at 361*20% = 72 moves (our 36th move, still 99 to play) u->yose_start = 40; // (100-40-25)*361/100/2 = 63 moves still to play by us then @@ -741,18 +741,20 @@ uct_state_init(char *arg, struct board *b) /* Tree parallelization - all threads * grind on the same tree. */ u->thread_model = TM_TREE; - u->virtual_loss = false; + u->virtual_loss = 0; } else if (!strcasecmp(optval, "treevl")) { /* Tree parallelization, but also * with virtual losses - this discou- * rages most threads choosing the * same tree branches to read. */ u->thread_model = TM_TREEVL; - u->virtual_loss = true; } else { fprintf(stderr, "UCT: Invalid thread model %s\n", optval); exit(1); } + } else if (!strcasecmp(optname, "virtual_loss")) { + /* Number of virtual losses added before evaluating a node. */ + u->virtual_loss = !optval || atoi(optval); } else if (!strcasecmp(optname, "pondering")) { /* Keep searching even during opponent's turn. */ u->pondering_opt = !optval || atoi(optval); diff --git a/uct/walk.c b/uct/walk.c index 1dc42e4..1ded011 100644 --- a/uct/walk.c +++ b/uct/walk.c @@ -523,7 +523,7 @@ uct_playout(struct uct *u, struct board *b, enum stone player_color, struct tree * other threads from visiting this node in case of multiple * threads doing the tree search. */ if (u->virtual_loss) - stats_add_result(&n->u, tree_parity(t, parity) > 0 ? 0 : 1, 1); + stats_add_result(&n->u, node_color == S_BLACK ? 0.0 : 1.0, u->virtual_loss); assert(n->coord >= -1); if (amaf && !is_pass(n->coord)) @@ -652,10 +652,10 @@ uct_playout(struct uct *u, struct board *b, enum stone player_color, struct tree end: /* We need to undo the virtual loss we added during descend. */ if (u->virtual_loss) { - int parity = (node_color == player_color ? 1 : -1); + floating_t loss = node_color == S_BLACK ? 0.0 : 1.0; for (; n->parent; n = n->parent) { - stats_rm_result(&n->u, tree_parity(t, parity) > 0 ? 0 : 1, 1); - parity = -parity; + stats_rm_result(&n->u, loss, u->virtual_loss); + loss = 1.0 - loss; } } -- 2.11.4.GIT