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
18 #include "uct/internal.h"
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 bool thread_manager_running
;
34 /* Search thread context */
35 struct uct_thread_ctx
{
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.) */
53 /* Number of last dynkomi adjustment. */
55 /* Number of last game with progress print. */
57 /* Number of simulations to wait before next print. */
59 /* Printed notification about full memory? */
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
);