UCT bestr_ratio: Implement to deal with confused playouts
[pachi.git] / uct / internal.h
blob32379f182755030e1a7f9724b2f712c0999ea112
1 #ifndef ZZGO_UCT_INTERNAL_H
2 #define ZZGO_UCT_INTERNAL_H
4 #include <signal.h> // sig_atomic_t
6 #include "debug.h"
7 #include "move.h"
8 #include "ownermap.h"
9 #include "playout.h"
11 struct tree;
12 struct tree_node;
13 struct uct_policy;
14 struct uct_prior;
16 /* Internal UCT structures */
19 /* Internal engine state. */
20 struct uct {
21 int debug_level;
22 int games, gamelen;
23 float resign_ratio;
24 float loss_threshold;
25 double best2_ratio, bestr_ratio;
26 bool pass_all_alive;
27 int expand_p;
28 bool playout_amaf, playout_amaf_nakade;
29 bool amaf_prior;
30 int playout_amaf_cutoff;
31 int dumpthres;
32 int force_seed;
33 bool no_book;
34 bool fast_alloc;
35 unsigned long max_tree_size;
36 int mercymin;
38 int threads;
39 enum uct_thread_model {
40 TM_ROOT, /* Root parallelization. */
41 TM_TREE, /* Tree parallelization w/o virtual loss. */
42 TM_TREEVL, /* Tree parallelization with virtual loss. */
43 } thread_model;
44 bool parallel_tree;
45 bool virtual_loss;
46 bool pondering_opt; /* User wants pondering */
47 bool pondering; /* Actually pondering now */
49 int fuseki_end;
50 int yose_start;
52 int dynkomi;
53 int dynkomi_mask;
55 float val_scale;
56 int val_points;
57 bool val_extra;
59 int random_policy_chance;
60 int root_heuristic;
62 char *banner;
64 struct uct_policy *policy;
65 struct uct_policy *random_policy;
66 struct playout_policy *playout;
67 struct uct_prior *prior;
69 /* Used within frame of single genmove. */
70 struct board_ownermap ownermap;
72 /* Game state - maintained by setup_state(), reset_state(). */
73 struct tree *t;
76 #define UDEBUGL(n) DEBUGL_(u->debug_level, n)
78 extern volatile sig_atomic_t uct_halt;
79 extern __thread int thread_id;
81 bool uct_pass_is_safe(struct uct *u, struct board *b, enum stone color, bool pass_all_alive);
84 typedef struct tree_node *(*uctp_choose)(struct uct_policy *p, struct tree_node *node, struct board *b, enum stone color, coord_t exclude);
85 typedef struct tree_node *(*uctp_winner)(struct uct_policy *p, struct tree *tree, struct tree_node *node);
86 typedef float (*uctp_evaluate)(struct uct_policy *p, void **state, struct tree *tree, struct tree_node *node, int parity);
87 typedef struct tree_node *(*uctp_descend)(struct uct_policy *p, void **state, struct tree *tree, struct tree_node *node, int parity, bool allow_pass);
88 typedef void (*uctp_prior)(struct uct_policy *p, struct tree *tree, struct tree_node *node, struct board *b, enum stone color, int parity);
89 typedef void (*uctp_update)(struct uct_policy *p, struct tree *tree, struct tree_node *node, enum stone node_color, enum stone player_color, struct playout_amafmap *amaf, float result);
91 struct uct_policy {
92 struct uct *uct;
93 uctp_choose choose;
94 uctp_winner winner;
95 uctp_evaluate evaluate;
96 uctp_descend descend;
97 uctp_update update;
98 uctp_prior prior;
99 bool wants_amaf;
100 void *data;
103 #endif