Merge pull request #50 from lemonsqueeze/can_countercap
[pachi.git] / uct / search.h
blob6ee817847b478481c978a5dbec2f95624d68447f
1 #ifndef PACHI_UCT_SEARCH_H
2 #define PACHI_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 bool thread_manager_running;
34 /* Search thread context */
35 struct uct_thread_ctx {
36 int tid;
37 struct uct *u;
38 struct board *b;
39 enum stone color;
40 struct tree *t;
41 unsigned long seed;
42 int games;
43 struct time_info *ti;
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