Moggy group_2lib_check(): Gain liberties by capturing
[pachi/derm.git] / uct / search.h
blob37eb52495617f72f0de6268a31da458387b1c81f
1 #ifndef ZZGO_UCT_SEARCH_H
2 #define ZZGO_UCT_SEARCH_H
4 /* MCTS Search infrastructure. We juggle the search threads and
5 * control search duration. */
7 /* uct.c provides the GTP interface and engine setup. */
8 /* walk.c controls repeated walking of the MCTS tree within
9 * the search threads. */
11 #include <signal.h> // sig_atomic_t
13 #include "debug.h"
14 #include "move.h"
15 #include "ownermap.h"
16 #include "playout.h"
17 #include "timeinfo.h"
18 #include "uct/internal.h"
20 struct tree;
21 struct tree_node;
23 /* Internal UCT structures */
25 /* How often to inspect the tree from the main thread to check for playout
26 * stop, progress reports, etc. (in seconds) */
27 #define TREE_BUSYWAIT_INTERVAL 0.1 /* 100ms */
30 /* Thread manager state */
31 extern volatile sig_atomic_t uct_halt;
32 extern __thread int thread_id;
33 extern bool thread_manager_running;
35 /* Search thread context */
36 struct uct_thread_ctx {
37 int tid;
38 struct uct *u;
39 struct board *b;
40 enum stone color;
41 struct tree *t;
42 unsigned long seed;
43 int games;
47 /* Progress information of the on-going MCTS search - when did we
48 * last adjusted dynkomi, printed out stuff, etc. */
49 struct uct_search_state {
50 /* Number of games simulated for this simulation before
51 * we started the search. (We have simulated them earlier.) */
52 int base_playouts;
53 /* Number of last dynkomi adjustment. */
54 int last_dynkomi;
55 /* Number of last game with progress print. */
56 int last_print;
57 /* Number of simulations to wait before next print. */
58 int print_interval;
59 /* Printed notification about full memory? */
60 bool fullmem;
62 struct time_stop stop;
63 struct uct_thread_ctx *ctx;
66 int uct_search_games(struct uct_search_state *s);
68 void uct_search_start(struct uct *u, struct board *b, enum stone color, struct tree *t, struct time_info *ti, struct uct_search_state *s);
69 struct uct_thread_ctx *uct_search_stop(void);
71 void uct_search_progress(struct uct *u, struct board *b, enum stone color, struct tree *t, struct time_info *ti, struct uct_search_state *s, int i);
73 bool uct_search_check_stop(struct uct *u, struct board *b, enum stone color, struct tree *t, struct time_info *ti, struct uct_search_state *s, int i);
75 struct tree_node *uct_search_result(struct uct *u, struct board *b, enum stone color, bool pass_all_alive, int played_games, int base_playouts, coord_t *best_coord);
77 #endif