1 #ifndef ZZGO_UCT_TREE_H
2 #define ZZGO_UCT_TREE_H
16 * +------+ v- sibling +------+
17 * | node | ------------ | node |
20 * +------+ +------+ +------+ +------+
21 * | node | - | node | | node | - | node |
22 * +------+ +------+ +------+ +------+
27 struct tree_node
*parent
, *sibling
, *children
;
29 /*** From here on, struct is saved/loaded from opening book */
31 int depth
; // just for statistics
36 struct move_stats prior
;
37 /* XXX: Should be way for policies to add their own stats */
38 struct move_stats amaf
;
39 /* Stats before starting playout; used for multi-thread normalization. */
40 struct move_stats pu
, pamaf
;
46 struct tree_node
*root
;
47 struct board_symmetry root_symmetry
;
48 enum stone root_color
;
54 struct tree
*tree_init(struct board
*board
, enum stone color
);
55 void tree_done(struct tree
*tree
);
56 void tree_dump(struct tree
*tree
, int thres
);
57 void tree_save(struct tree
*tree
, struct board
*b
, int thres
);
58 void tree_load(struct tree
*tree
, struct board
*b
);
59 struct tree
*tree_copy(struct tree
*tree
);
60 void tree_merge(struct tree
*dest
, struct tree
*src
);
61 void tree_normalize(struct tree
*tree
, int factor
);
63 void tree_expand_node(struct tree
*tree
, struct tree_node
*node
, struct board
*b
, enum stone color
, int radar
, struct uct
*u
, int parity
);
64 void tree_delete_node(struct tree
*tree
, struct tree_node
*node
);
65 void tree_promote_node(struct tree
*tree
, struct tree_node
*node
);
66 bool tree_promote_at(struct tree
*tree
, struct board
*b
, coord_t c
);
68 static bool tree_leaf_node(struct tree_node
*node
);
70 /* Get black parity from parity within the tree. */
71 #define tree_parity(tree, parity) \
72 (tree->root_color == S_WHITE ? (parity) : -1 * (parity))
74 /* Get a value to maximize; @parity is parity within the tree. */
75 #define tree_node_get_value(tree, node, type, parity) \
76 (tree_parity(tree, parity) > 0 ? node->type.value : 1 - node->type.value)
77 #define tree_node_get_wins(tree, node, type, parity) \
78 (tree_parity(tree, parity) > 0 ? node->type.wins : node->type.playouts - node->type.wins)
81 tree_leaf_node(struct tree_node
*node
)
83 return !(node
->children
);