tree_fix_symmetry(): Rewrite, was totally bogus
[pachi.git] / uct / tree.h
blobbdafef23b730739eed15dbe8aeb822d6ae49714d
1 #ifndef ZZGO_UCT_TREE_H
2 #define ZZGO_UCT_TREE_H
4 #include <stdbool.h>
5 #include "move.h"
7 struct board;
8 struct uct_policy;
11 * +------+
12 * | node |
13 * +------+
14 * / <- parent
15 * +------+ v- sibling +------+
16 * | node | ------------ | node |
17 * +------+ +------+
18 * | <- children |
19 * +------+ +------+ +------+ +------+
20 * | node | - | node | | node | - | node |
21 * +------+ +------+ +------+ +------+
24 struct move_stats {
25 int playouts; // # of playouts coming through this node
26 int wins; // # of wins coming through this node
27 float value; // wins/playouts
30 struct tree_node {
31 hash_t hash;
32 struct tree_node *parent, *sibling, *children;
34 /*** From here on, struct is saved/loaded from opening book */
36 int depth; // just for statistics
38 coord_t coord;
40 struct move_stats u;
41 struct move_stats prior;
42 /* XXX: Should be way for policies to add their own stats */
43 struct move_stats amaf;
44 int hints;
47 struct tree {
48 struct board *board;
49 struct tree_node *root;
50 struct board_symmetry root_symmetry;
52 // Statistics
53 int max_depth;
56 struct tree *tree_init(struct board *board, enum stone color);
57 void tree_done(struct tree *tree);
58 void tree_dump(struct tree *tree, int thres);
59 void tree_save(struct tree *tree, struct board *b, int thres);
60 void tree_load(struct tree *tree, struct board *b);
62 void tree_expand_node(struct tree *tree, struct tree_node *node, struct board *b, enum stone color, int radar, struct uct_policy *policy, int parity);
63 void tree_delete_node(struct tree *tree, struct tree_node *node);
64 void tree_promote_node(struct tree *tree, struct tree_node *node);
65 bool tree_promote_at(struct tree *tree, struct board *b, coord_t c);
66 bool tree_leaf_node(struct tree_node *node);
67 void tree_update_node_value(struct tree_node *node, bool add_amaf);
69 #endif