Fix previous fix on pass_limit.
[pachi/derm.git] / uct / internal.h
blob74d9979fbdc4ef6c877fca67821f6f25687611f9
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 bool pass_all_alive;
26 int expand_p;
27 bool playout_amaf, playout_amaf_nakade;
28 bool amaf_prior;
29 int playout_amaf_cutoff;
30 int dumpthres;
31 int force_seed;
32 bool no_book;
33 unsigned long max_tree_size;
34 int mercymin;
36 int threads;
37 enum uct_thread_model {
38 TM_ROOT, /* Root parallelization. */
39 TM_TREE, /* Tree parallelization w/o virtual loss. */
40 TM_TREEVL, /* Tree parallelization with virtual loss. */
41 } thread_model;
42 bool parallel_tree;
43 bool virtual_loss;
44 bool pondering_opt; /* User wants pondering */
45 bool pondering; /* Actually pondering now */
46 int fuseki_end;
47 int yose_start;
49 int dynkomi;
50 int dynkomi_mask;
52 float val_scale;
53 int val_points;
54 bool val_extra;
56 int random_policy_chance;
57 int root_heuristic;
59 char *banner;
61 struct uct_policy *policy;
62 struct uct_policy *random_policy;
63 struct playout_policy *playout;
64 struct uct_prior *prior;
66 /* Used within frame of single genmove. */
67 struct board_ownermap ownermap;
69 /* Game state - maintained by setup_state(), reset_state(). */
70 struct tree *t;
73 #define UDEBUGL(n) DEBUGL_(u->debug_level, n)
75 extern volatile sig_atomic_t uct_halt;
76 extern __thread int thread_id;
78 bool uct_pass_is_safe(struct uct *u, struct board *b, enum stone color, bool pass_all_alive);
81 typedef struct tree_node *(*uctp_choose)(struct uct_policy *p, struct tree_node *node, struct board *b, enum stone color);
82 typedef struct tree_node *(*uctp_winner)(struct uct_policy *p, struct tree *tree, struct tree_node *node);
83 typedef float (*uctp_evaluate)(struct uct_policy *p, void **state, struct tree *tree, struct tree_node *node, int parity);
84 typedef struct tree_node *(*uctp_descend)(struct uct_policy *p, void **state, struct tree *tree, struct tree_node *node, int parity, bool allow_pass);
85 typedef void (*uctp_prior)(struct uct_policy *p, struct tree *tree, struct tree_node *node, struct board *b, enum stone color, int parity);
86 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);
88 struct uct_policy {
89 struct uct *uct;
90 uctp_choose choose;
91 uctp_winner winner;
92 uctp_evaluate evaluate;
93 uctp_descend descend;
94 uctp_update update;
95 uctp_prior prior;
96 bool wants_amaf;
97 void *data;
100 #endif