From 9c8a096e0f972a7faab9329c25d13e84724a98d3 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Sun, 13 Feb 2011 16:02:47 +0100 Subject: [PATCH] UCT local_tree_depth_decay: Apply based on start of sub-sequence, not end of descent --- uct/walk.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/uct/walk.c b/uct/walk.c index 37878f5..3b6f674 100644 --- a/uct/walk.c +++ b/uct/walk.c @@ -203,8 +203,10 @@ scale_value(struct uct *u, struct board *b, int result) static void record_local_sequence(struct uct *u, struct tree *t, struct uct_descent *descent, int dlen, int di, - enum stone seq_color, floating_t rval, int pval) + enum stone seq_color, floating_t rval) { +#define LTREE_DEBUG if (UDEBUGL(6)) + /* Ignore pass sequences. */ if (is_pass(descent[di].node->coord)) return; @@ -216,16 +218,24 @@ record_local_sequence(struct uct *u, struct tree *t, rval = stats_temper_value(rval, expval, u->local_tree); } -#define LTREE_DEBUG if (UDEBUGL(6)) LTREE_DEBUG fprintf(stderr, "recording result %f in local %s sequence: ", rval, stone2str(seq_color)); - int di0 = di; + + /* Sequences starting deeper are less relevant in general. */ + int pval = LTREE_PLAYOUTS_MULTIPLIER; + if (u->local_tree && u->local_tree_depth_decay > 0) + pval = ((floating_t) pval) / pow(u->local_tree_depth_decay, di - 1); + if (!pval) { + LTREE_DEBUG fprintf(stderr, "too deep @%d\n", di); + return; + } /* Pick the right local tree root... */ struct tree_node *lnode = seq_color == S_BLACK ? t->ltree_black : t->ltree_white; lnode->u.playouts++; /* ...and record the sequence. */ + int di0 = di; while (di < dlen && (di == di0 || descent[di].node->d < u->tenuki_d)) { LTREE_DEBUG fprintf(stderr, "%s[%d] ", coord2sstr(descent[di].node->coord, t->board), @@ -420,10 +430,6 @@ uct_playout(struct uct *u, struct board *b, enum stone player_color, struct tree floating_t rval = scale_value(u, b, result); u->policy->update(u->policy, t, n, node_color, player_color, amaf, rval); - int pval = LTREE_PLAYOUTS_MULTIPLIER; - if (u->local_tree && u->local_tree_depth_decay > 0) - pval = ((floating_t) pval) / pow(u->local_tree_depth_decay, dlen); - if (t->use_extra_komi) { stats_add_result(&u->dynkomi->score, result / 2, 1); stats_add_result(&u->dynkomi->value, rval, 1); @@ -444,22 +450,22 @@ uct_playout(struct uct *u, struct board *b, enum stone player_color, struct tree * which is expected as it will create new lnodes. */ enum stone seq_color = player_color; /* First move always starts a sequence. */ - record_local_sequence(u, t, descent, dlen, 1, seq_color, rval, pval); + record_local_sequence(u, t, descent, dlen, 1, seq_color, rval); seq_color = stone_other(seq_color); for (int dseqi = 2; dseqi < dlen; dseqi++, seq_color = stone_other(seq_color)) { if (u->local_tree_allseq) { /* We are configured to record all subsequences. */ - record_local_sequence(u, t, descent, dlen, dseqi, seq_color, rval, pval); + record_local_sequence(u, t, descent, dlen, dseqi, seq_color, rval); continue; } if (descent[dseqi].node->d >= u->tenuki_d) { /* Tenuki! Record the fresh sequence. */ - record_local_sequence(u, t, descent, dlen, dseqi, seq_color, rval, pval); + record_local_sequence(u, t, descent, dlen, dseqi, seq_color, rval); continue; } if (descent[dseqi].lnode && !descent[dseqi].lnode) { /* Record result for in-descent picked sequence. */ - record_local_sequence(u, t, descent, dlen, dseqi, seq_color, rval, pval); + record_local_sequence(u, t, descent, dlen, dseqi, seq_color, rval); continue; } } -- 2.11.4.GIT