-
Notifications
You must be signed in to change notification settings - Fork 16
/
UCTSearch.h
85 lines (74 loc) · 2.28 KB
/
UCTSearch.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#ifndef UCTSEARCH_H_INCLUDED
#define UCTSEARCH_H_INCLUDED
#include <memory>
#include <atomic>
#include <tuple>
#include "GameState.h"
#include "UCTNode.h"
#include "Playout.h"
class UCTSearch {
public:
/*
Depending on rule set and state of the game, we might
prefer to pass, or we might prefer not to pass unless
it's the last resort. Same for resigning.
*/
typedef int passflag_t;
static const passflag_t NORMAL = 0;
static const passflag_t NOPASS = 1 << 0;
static const passflag_t NORESIGN = 1 << 1;
/*
Maximum size of the tree in memory.
*/
static constexpr int MAX_TREE_SIZE = 10000000;
UCTSearch(GameState & g);
int think(int color, passflag_t passflag = NORMAL);
void set_playout_limit(int playouts);
void set_use_nets(bool usenets);
void set_runflag(std::atomic<bool> * flag);
void set_analyzing(bool flag);
void set_quiet(bool flag);
void ponder();
bool is_running();
bool playout_limit_reached();
void increment_playouts();
Playout play_simulation(KoState & currstate, UCTNode * const node);
std::tuple<float, float, float> get_scores();
private:
void dump_stats(KoState & state, UCTNode & parent);
void dump_GUI_stats(GameState & state, UCTNode & parent);
std::string get_pv(KoState & state, UCTNode & parent);
void dump_thinking();
void dump_analysis();
void dump_order2(void);
int get_best_move(passflag_t passflag);
int get_best_move_nosearch(std::vector<std::pair<float, int>> moves,
float score, passflag_t passflag);
bool allow_early_exit();
bool allow_easy_move();
bool easy_move_precondition();
GameState & m_rootstate;
UCTNode m_root;
std::atomic<int> m_nodes;
std::atomic<int> m_playouts;
std::atomic<bool> m_run;
int m_maxplayouts;
// For external control
bool m_hasrunflag;
std::atomic<bool> * m_runflag;
// Special modes
bool m_use_nets;
bool m_analyzing;
bool m_quiet;
};
class UCTWorker {
public:
UCTWorker(GameState & state, UCTSearch * search, UCTNode * root)
: m_rootstate(state), m_search(search), m_root(root) {};
void operator()();
private:
GameState & m_rootstate;
UCTSearch * m_search;
UCTNode * m_root;
};
#endif