From 95761281a353a8b166a473da21ed1e7eb9655b46 Mon Sep 17 00:00:00 2001 From: Jean-loup Gailly Date: Wed, 10 Aug 2011 16:54:45 +0200 Subject: [PATCH] UCT node allocation: fix 18d0f99 for fast_alloc=0 Thanks to Pasky for reporting this bug. --- uct/tree.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/uct/tree.c b/uct/tree.c index 492e185..8d0687b 100644 --- a/uct/tree.c +++ b/uct/tree.c @@ -602,8 +602,8 @@ tree_expand_node(struct tree *t, struct tree_node *node, struct board *b, enum s } foreach_free_point_end; uct_prior(u, node, &map); - /* Now, create the nodes. */ - struct tree_node *ni = tree_alloc_node(t, child_count, t->nodes); + /* Now, create the nodes (all at once if fast_alloc) */ + struct tree_node *ni = t->nodes ? tree_alloc_node(t, child_count, true) : tree_alloc_node(t, 1, false); /* In fast_alloc mode we might temporarily run out of nodes but this should be rare. */ if (!ni) { node->is_expanded = false; @@ -640,7 +640,7 @@ tree_expand_node(struct tree *t, struct tree_node *node, struct board *b, enum s continue; assert(c != node_coord(node)); // I have spotted "C3 C3" in some sequence... - struct tree_node *nj = first_child + child++; + struct tree_node *nj = t->nodes ? first_child + child++ : tree_alloc_node(t, 1, false); tree_setup_node(t, nj, c, node->depth + 1); nj->parent = node; ni->sibling = nj; ni = nj; @@ -648,10 +648,6 @@ tree_expand_node(struct tree *t, struct tree_node *node, struct board *b, enum s ni->d = distances[c]; } } - if (b->symmetry.type == SYM_NONE && child != child_count) { - fprintf(stderr, "child %d child_count %d\n", child, child_count); - assert(child == child_count); - } node->children = first_child; // must be done at the end to avoid race } -- 2.11.4.GIT