Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 440 lines (371 sloc) 13.495 kB
302209c Commit the beginnings of a UCT MCTS player
Timo Ewalds authored
1
4f30f52 @tewalds Remove some the old children library as well as old time code, replac…
authored
2 #pragma once
302209c Commit the beginnings of a UCT MCTS player
Timo Ewalds authored
3
141e49f The player should first consult the solver for some tactics. Spend 20…
Timo Ewalds authored
4 #include <cmath>
9d34d4e Clean up keeping the subtree...
Timo Ewalds authored
5 #include <cassert>
141e49f The player should first consult the solver for some tactics. Spend 20…
Timo Ewalds authored
6
b562450 @tewalds Add profiling to show how much time is spent in each of the 4 MCTS st…
authored
7 #include "time.h"
3b07ddf @tewalds Fix the read/write lock system to not starve the writer, simplifiy th…
authored
8 #include "types.h"
18c886f add a simpler move struct, add a basic, though likely incomplete, RAV…
Timo Ewalds authored
9 #include "move.h"
302209c Commit the beginnings of a UCT MCTS player
Timo Ewalds authored
10 #include "board.h"
0aa0c76 Factor the stats out into a separate file, display some better stats
Timo Ewalds authored
11 #include "depthstats.h"
63f388e @tewalds Initial multi-threaded version. Limited to one thread, but it does wo…
authored
12 #include "thread.h"
48d137d @tewalds Replace the MTRand library with a xorshift random number generator. I…
authored
13 #include "xorshift.h"
b61a518 @tewalds Move the weightedrandom data structure into the thread context so it …
authored
14 #include "weightedrandtree.h"
7e65edb @tewalds Add a lower bound distance heuristic, optionally used as knowledge. A…
authored
15 #include "lbdist.h"
1fdcd7e @tewalds Switch the player to use the compact tree
authored
16 #include "compacttree.h"
b1c50a0 @tewalds Switch from fprintf(stderr... to logerr(string), clean up tons of war…
authored
17 #include "log.h"
033bb81 @tewalds Add a command to confirm a players proof
authored
18 #include "solverab.h"
19 #include "solverpns.h"
4214b7b @tewalds Fix two warnings, one lack of return, one signed/unsigned comparison
authored
20
302209c Commit the beginnings of a UCT MCTS player
Timo Ewalds authored
21 class Player {
ed6410c Deallocate the root properly, fixes a reverse memory leak
Timo Ewalds authored
22 public:
0d04152 Make ExpPair into a class, use accessor functions...
Timo Ewalds authored
23 class ExpPair {
1e98e59 @tewalds Revert "Add a minimax option to remove the experience from moves prov…
authored
24 uword s, n;
25 ExpPair(uword S, uword N) : s(S), n(N) { }
0d04152 Make ExpPair into a class, use accessor functions...
Timo Ewalds authored
26 public:
27 ExpPair() : s(0), n(0) { }
f9366a7 @tewalds Make ExpPair have atomic operations, forced to use int instead of flo…
authored
28 float avg() const { return 0.5f*s/n; }
1e98e59 @tewalds Revert "Add a minimax option to remove the experience from moves prov…
authored
29 uword num() const { return n; }
30 uword sum() const { return s/2; }
e03f7c0 @tewalds Add a move selection policy of choosing the one with the most wins, a…
authored
31
ce707ea @tewalds Refactor experience and rave to allow multiple rollouts per simulation
authored
32 void clear() { s = 0; n = 0; }
33
f9366a7 @tewalds Make ExpPair have atomic operations, forced to use int instead of flo…
authored
34 void addvloss(){ INCR(n); }
35 void addvtie() { INCR(s); }
36 void addvwin() { PLUS(s, 2); }
ce707ea @tewalds Refactor experience and rave to allow multiple rollouts per simulation
authored
37 void addv(const ExpPair & a){
38 if(a.s) PLUS(s, a.s);
39 if(a.n) PLUS(n, a.n);
40 }
41
42 void addloss(){ n++; }
43 void addtie() { s++; }
44 void addwin() { s += 2; }
45 void add(const ExpPair & a){
46 s += a.s;
47 n += a.n;
48 }
f9366a7 @tewalds Make ExpPair have atomic operations, forced to use int instead of flo…
authored
49
d91f720 @tewalds Fix some types so it imports properly
authored
50 void addwins(uword num) { n += num; s += 2*num; }
51 void addlosses(uword num){ n += num; }
1ec81f9 add experience to each other
Timo Ewalds authored
52 ExpPair & operator+=(const ExpPair & a){
53 s += a.s;
54 n += a.n;
55 return *this;
56 }
c49f5ca Split knowledge out explicitly
Timo Ewalds authored
57 ExpPair operator + (const ExpPair & a){
58 return ExpPair(s + a.s, n + a.n);
59 }
d91f720 @tewalds Fix some types so it imports properly
authored
60 ExpPair & operator*=(uword m){
0d04152 Make ExpPair into a class, use accessor functions...
Timo Ewalds authored
61 s *= m;
62 n *= m;
6911213 Refactor storing experience in the tree
Timo Ewalds authored
63 return *this;
64 }
1346e2d @tewalds Move do_backups to Player:: instead of Player::PlayerUCT::, but still…
authored
65 ExpPair invert(){
66 return ExpPair(n*2 - s, n);
67 }
6911213 Refactor storing experience in the tree
Timo Ewalds authored
68 };
69
302209c Commit the beginnings of a UCT MCTS player
Timo Ewalds authored
70 struct Node {
74af2df @tewalds Move children pointer to be managed in a class, hopefully remove the …
authored
71 public:
6911213 Refactor storing experience in the tree
Timo Ewalds authored
72 ExpPair rave;
73 ExpPair exp;
d27ab80 @tewalds Switch from an ExpPair to a small int, shrink the Node size by 8 byte…
authored
74 int16_t know;
b1c643c @tewalds Add proof depth to the nodes, may be useful in the future for copying…
authored
75 int8_t outcome;
76 uint8_t proofdepth;
74af2df @tewalds Move children pointer to be managed in a class, hopefully remove the …
authored
77 Move move;
78 Move bestmove; //if outcome is set, then bestmove is the way to get there
1fdcd7e @tewalds Switch the player to use the compact tree
authored
79 CompactTree<Node>::Children children;
80 // int padding;
d27ab80 @tewalds Switch from an ExpPair to a small int, shrink the Node size by 8 byte…
authored
81 //seems to need padding to multiples of 8 bytes or it segfaults?
8e8be5f Backup wins in the tree, possibly proving the root
Timo Ewalds authored
82 //don't forget to update the copy constructor/operator
302209c Commit the beginnings of a UCT MCTS player
Timo Ewalds authored
83
b1c643c @tewalds Add proof depth to the nodes, may be useful in the future for copying…
authored
84 Node() : know(0), outcome(-3), proofdepth(0) { }
85 Node(const Move & m, char o = -3) : know(0), outcome( o), proofdepth(0), move(m) { }
8e8be5f Backup wins in the tree, possibly proving the root
Timo Ewalds authored
86 Node(const Node & n) { *this = n; }
9d34d4e Clean up keeping the subtree...
Timo Ewalds authored
87 Node & operator = (const Node & n){
74af2df @tewalds Move children pointer to be managed in a class, hopefully remove the …
authored
88 if(this != & n){ //don't copy to self
9d34d4e Clean up keeping the subtree...
Timo Ewalds authored
89 //don't copy to a node that already has children
74af2df @tewalds Move children pointer to be managed in a class, hopefully remove the …
authored
90 assert(children.empty());
9d34d4e Clean up keeping the subtree...
Timo Ewalds authored
91
92 rave = n.rave;
93 exp = n.exp;
74af2df @tewalds Move children pointer to be managed in a class, hopefully remove the …
authored
94 know = n.know;
9d34d4e Clean up keeping the subtree...
Timo Ewalds authored
95 move = n.move;
8e8be5f Backup wins in the tree, possibly proving the root
Timo Ewalds authored
96 bestmove = n.bestmove;
74af2df @tewalds Move children pointer to be managed in a class, hopefully remove the …
authored
97 outcome = n.outcome;
b1c643c @tewalds Add proof depth to the nodes, may be useful in the future for copying…
authored
98 proofdepth = n.proofdepth;
ff7f4ff @tewalds Blah, undo a fix earlier, but at least comment it this time
authored
99 //children = n.children; ignore the children, they need to be swap_tree'd in
9d34d4e Clean up keeping the subtree...
Timo Ewalds authored
100 }
101 return *this;
102 }
103
104 void swap_tree(Node & n){
74af2df @tewalds Move children pointer to be managed in a class, hopefully remove the …
authored
105 children.swap(n.children);
ced4d1c Keep the tree between moves. For now that means turning off the solve…
Timo Ewalds authored
106 }
107
108 void print() const {
c033243 Fix size(), add Node::to_s()
Timo Ewalds authored
109 printf("%s\n", to_s().c_str());
110 }
111 string to_s() const {
0d04152 Make ExpPair into a class, use accessor functions...
Timo Ewalds authored
112 return "Node: exp " + to_str(exp.avg(), 2) + "/" + to_str(exp.num()) +
113 ", rave " + to_str(rave.avg(), 2) + "/" + to_str(rave.num()) +
74af2df @tewalds Move children pointer to be managed in a class, hopefully remove the …
authored
114 ", move " + to_str(move.x) + "," + to_str(move.y) + ", " + to_str(children.num());
ced4d1c Keep the tree between moves. For now that means turning off the solve…
Timo Ewalds authored
115 }
116
a0fc6cf Fix warnings about signed/unsigned
Timo Ewalds authored
117 unsigned int size() const {
74af2df @tewalds Move children pointer to be managed in a class, hopefully remove the …
authored
118 unsigned int num = children.num();
119
1fdcd7e @tewalds Switch the player to use the compact tree
authored
120 if(children.num())
121 for(Node * i = children.begin(); i != children.end(); i++)
122 num += i->size();
74af2df @tewalds Move children pointer to be managed in a class, hopefully remove the …
authored
123
124 return num;
b9d644e Add a tree size function
Timo Ewalds authored
125 }
74af2df @tewalds Move children pointer to be managed in a class, hopefully remove the …
authored
126
302209c Commit the beginnings of a UCT MCTS player
Timo Ewalds authored
127 ~Node(){
74af2df @tewalds Move children pointer to be managed in a class, hopefully remove the …
authored
128 assert(children.empty());
302209c Commit the beginnings of a UCT MCTS player
Timo Ewalds authored
129 }
130
1fdcd7e @tewalds Switch the player to use the compact tree
authored
131 unsigned int alloc(unsigned int num, CompactTree<Node> & ct){
132 return children.alloc(num, ct);
302209c Commit the beginnings of a UCT MCTS player
Timo Ewalds authored
133 }
1fdcd7e @tewalds Switch the player to use the compact tree
authored
134 unsigned int dealloc(CompactTree<Node> & ct){
74af2df @tewalds Move children pointer to be managed in a class, hopefully remove the …
authored
135 unsigned int num = 0;
f9e6f77 Force the dealloc to be used for deallocation.
Timo Ewalds authored
136
1fdcd7e @tewalds Switch the player to use the compact tree
authored
137 if(children.num())
138 for(Node * i = children.begin(); i != children.end(); i++)
139 num += i->dealloc(ct);
140 num += children.dealloc(ct);
f9e6f77 Force the dealloc to be used for deallocation.
Timo Ewalds authored
141
74af2df @tewalds Move children pointer to be managed in a class, hopefully remove the …
authored
142 return num;
302209c Commit the beginnings of a UCT MCTS player
Timo Ewalds authored
143 }
f19945c @tewalds Remove unused value calculation
authored
144
214afe6 Update to a more standard way of doing rave scores.
Timo Ewalds authored
145 //new way, more standard way of changing over from rave scores to real scores
61dbdce @tewalds Change the way knowledge is used. Let each knowledge paramater be tun…
authored
146 float value(float ravefactor, bool knowledge, float fpurgency){
b135336 @tewalds Use an independent knowledge factor instead of extra experience
authored
147 float val = fpurgency;
c7b8903 @tewalds Speed up the value function, at least in profiling
authored
148 float expnum = exp.num();
cedb800 @tewalds Minor optimization to the Node value function
authored
149 float ravenum = rave.num();
b135336 @tewalds Use an independent knowledge factor instead of extra experience
authored
150
151 if(ravefactor <= min_rave){
c7b8903 @tewalds Speed up the value function, at least in profiling
authored
152 if(expnum > 0)
b135336 @tewalds Use an independent knowledge factor instead of extra experience
authored
153 val = exp.avg();
cedb800 @tewalds Minor optimization to the Node value function
authored
154 }else if(ravenum > 0 || expnum > 0){
c7b8903 @tewalds Speed up the value function, at least in profiling
authored
155 float alpha = ravefactor/(ravefactor + expnum);
cedb800 @tewalds Minor optimization to the Node value function
authored
156 // float alpha = sqrt(ravefactor/(ravefactor + 3.0f*expnum));
157 // float alpha = ravenum/(expnum + ravenum + expnum*ravenum*ravefactor);
b135336 @tewalds Use an independent knowledge factor instead of extra experience
authored
158
159 val = 0;
cedb800 @tewalds Minor optimization to the Node value function
authored
160 if(ravenum > 0) val += alpha*rave.avg();
161 if(expnum > 0) val += (1.0f-alpha)*exp.avg();
b135336 @tewalds Use an independent knowledge factor instead of extra experience
authored
162 }
214afe6 Update to a more standard way of doing rave scores.
Timo Ewalds authored
163
c7b8903 @tewalds Speed up the value function, at least in profiling
authored
164 if(knowledge && know > 0){
165 if(expnum <= 1)
166 val += 0.01f * know;
167 else if(expnum < 1000) //knowledge is only useful with little experience
168 val += 0.01f * know / sqrt(expnum);
169 }
7cc84b2 Avoid a potential divide by 0, set the explore rate based on tests of…
Timo Ewalds authored
170
171 return val;
214afe6 Update to a more standard way of doing rave scores.
Timo Ewalds authored
172 }
302209c Commit the beginnings of a UCT MCTS player
Timo Ewalds authored
173 };
174
ce707ea @tewalds Refactor experience and rave to allow multiple rollouts per simulation
authored
175 struct MoveList {
1199606 Some cleanups to rave...
Timo Ewalds authored
176 struct RaveMove : public Move {
609a971 Fix rave values so it updates wins to the winner and losses to the lo…
Timo Ewalds authored
177 char player;
178
ce707ea @tewalds Refactor experience and rave to allow multiple rollouts per simulation
authored
179 RaveMove() : Move(M_UNKNOWN), player(0) { }
f9366a7 @tewalds Make ExpPair have atomic operations, forced to use int instead of flo…
authored
180 RaveMove(const Move & m, char p = 0) : Move(m), player(p) { }
609a971 Fix rave values so it updates wins to the winner and losses to the lo…
Timo Ewalds authored
181 };
182
ce707ea @tewalds Refactor experience and rave to allow multiple rollouts per simulation
authored
183 ExpPair exp[2]; //aggregated outcomes overall
184 ExpPair rave[2][361]; //aggregated outcomes per move
185 RaveMove moves[361]; //moves made in order
186 int tree; //number of moves in the tree
187 int rollout; //number of moves in the rollout
188 Board * board; //reference to rootboard for xy()
7149ea6 Add an option to make the rave scores scale from 2 down to 0
Timo Ewalds authored
189
ce707ea @tewalds Refactor experience and rave to allow multiple rollouts per simulation
authored
190 MoveList() : tree(0), rollout(0), board(NULL) { }
7149ea6 Add an option to make the rave scores scale from 2 down to 0
Timo Ewalds authored
191
ce707ea @tewalds Refactor experience and rave to allow multiple rollouts per simulation
authored
192 void addtree(const Move & move, char player){
193 moves[tree++] = RaveMove(move, player);
7149ea6 Add an option to make the rave scores scale from 2 down to 0
Timo Ewalds authored
194 }
ce707ea @tewalds Refactor experience and rave to allow multiple rollouts per simulation
authored
195 void addrollout(const Move & move, char player){
196 moves[rollout++] = RaveMove(move, player);
7149ea6 Add an option to make the rave scores scale from 2 down to 0
Timo Ewalds authored
197 }
ce707ea @tewalds Refactor experience and rave to allow multiple rollouts per simulation
authored
198 void reset(Board * b){
199 tree = 0;
200 rollout = 0;
201 board = b;
202 exp[0].clear();
203 exp[1].clear();
204 for(int i = 0; i < b->vecsize(); i++){
205 rave[0][i].clear();
206 rave[1][i].clear();
207 }
208 }
209 void finishrollout(int won){
210 exp[0].addloss();
211 exp[1].addloss();
212 if(won == 0){
213 exp[0].addtie();
214 exp[1].addtie();
215 }else{
216 exp[won-1].addwin();
217
218 for(RaveMove * i = begin(), * e = end(); i != e; i++){
219 ExpPair & r = rave[i->player-1][board->xy(*i)];
220 r.addloss();
221 if(i->player == won)
222 r.addwin();
223 }
224 }
225 rollout = 0;
226 }
227 RaveMove * begin() {
228 return moves;
7149ea6 Add an option to make the rave scores scale from 2 down to 0
Timo Ewalds authored
229 }
ce707ea @tewalds Refactor experience and rave to allow multiple rollouts per simulation
authored
230 RaveMove * end() {
231 return moves + tree + rollout;
7149ea6 Add an option to make the rave scores scale from 2 down to 0
Timo Ewalds authored
232 }
ce707ea @tewalds Refactor experience and rave to allow multiple rollouts per simulation
authored
233 void subvlosses(int n){
234 exp[0].addlosses(-n);
235 exp[1].addlosses(-n);
71d4142 Rewrite update_rave to use iterators, which makes it a bit faster, an…
Timo Ewalds authored
236 }
ce707ea @tewalds Refactor experience and rave to allow multiple rollouts per simulation
authored
237 const ExpPair & getrave(int player, const Move & move) const {
238 return rave[player-1][board->xy(move)];
71d4142 Rewrite update_rave to use iterators, which makes it a bit faster, an…
Timo Ewalds authored
239 }
ce707ea @tewalds Refactor experience and rave to allow multiple rollouts per simulation
authored
240 const ExpPair & getexp(int player) const {
241 return exp[player-1];
7149ea6 Add an option to make the rave scores scale from 2 down to 0
Timo Ewalds authored
242 }
243 };
244
63f388e @tewalds Initial multi-threaded version. Limited to one thread, but it does wo…
authored
245 class PlayerThread {
246 protected:
2da3341 @tewalds Allow multiple threads to be created, allow ponder to be switched on/off
authored
247 public:
48d137d @tewalds Replace the MTRand library with a xorshift random number generator. I…
authored
248 mutable XORShift_uint32 rand32;
249 mutable XORShift_float unitrand;
63f388e @tewalds Initial multi-threaded version. Limited to one thread, but it does wo…
authored
250 Thread thread;
251 Player * player;
3778fc2 @tewalds A few fixes to multi-threading, allow ponder
authored
252 public:
63f388e @tewalds Initial multi-threaded version. Limited to one thread, but it does wo…
authored
253 DepthStats treelen, gamelen;
3487c35 @tewalds Save the win type stats in a depthstats object, add a some code to ou…
authored
254 DepthStats wintypes[2][4]; //player,wintype
b562450 @tewalds Add profiling to show how much time is spent in each of the 4 MCTS st…
authored
255 double times[4]; //time spent in each of the stages
63f388e @tewalds Initial multi-threaded version. Limited to one thread, but it does wo…
authored
256
4bd6df4 @tewalds Count the number of simulations as a global counter instead of a per-…
authored
257 PlayerThread() : rand32(std::rand()), unitrand(std::rand()) {}
39a5ac7 @tewalds Fix some warnings
authored
258 virtual ~PlayerThread() { }
63f388e @tewalds Initial multi-threaded version. Limited to one thread, but it does wo…
authored
259 virtual void reset() { }
9e03444 @tewalds reset threads can decrease the number of threads, and restarts thread…
authored
260 int join(){ return thread.join(); }
f60e900 @tewalds Switch back to using the normal read write lock now that writer starv…
authored
261 void run(); //thread runner, calls iterate on each iteration
262 virtual void iterate() { } //handles each iteration
63f388e @tewalds Initial multi-threaded version. Limited to one thread, but it does wo…
authored
263 };
264
265 class PlayerUCT : public PlayerThread {
266 Move goodreply[2][361]; //361 is big enough for size 10 (ie 19x19), but no bigger...
2530d36 @tewalds Switch from skiprave once in so many times, to use rave and explorati…
authored
267 bool use_rave; //whether to use rave for this simulation
268 bool use_explore; //whether to use exploration for this simulation
9df0bbf @tewalds Add a mersenne twister random number generator, and use it to reduce …
authored
269 int rollout_pattern_offset; //where to start the rollout pattern
e55f51a @tewalds Rewrite weighted random to use locality instead of rave
authored
270 Move moves[361]; //moves in the rollout
271 WeightedRandTree wtree[2]; //hold the weights for weighted random values, one per player
7e65edb @tewalds Add a lower bound distance heuristic, optionally used as knowledge. A…
authored
272 LBDists dists; //holds the distances to the various non-ring wins as a heuristic for the minimum moves needed to win
ce707ea @tewalds Refactor experience and rave to allow multiple rollouts per simulation
authored
273 MoveList movelist;
b562450 @tewalds Add profiling to show how much time is spent in each of the 4 MCTS st…
authored
274 int stage; //which of the four MCTS stages is it on
275 Time timestamps[4]; //timestamps for the beginning, before child creation, before rollout, after rollout
63f388e @tewalds Initial multi-threaded version. Limited to one thread, but it does wo…
authored
276
277 public:
278 PlayerUCT(Player * p) {
9e03444 @tewalds reset threads can decrease the number of threads, and restarts thread…
authored
279 PlayerThread();
63f388e @tewalds Initial multi-threaded version. Limited to one thread, but it does wo…
authored
280 player = p;
281 reset();
282 thread(bind(&PlayerUCT::run, this));
283 }
284
285 void reset(){
286 treelen.reset();
287 gamelen.reset();
288
289 for(int p = 0; p < 2; p++)
290 for(int i = 0; i < 361; i++)
291 goodreply[p][i] = M_UNKNOWN;
2530d36 @tewalds Switch from skiprave once in so many times, to use rave and explorati…
authored
292
293 use_rave = false;
294 use_explore = false;
9df0bbf @tewalds Add a mersenne twister random number generator, and use it to reduce …
authored
295 rollout_pattern_offset = 0;
3487c35 @tewalds Save the win type stats in a depthstats object, add a some code to ou…
authored
296
297 for(int a = 0; a < 2; a++)
298 for(int b = 0; b < 4; b++)
299 wintypes[a][b].reset();
b562450 @tewalds Add profiling to show how much time is spent in each of the 4 MCTS st…
authored
300
301 for(int a = 0; a < 4; a++)
302 times[a] = 0;
63f388e @tewalds Initial multi-threaded version. Limited to one thread, but it does wo…
authored
303 }
304
305 private:
f60e900 @tewalds Switch back to using the normal read write lock now that writer starv…
authored
306 void iterate();
ce707ea @tewalds Refactor experience and rave to allow multiple rollouts per simulation
authored
307 void walk_tree(Board & board, Node * node, int depth);
308 bool create_children(Board & board, Node * node, int toplay);
63f388e @tewalds Initial multi-threaded version. Limited to one thread, but it does wo…
authored
309 void add_knowledge(Board & board, Node * node, Node * child);
e1063a1 @tewalds Add an option to decrease rave over time
authored
310 Node * choose_move(const Node * node, int toplay, int remain) const;
ce707ea @tewalds Refactor experience and rave to allow multiple rollouts per simulation
authored
311 void update_rave(const Node * node, int toplay);
9df0bbf @tewalds Add a mersenne twister random number generator, and use it to reduce …
authored
312 bool test_bridge_probe(const Board & board, const Move & move, const Move & test) const;
63f388e @tewalds Initial multi-threaded version. Limited to one thread, but it does wo…
authored
313
ce707ea @tewalds Refactor experience and rave to allow multiple rollouts per simulation
authored
314 int rollout(Board & board, Move move, int depth);
2d31bc7 @tewalds Fix a bug where getting to the same loss a second time was considered…
authored
315 PairMove rollout_choose_move(Board & board, const Move & prev, int & doinstwin, bool checkrings);
63f388e @tewalds Initial multi-threaded version. Limited to one thread, but it does wo…
authored
316 Move rollout_pattern(const Board & board, const Move & move);
317 };
318
3b07ddf @tewalds Fix the read/write lock system to not starve the writer, simplifiy th…
authored
319
cb365ad Allow the explore and ravefactor values to be set over gtp
Timo Ewalds authored
320 public:
6beda47 Make the minimum rave_factor a constant
Timo Ewalds authored
321
1b38950 @tewalds move the static const float out of the header, as per the spec, as ol…
authored
322 static const float min_rave;
6beda47 Make the minimum rave_factor a constant
Timo Ewalds authored
323
63f388e @tewalds Initial multi-threaded version. Limited to one thread, but it does wo…
authored
324 bool ponder; //think during opponents time?
4da2397 @tewalds Make the number of threads configurable
authored
325 int numthreads; //number of player threads to run
20d6697 @tewalds Make the memory limit easily configurable
authored
326 u64 maxmem; //maximum memory for the tree in bytes
b562450 @tewalds Add profiling to show how much time is spent in each of the 4 MCTS st…
authored
327 bool profile; //count how long is spent in each stage of MCTS
cc6d3a1 @tewalds Allow different final move selection options, keep the current defaul…
authored
328 //final move selection
329 float msrave; //rave factor in final move selection, -1 means use number instead of value
330 float msexplore; //the UCT constant in final move selection
0ec1b32 Prepare for new knowledge initialization code
Timo Ewalds authored
331 //tree traversal
e5df5dd @tewalds Add an option to scale the exploration term by the parent's experience
authored
332 bool parentexplore; // whether to multiple exploration by the parents winrate
18c886f add a simpler move struct, add a basic, though likely incomplete, RAV…
Timo Ewalds authored
333 float explore; //greater than one favours exploration, smaller than one favours exploitation
22038b1 Major refactoring of UCT/RAVE. Pulled rave updates out of walk_tree. …
Timo Ewalds authored
334 float ravefactor; //big numbers favour rave scores, small ignore it
e1063a1 @tewalds Add an option to decrease rave over time
authored
335 float decrrave; //decrease rave over time, add this value for each empty position on the board
61dbdce @tewalds Change the way knowledge is used. Let each knowledge paramater be tun…
authored
336 bool knowledge; //whether to include knowledge
2530d36 @tewalds Switch from skiprave once in so many times, to use rave and explorati…
authored
337 float userave; //what probability to use rave
338 float useexplore; //what probability to use UCT exploration
dc02794 @tewalds Reorder variables
authored
339 float fpurgency; //what value to return for a move that hasn't been played yet
ce707ea @tewalds Refactor experience and rave to allow multiple rollouts per simulation
authored
340 int rollouts; //number of rollouts to run after the tree traversal
97c23c4 @tewalds Add dynamic widening, so only consider the first few children, accord…
authored
341 float dynwiden; //dynamic widening, look at first log_dynwiden(experience) number of children, 0 to disable
342 float logdynwiden; // = log(dynwiden), cached for performance
dc02794 @tewalds Reorder variables
authored
343 //tree building
4b36b92 Add an option to only use short rollouts, for higher quality rave upd…
Timo Ewalds authored
344 bool shortrave; //only update rave values on short rollouts
dca42bd Make keeping tree optional
Timo Ewalds authored
345 bool keeptree; //reuse the tree from the previous move
4d2b548 @tewalds Allow solving to deeper levels at node expansion
authored
346 int minimax; //solve the minimax tree within the uct tree
d3bcd3f @tewalds Option to check for a draw at child creation.
authored
347 bool detectdraw; //look for draws early, slow
1e98e59 @tewalds Revert "Add a minimax option to remove the experience from moves prov…
authored
348 uint visitexpand;//number of visits before expanding a node
f78a468 @tewalds Add an option to prune symmetries in the player tree, useful mainly f…
authored
349 bool prunesymmetry; //prune symmetric children from the move list, useful for proving but likely not for playing
7dc76a9 @tewalds Allow garbage collection to keep the heavy nodes of the proof tree ar…
authored
350 uint gcsolved; //garbage collect solved nodes or keep them in the tree, assuming they meet the required amount of work
0ec1b32 Prepare for new knowledge initialization code
Timo Ewalds authored
351 //knowledge
61dbdce @tewalds Change the way knowledge is used. Let each knowledge paramater be tun…
authored
352 int localreply; //boost for a local reply, ie a move near the previous move
353 int locality; //boost for playing near previous stones
354 int connect; //boost for having connections to edges and corners
699b9f2 @tewalds Add a size of group heuristic
authored
355 int size; //boost for large groups
61dbdce @tewalds Change the way knowledge is used. Let each knowledge paramater be tun…
authored
356 int bridge; //boost replying to a probe at a bridge
7e65edb @tewalds Add a lower bound distance heuristic, optionally used as knowledge. A…
authored
357 int dists; //boost based on minimum number of stones needed to finish a non-ring win
0ec1b32 Prepare for new knowledge initialization code
Timo Ewalds authored
358 //rollout
a61398d @tewalds Refine the pattern stuff, remove the old weighted random weights and …
authored
359 bool weightedrandom; //use weighted random for move ordering based on gammas
96a004c @tewalds Add an option to limit the ring depth
authored
360 float checkrings; //how often to allow rings as a win condition in a rollout
3487c35 @tewalds Save the win type stats in a depthstats object, add a some code to ou…
authored
361 float checkringdepth; //how deep to allow rings as a win condition in a rollout
52dbe9a @tewalds Allow the minimum ring size to be set
authored
362 float minringsize; //how big is the minimum starting ring size (<6 is good)
a317614 @tewalds Add an option to gradually increase the minimum ring size
authored
363 float ringincr; //a growth rate on how big must the ring be to be valid
c7a7f61 @tewalds Add an option to only allow rings that include some 'permanent' piece…
authored
364 int ringperm; //how many stones in a ring must be in place before the rollout begins
ff9a09b Parameterize a few features
Timo Ewalds authored
365 bool rolloutpattern; //play the response to a virtual connection threat in rollouts
6df57e1 @tewalds Make last good reply wins vs wins+losses options
authored
366 int lastgoodreply; //use the last-good-reply rollout heuristic
9d27a53 @tewalds Add an option to only check for instant wins for a limited amount of …
authored
367 int instantwin; //look for instant wins in rollouts
368 int instwindepth; //how deep to look for instant wins
0ec1b32 Prepare for new knowledge initialization code
Timo Ewalds authored
369
a61398d @tewalds Refine the pattern stuff, remove the old weighted random weights and …
authored
370 float gammas[4096]; //pattern weights for weighted random
371
ced4d1c Keep the tree between moves. For now that means turning off the solve…
Timo Ewalds authored
372 Board rootboard;
63f388e @tewalds Initial multi-threaded version. Limited to one thread, but it does wo…
authored
373 Node root;
1fdcd7e @tewalds Switch the player to use the compact tree
authored
374 uword nodes;
2f657fa @tewalds Make the garbage collection start closer to last time, decaying slowl…
authored
375 int gclimit; //the minimum experience needed to not be garbage collected
ced4d1c Keep the tree between moves. For now that means turning off the solve…
Timo Ewalds authored
376
4bd6df4 @tewalds Count the number of simulations as a global counter instead of a per-…
authored
377 uint64_t runs, maxruns;
378
1fdcd7e @tewalds Switch the player to use the compact tree
authored
379 CompactTree<Node> ctmem;
380
bca6d7d @tewalds Rename logfile and logname to solved_logfile and solved_logname, sinc…
authored
381 string solved_logname;
382 FILE * solved_logfile;
5da2af0 @tewalds Garbage collect solved nodes, after optionally logging them to a file
authored
383
2027a9e @tewalds Switch the player thread synchronization to use a threadstate with at…
authored
384 enum ThreadState {
385 Thread_Cancelled, //threads should exit
386 Thread_Wait_Start, //threads are waiting to start
aa8fdb6 @tewalds Add a Thread_Wait_Start_Cancelled state, to make it cancel the thread…
authored
387 Thread_Wait_Start_Cancelled, //once done waiting, go to cancelled instead of running
2027a9e @tewalds Switch the player thread synchronization to use a threadstate with at…
authored
388 Thread_Running, //threads are running
389 Thread_GC, //one thread is running garbage collection, the rest are waiting
390 Thread_GC_End, //once done garbage collecting, go to wait_end instead of back to running
391 Thread_Wait_End, //threads are waiting to end
392 };
393 volatile ThreadState threadstate;
63f388e @tewalds Initial multi-threaded version. Limited to one thread, but it does wo…
authored
394 vector<PlayerThread *> threads;
2027a9e @tewalds Switch the player thread synchronization to use a threadstate with at…
authored
395 Barrier runbarrier, gcbarrier;
302209c Commit the beginnings of a UCT MCTS player
Timo Ewalds authored
396
bdc8b7d Add some version of time control...
Timo Ewalds authored
397 double time_used;
398
8a32249 @tewalds Move a bunch of code from player.h to player.cpp to improve compile t…
authored
399 Player();
400 ~Player();
2027a9e @tewalds Switch the player thread synchronization to use a threadstate with at…
authored
401
8a32249 @tewalds Move a bunch of code from player.h to player.cpp to improve compile t…
authored
402 void timedout();
5da2af0 @tewalds Garbage collect solved nodes, after optionally logging them to a file
authored
403
8a32249 @tewalds Move a bunch of code from player.h to player.cpp to improve compile t…
authored
404 string statestring();
b930ead Set the parameters based on all the recent testing, changing by board…
Timo Ewalds authored
405
8a32249 @tewalds Move a bunch of code from player.h to player.cpp to improve compile t…
authored
406 void stop_threads();
407 void start_threads();
408 void reset_threads();
5da2af0 @tewalds Garbage collect solved nodes, after optionally logging them to a file
authored
409
8a32249 @tewalds Move a bunch of code from player.h to player.cpp to improve compile t…
authored
410 void set_ponder(bool p);
411 void set_board(const Board & board);
9d34d4e Clean up keeping the subtree...
Timo Ewalds authored
412
8a32249 @tewalds Move a bunch of code from player.h to player.cpp to improve compile t…
authored
413 void move(const Move & m);
61a6b44 Output the amount of the tree that is saved by keeping the tree
Timo Ewalds authored
414
8a32249 @tewalds Move a bunch of code from player.h to player.cpp to improve compile t…
authored
415 double gamelen();
9d34d4e Clean up keeping the subtree...
Timo Ewalds authored
416
8a32249 @tewalds Move a bunch of code from player.h to player.cpp to improve compile t…
authored
417 bool setlogfile(string name);
418 void flushlog();
1ec7f6c @tewalds Rewrite the garbage collection and solved nodes logging to hopefully …
authored
419 void logsolved(Board board, const Node * node, bool skiproot = false); //copies the board before passing to unsafe
420 void logsolved_unsafe(Board & board, const Node * node, bool skiproot); //modifies the board
5da2af0 @tewalds Garbage collect solved nodes, after optionally logging them to a file
authored
421
4bd6df4 @tewalds Count the number of simulations as a global counter instead of a per-…
authored
422 Node * genmove(double time, int max_runs);
ced4d1c Keep the tree between moves. For now that means turning off the solve…
Timo Ewalds authored
423 vector<Move> get_pv();
1ec7f6c @tewalds Rewrite the garbage collection and solved nodes logging to hopefully …
authored
424 void garbage_collect(Board & board, Node * node); //destroys the board, so pass in a copy
a193bfe @tewalds Move child creation and search to functions, hopefully fix some bugs …
authored
425
1346e2d @tewalds Move do_backups to Player:: instead of Player::PlayerUCT::, but still…
authored
426 bool do_backup(Node * node, Node * backup, int toplay);
427
1ec7f6c @tewalds Rewrite the garbage collection and solved nodes logging to hopefully …
authored
428 void gen_hgf(Board & board, Node * node, unsigned int limit, unsigned int depth, FILE * fd);
c691e85 @tewalds Support loading hgfs from the root node, fix some warnings and bugs
authored
429 void load_hgf(Board board, Node * node, FILE * fd);
302209c Commit the beginnings of a UCT MCTS player
Timo Ewalds authored
430
a193bfe @tewalds Move child creation and search to functions, hopefully fix some bugs …
authored
431 void create_children_simple(const Board & board, Node * node);
432 Node * find_child(Node * node, const Move & move);
433
033bb81 @tewalds Add a command to confirm a players proof
authored
434 int confirm_proof(const Board & board, Node * node, SolverAB & ab, SolverPNS & pns);
435
302209c Commit the beginnings of a UCT MCTS player
Timo Ewalds authored
436 protected:
811c718 @tewalds Actually finish a game, deal with the last ply not existing by runnin…
authored
437 Node * return_move(Node * node, int toplay) const;
302209c Commit the beginnings of a UCT MCTS player
Timo Ewalds authored
438 };
439
Something went wrong with that request. Please try again.