Skip to content
Newer
Older
100644 672 lines (566 sloc) 17.1 KB
302209c Commit the beginnings of a UCT MCTS player
Timo Ewalds authored Feb 22, 2010
1
2 #ifndef __PLAYER_H_
3 #define __PLAYER_H_
4
141e49f The player should first consult the solver for some tactics. Spend 20…
Timo Ewalds authored Mar 3, 2010
5 #include <cmath>
9d34d4e Clean up keeping the subtree...
Timo Ewalds authored Apr 9, 2010
6 #include <cassert>
141e49f The player should first consult the solver for some tactics. Spend 20…
Timo Ewalds authored Mar 4, 2010
7
3b07ddf @tewalds Fix the read/write lock system to not starve the writer, simplifiy th…
authored Jul 24, 2010
8 #include "types.h"
18c886f add a simpler move struct, add a basic, though likely incomplete, RAV…
Timo Ewalds authored Feb 26, 2010
9 #include "move.h"
302209c Commit the beginnings of a UCT MCTS player
Timo Ewalds authored Feb 23, 2010
10 #include "board.h"
11 #include "time.h"
0aa0c76 Factor the stats out into a separate file, display some better stats
Timo Ewalds authored Feb 28, 2010
12 #include "depthstats.h"
63f388e @tewalds Initial multi-threaded version. Limited to one thread, but it does wo…
authored Jul 7, 2010
13 #include "thread.h"
9df0bbf @tewalds Add a mersenne twister random number generator, and use it to reduce …
authored Sep 28, 2010
14 #include "mtrand.h"
b61a518 @tewalds Move the weightedrandom data structure into the thread context so it …
authored Sep 29, 2010
15 #include "weightedrandtree.h"
7e65edb @tewalds Add a lower bound distance heuristic, optionally used as knowledge. A…
authored Sep 29, 2010
16 #include "lbdist.h"
1fdcd7e @tewalds Switch the player to use the compact tree
authored Nov 29, 2010
17 #include "compacttree.h"
b1c50a0 @tewalds Switch from fprintf(stderr... to logerr(string), clean up tons of war…
authored Dec 1, 2010
18 #include "log.h"
4214b7b @tewalds Fix two warnings, one lack of return, one signed/unsigned comparison
authored Jun 23, 2010
19
302209c Commit the beginnings of a UCT MCTS player
Timo Ewalds authored Feb 23, 2010
20 class Player {
ed6410c Deallocate the root properly, fixes a reverse memory leak
Timo Ewalds authored Mar 28, 2010
21 public:
0d04152 Make ExpPair into a class, use accessor functions...
Timo Ewalds authored Apr 10, 2010
22 class ExpPair {
88b27a4 @tewalds Switch from 64bit experience to word size experience, so it's 32bit o…
authored Dec 1, 2010
23 uword s, n;
24 ExpPair(uword S, uword N) : s(S), n(N) { }
0d04152 Make ExpPair into a class, use accessor functions...
Timo Ewalds authored Apr 10, 2010
25 public:
26 ExpPair() : s(0), n(0) { }
f9366a7 @tewalds Make ExpPair have atomic operations, forced to use int instead of flo…
authored Jul 10, 2010
27 float avg() const { return 0.5f*s/n; }
88b27a4 @tewalds Switch from 64bit experience to word size experience, so it's 32bit o…
authored Dec 1, 2010
28 uword num() const { return n; }
29 uword sum() const { return s/2; }
e03f7c0 @tewalds Add a move selection policy of choosing the one with the most wins, a…
authored Aug 7, 2010
30
ce707ea @tewalds Refactor experience and rave to allow multiple rollouts per simulation
authored Dec 18, 2010
31 void clear() { s = 0; n = 0; }
32
f9366a7 @tewalds Make ExpPair have atomic operations, forced to use int instead of flo…
authored Jul 11, 2010
33 void addvloss(){ INCR(n); }
34 void addvtie() { INCR(s); }
35 void addvwin() { PLUS(s, 2); }
ce707ea @tewalds Refactor experience and rave to allow multiple rollouts per simulation
authored Dec 18, 2010
36 void addv(const ExpPair & a){
37 if(a.s) PLUS(s, a.s);
38 if(a.n) PLUS(n, a.n);
39 }
40
41 void addloss(){ n++; }
42 void addtie() { s++; }
43 void addwin() { s += 2; }
44 void add(const ExpPair & a){
45 s += a.s;
46 n += a.n;
47 }
f9366a7 @tewalds Make ExpPair have atomic operations, forced to use int instead of flo…
authored Jul 11, 2010
48
49 void addwins(int num) { n += num; s += 2*num; }
50 void addlosses(int num){ n += num; }
1ec81f9 add experience to each other
Timo Ewalds authored Apr 17, 2010
51 ExpPair & operator+=(const ExpPair & a){
52 s += a.s;
53 n += a.n;
54 return *this;
55 }
c49f5ca Split knowledge out explicitly
Timo Ewalds authored Apr 22, 2010
56 ExpPair operator + (const ExpPair & a){
57 return ExpPair(s + a.s, n + a.n);
58 }
0d04152 Make ExpPair into a class, use accessor functions...
Timo Ewalds authored Apr 10, 2010
59 ExpPair & operator*=(int m){
60 s *= m;
61 n *= m;
6911213 Refactor storing experience in the tree
Timo Ewalds authored Apr 7, 2010
62 return *this;
63 }
64 };
65
302209c Commit the beginnings of a UCT MCTS player
Timo Ewalds authored Feb 23, 2010
66 struct Node {
74af2df @tewalds Move children pointer to be managed in a class, hopefully remove the …
authored May 26, 2010
67 public:
6911213 Refactor storing experience in the tree
Timo Ewalds authored Apr 7, 2010
68 ExpPair rave;
69 ExpPair exp;
d27ab80 @tewalds Switch from an ExpPair to a small int, shrink the Node size by 8 byte…
authored Jun 23, 2010
70 int16_t know;
71 int16_t outcome;
74af2df @tewalds Move children pointer to be managed in a class, hopefully remove the …
authored May 26, 2010
72 Move move;
73 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 Nov 29, 2010
74 CompactTree<Node>::Children children;
75 // int padding;
d27ab80 @tewalds Switch from an ExpPair to a small int, shrink the Node size by 8 byte…
authored Jun 23, 2010
76 //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 Apr 10, 2010
77 //don't forget to update the copy constructor/operator
302209c Commit the beginnings of a UCT MCTS player
Timo Ewalds authored Feb 23, 2010
78
8efcfbc @tewalds Switch from unknown = -1 to unknown = -3 so that black_or_win and whi…
authored Dec 16, 2010
79 Node() : know(0), outcome(-3) { }
80 Node(const Move & m, char o = -3) : know(0), outcome(o), move(m) { }
8e8be5f Backup wins in the tree, possibly proving the root
Timo Ewalds authored Apr 10, 2010
81 Node(const Node & n) { *this = n; }
9d34d4e Clean up keeping the subtree...
Timo Ewalds authored Apr 9, 2010
82 Node & operator = (const Node & n){
74af2df @tewalds Move children pointer to be managed in a class, hopefully remove the …
authored May 26, 2010
83 if(this != & n){ //don't copy to self
9d34d4e Clean up keeping the subtree...
Timo Ewalds authored Apr 9, 2010
84 //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 May 26, 2010
85 assert(children.empty());
9d34d4e Clean up keeping the subtree...
Timo Ewalds authored Apr 9, 2010
86
87 rave = n.rave;
88 exp = n.exp;
74af2df @tewalds Move children pointer to be managed in a class, hopefully remove the …
authored May 26, 2010
89 know = n.know;
9d34d4e Clean up keeping the subtree...
Timo Ewalds authored Apr 9, 2010
90 move = n.move;
8e8be5f Backup wins in the tree, possibly proving the root
Timo Ewalds authored Apr 10, 2010
91 bestmove = n.bestmove;
74af2df @tewalds Move children pointer to be managed in a class, hopefully remove the …
authored May 26, 2010
92 outcome = n.outcome;
ff7f4ff @tewalds Blah, undo a fix earlier, but at least comment it this time
authored Nov 29, 2010
93 //children = n.children; ignore the children, they need to be swap_tree'd in
9d34d4e Clean up keeping the subtree...
Timo Ewalds authored Apr 9, 2010
94 }
95 return *this;
96 }
97
98 void swap_tree(Node & n){
74af2df @tewalds Move children pointer to be managed in a class, hopefully remove the …
authored May 26, 2010
99 children.swap(n.children);
ced4d1c Keep the tree between moves. For now that means turning off the solve…
Timo Ewalds authored Mar 28, 2010
100 }
101
102 void print() const {
c033243 Fix size(), add Node::to_s()
Timo Ewalds authored Apr 9, 2010
103 printf("%s\n", to_s().c_str());
104 }
105 string to_s() const {
0d04152 Make ExpPair into a class, use accessor functions...
Timo Ewalds authored Apr 10, 2010
106 return "Node: exp " + to_str(exp.avg(), 2) + "/" + to_str(exp.num()) +
107 ", 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 May 26, 2010
108 ", 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 Mar 28, 2010
109 }
110
a0fc6cf Fix warnings about signed/unsigned
Timo Ewalds authored May 4, 2010
111 unsigned int size() const {
74af2df @tewalds Move children pointer to be managed in a class, hopefully remove the …
authored May 26, 2010
112 unsigned int num = children.num();
113
1fdcd7e @tewalds Switch the player to use the compact tree
authored Nov 29, 2010
114 if(children.num())
115 for(Node * i = children.begin(); i != children.end(); i++)
116 num += i->size();
74af2df @tewalds Move children pointer to be managed in a class, hopefully remove the …
authored May 26, 2010
117
118 return num;
b9d644e Add a tree size function
Timo Ewalds authored Apr 8, 2010
119 }
74af2df @tewalds Move children pointer to be managed in a class, hopefully remove the …
authored May 26, 2010
120
302209c Commit the beginnings of a UCT MCTS player
Timo Ewalds authored Feb 23, 2010
121 ~Node(){
74af2df @tewalds Move children pointer to be managed in a class, hopefully remove the …
authored May 26, 2010
122 assert(children.empty());
302209c Commit the beginnings of a UCT MCTS player
Timo Ewalds authored Feb 23, 2010
123 }
124
1fdcd7e @tewalds Switch the player to use the compact tree
authored Nov 29, 2010
125 unsigned int alloc(unsigned int num, CompactTree<Node> & ct){
126 return children.alloc(num, ct);
302209c Commit the beginnings of a UCT MCTS player
Timo Ewalds authored Feb 23, 2010
127 }
1fdcd7e @tewalds Switch the player to use the compact tree
authored Nov 29, 2010
128 unsigned int dealloc(CompactTree<Node> & ct){
74af2df @tewalds Move children pointer to be managed in a class, hopefully remove the …
authored May 26, 2010
129 unsigned int num = 0;
f9e6f77 Force the dealloc to be used for deallocation.
Timo Ewalds authored Apr 9, 2010
130
1fdcd7e @tewalds Switch the player to use the compact tree
authored Nov 29, 2010
131 if(children.num())
132 for(Node * i = children.begin(); i != children.end(); i++)
133 num += i->dealloc(ct);
134 num += children.dealloc(ct);
f9e6f77 Force the dealloc to be used for deallocation.
Timo Ewalds authored Apr 9, 2010
135
74af2df @tewalds Move children pointer to be managed in a class, hopefully remove the …
authored May 26, 2010
136 return num;
302209c Commit the beginnings of a UCT MCTS player
Timo Ewalds authored Feb 23, 2010
137 }
576fa84 Fix a few bugs: use factor instead of scale. Stop assigning rave loss…
Timo Ewalds authored Mar 7, 2010
138 //*
214afe6 Update to a more standard way of doing rave scores.
Timo Ewalds authored Mar 5, 2010
139 //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 Aug 10, 2010
140 float value(float ravefactor, bool knowledge, float fpurgency){
b135336 @tewalds Use an independent knowledge factor instead of extra experience
authored Jun 23, 2010
141 float val = fpurgency;
142
143 if(ravefactor <= min_rave){
144 if(exp.num() > 0)
145 val = exp.avg();
146 }else if(rave.num() || exp.num()){
147 float alpha = ravefactor/(ravefactor + exp.num());
148 // float alpha = sqrt(ravefactor/(ravefactor + 3*exp.num()));
149 // float alpha = (float)rave.num()/((float)exp.num() + (float)rave.num() + 4.0*exp.num()*rave.num()*ravefactor);
150
151 val = 0;
152 if(rave.num()) val += alpha*rave.avg();
153 if(exp.num()) val += (1-alpha)*exp.avg();
154 }
214afe6 Update to a more standard way of doing rave scores.
Timo Ewalds authored Mar 6, 2010
155
61dbdce @tewalds Change the way knowledge is used. Let each knowledge paramater be tun…
authored Aug 10, 2010
156 if(knowledge && know > 0)
157 val += 0.01f * know / sqrt((float)(exp.num() + 1));
7cc84b2 Avoid a potential divide by 0, set the explore rate based on tests of…
Timo Ewalds authored Mar 6, 2010
158
159 return val;
214afe6 Update to a more standard way of doing rave scores.
Timo Ewalds authored Mar 6, 2010
160 }
576fa84 Fix a few bugs: use factor instead of scale. Stop assigning rave loss…
Timo Ewalds authored Mar 7, 2010
161 /*/
214afe6 Update to a more standard way of doing rave scores.
Timo Ewalds authored Mar 6, 2010
162 //my understanding of how fuego does it
22038b1 Major refactoring of UCT/RAVE. Pulled rave updates out of walk_tree. …
Timo Ewalds authored Mar 27, 2010
163 float value(float ravefactor, float fpurgency){
214afe6 Update to a more standard way of doing rave scores.
Timo Ewalds authored Mar 6, 2010
164 float val = 0;
165 float weight = 0;
166 if(visits) {
167 val += score;
168 weight += visits;
169 }
576fa84 Fix a few bugs: use factor instead of scale. Stop assigning rave loss…
Timo Ewalds authored Mar 7, 2010
170 if(ravevisits){
cd8a3a9 Update the fuego based value function, fix a misunderstanding as well…
Timo Ewalds authored Mar 25, 2010
171 float bias = 1.0/(1.1 + ravevisits/20000.0);
172 val += rave*bias;
173 weight += ravevisits*bias;
214afe6 Update to a more standard way of doing rave scores.
Timo Ewalds authored Mar 6, 2010
174 }
175 if(weight > 0)
176 return val / weight;
177 else
cd8a3a9 Update the fuego based value function, fix a misunderstanding as well…
Timo Ewalds authored Mar 26, 2010
178 return fpurgency;
179 }
180
181 //based directly on fuego
22038b1 Major refactoring of UCT/RAVE. Pulled rave updates out of walk_tree. …
Timo Ewalds authored Mar 27, 2010
182 float value(float ravefactor, float fpurgency){
cd8a3a9 Update the fuego based value function, fix a misunderstanding as well…
Timo Ewalds authored Mar 26, 2010
183 float val = 0.f;
184 float weightSum = 0.f;
185 bool hasValue = false;
186 if(visits){
187 val += score;
188 weightSum += visits;
189 hasValue = true;
190 }
191 if(ravevisits){
192 float weight = ravevisits / ( 1.1 + ravevisits/20000.);
193 val += weight * rave / ravevisits;
194 weightSum += weight;
195 hasValue = true;
196 }
197 if(hasValue)
198 return val / weightSum;
199 else
200 return fpurgency;
214afe6 Update to a more standard way of doing rave scores.
Timo Ewalds authored Mar 6, 2010
201 }
cd8a3a9 Update the fuego based value function, fix a misunderstanding as well…
Timo Ewalds authored Mar 26, 2010
202
214afe6 Update to a more standard way of doing rave scores.
Timo Ewalds authored Mar 6, 2010
203 //*/
302209c Commit the beginnings of a UCT MCTS player
Timo Ewalds authored Feb 23, 2010
204 };
205
ce707ea @tewalds Refactor experience and rave to allow multiple rollouts per simulation
authored Dec 18, 2010
206 struct MoveList {
1199606 Some cleanups to rave...
Timo Ewalds authored Apr 18, 2010
207 struct RaveMove : public Move {
609a971 Fix rave values so it updates wins to the winner and losses to the lo…
Timo Ewalds authored Mar 9, 2010
208 char player;
209
ce707ea @tewalds Refactor experience and rave to allow multiple rollouts per simulation
authored Dec 18, 2010
210 RaveMove() : Move(M_UNKNOWN), player(0) { }
f9366a7 @tewalds Make ExpPair have atomic operations, forced to use int instead of flo…
authored Jul 11, 2010
211 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 Mar 9, 2010
212 };
213
ce707ea @tewalds Refactor experience and rave to allow multiple rollouts per simulation
authored Dec 18, 2010
214 ExpPair exp[2]; //aggregated outcomes overall
215 ExpPair rave[2][361]; //aggregated outcomes per move
216 RaveMove moves[361]; //moves made in order
217 int tree; //number of moves in the tree
218 int rollout; //number of moves in the rollout
219 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 Mar 5, 2010
220
ce707ea @tewalds Refactor experience and rave to allow multiple rollouts per simulation
authored Dec 18, 2010
221 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 Mar 5, 2010
222
ce707ea @tewalds Refactor experience and rave to allow multiple rollouts per simulation
authored Dec 18, 2010
223 void addtree(const Move & move, char player){
224 moves[tree++] = RaveMove(move, player);
7149ea6 Add an option to make the rave scores scale from 2 down to 0
Timo Ewalds authored Mar 5, 2010
225 }
ce707ea @tewalds Refactor experience and rave to allow multiple rollouts per simulation
authored Dec 18, 2010
226 void addrollout(const Move & move, char player){
227 moves[rollout++] = RaveMove(move, player);
7149ea6 Add an option to make the rave scores scale from 2 down to 0
Timo Ewalds authored Mar 5, 2010
228 }
ce707ea @tewalds Refactor experience and rave to allow multiple rollouts per simulation
authored Dec 18, 2010
229 void reset(Board * b){
230 tree = 0;
231 rollout = 0;
232 board = b;
233 exp[0].clear();
234 exp[1].clear();
235 for(int i = 0; i < b->vecsize(); i++){
236 rave[0][i].clear();
237 rave[1][i].clear();
238 }
239 }
240 void finishrollout(int won){
241 exp[0].addloss();
242 exp[1].addloss();
243 if(won == 0){
244 exp[0].addtie();
245 exp[1].addtie();
246 }else{
247 exp[won-1].addwin();
248
249 for(RaveMove * i = begin(), * e = end(); i != e; i++){
250 ExpPair & r = rave[i->player-1][board->xy(*i)];
251 r.addloss();
252 if(i->player == won)
253 r.addwin();
254 }
255 }
256 rollout = 0;
257 }
258 RaveMove * begin() {
259 return moves;
7149ea6 Add an option to make the rave scores scale from 2 down to 0
Timo Ewalds authored Mar 5, 2010
260 }
ce707ea @tewalds Refactor experience and rave to allow multiple rollouts per simulation
authored Dec 18, 2010
261 RaveMove * end() {
262 return moves + tree + rollout;
7149ea6 Add an option to make the rave scores scale from 2 down to 0
Timo Ewalds authored Mar 5, 2010
263 }
ce707ea @tewalds Refactor experience and rave to allow multiple rollouts per simulation
authored Dec 18, 2010
264 void subvlosses(int n){
265 exp[0].addlosses(-n);
266 exp[1].addlosses(-n);
71d4142 Rewrite update_rave to use iterators, which makes it a bit faster, an…
Timo Ewalds authored Apr 18, 2010
267 }
ce707ea @tewalds Refactor experience and rave to allow multiple rollouts per simulation
authored Dec 18, 2010
268 const ExpPair & getrave(int player, const Move & move) const {
269 return rave[player-1][board->xy(move)];
71d4142 Rewrite update_rave to use iterators, which makes it a bit faster, an…
Timo Ewalds authored Apr 18, 2010
270 }
ce707ea @tewalds Refactor experience and rave to allow multiple rollouts per simulation
authored Dec 18, 2010
271 const ExpPair & getexp(int player) const {
272 return exp[player-1];
7149ea6 Add an option to make the rave scores scale from 2 down to 0
Timo Ewalds authored Mar 5, 2010
273 }
274 };
275
63f388e @tewalds Initial multi-threaded version. Limited to one thread, but it does wo…
authored Jul 7, 2010
276 class PlayerThread {
277 protected:
2da3341 @tewalds Allow multiple threads to be created, allow ponder to be switched on/off
authored Jul 10, 2010
278 public:
9df0bbf @tewalds Add a mersenne twister random number generator, and use it to reduce …
authored Sep 27, 2010
279 mutable MTRand_int32 rand32;
e37da98 @tewalds Move unitrand into the thread context
authored Sep 30, 2010
280 mutable MTRand unitrand;
63f388e @tewalds Initial multi-threaded version. Limited to one thread, but it does wo…
authored Jul 7, 2010
281 Thread thread;
282 Player * player;
9e03444 @tewalds reset threads can decrease the number of threads, and restarts thread…
authored Jul 26, 2010
283 bool cancelled;
3778fc2 @tewalds A few fixes to multi-threading, allow ponder
authored Jul 9, 2010
284 public:
ee53b23 @tewalds Let maxruns work again. It doesn't make much sense with ponder, and w…
authored Jul 30, 2010
285 int runs, maxruns;
63f388e @tewalds Initial multi-threaded version. Limited to one thread, but it does wo…
authored Jul 7, 2010
286 DepthStats treelen, gamelen;
3487c35 @tewalds Save the win type stats in a depthstats object, add a some code to ou…
authored Oct 1, 2010
287 DepthStats wintypes[2][4]; //player,wintype
63f388e @tewalds Initial multi-threaded version. Limited to one thread, but it does wo…
authored Jul 7, 2010
288
ee53b23 @tewalds Let maxruns work again. It doesn't make much sense with ponder, and w…
authored Jul 30, 2010
289 PlayerThread() : cancelled(false), runs(0), maxruns(0) {}
39a5ac7 @tewalds Fix some warnings
authored Oct 5, 2010
290 virtual ~PlayerThread() { }
63f388e @tewalds Initial multi-threaded version. Limited to one thread, but it does wo…
authored Jul 7, 2010
291 virtual void reset() { }
9e03444 @tewalds reset threads can decrease the number of threads, and restarts thread…
authored Jul 26, 2010
292 void cancel(){ cancelled = true; }
293 int join(){ return thread.join(); }
f60e900 @tewalds Switch back to using the normal read write lock now that writer starv…
authored Oct 5, 2010
294 void run(); //thread runner, calls iterate on each iteration
295 virtual void iterate() { } //handles each iteration
63f388e @tewalds Initial multi-threaded version. Limited to one thread, but it does wo…
authored Jul 7, 2010
296 };
297
298 class PlayerUCT : public PlayerThread {
299 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 Sep 24, 2010
300 bool use_rave; //whether to use rave for this simulation
301 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 Sep 27, 2010
302 int rollout_pattern_offset; //where to start the rollout pattern
b61a518 @tewalds Move the weightedrandom data structure into the thread context so it …
authored Sep 29, 2010
303 WeightedRandTree wtree; //struct to hold the valued for weighted random values
7e65edb @tewalds Add a lower bound distance heuristic, optionally used as knowledge. A…
authored Sep 29, 2010
304 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 Dec 18, 2010
305 MoveList movelist;
63f388e @tewalds Initial multi-threaded version. Limited to one thread, but it does wo…
authored Jul 7, 2010
306
307 public:
308 PlayerUCT(Player * p) {
9e03444 @tewalds reset threads can decrease the number of threads, and restarts thread…
authored Jul 26, 2010
309 PlayerThread();
63f388e @tewalds Initial multi-threaded version. Limited to one thread, but it does wo…
authored Jul 7, 2010
310 player = p;
311 reset();
312 thread(bind(&PlayerUCT::run, this));
313 }
314
315 void reset(){
316 runs = 0;
317 treelen.reset();
318 gamelen.reset();
319
320 for(int p = 0; p < 2; p++)
321 for(int i = 0; i < 361; i++)
322 goodreply[p][i] = M_UNKNOWN;
2530d36 @tewalds Switch from skiprave once in so many times, to use rave and explorati…
authored Sep 24, 2010
323
324 use_rave = false;
325 use_explore = false;
9df0bbf @tewalds Add a mersenne twister random number generator, and use it to reduce …
authored Sep 27, 2010
326 rollout_pattern_offset = 0;
3487c35 @tewalds Save the win type stats in a depthstats object, add a some code to ou…
authored Oct 1, 2010
327
328 for(int a = 0; a < 2; a++)
329 for(int b = 0; b < 4; b++)
330 wintypes[a][b].reset();
63f388e @tewalds Initial multi-threaded version. Limited to one thread, but it does wo…
authored Jul 7, 2010
331 }
332
333 private:
f60e900 @tewalds Switch back to using the normal read write lock now that writer starv…
authored Oct 5, 2010
334 void iterate();
ce707ea @tewalds Refactor experience and rave to allow multiple rollouts per simulation
authored Dec 18, 2010
335 void walk_tree(Board & board, Node * node, int depth);
336 bool create_children(Board & board, Node * node, int toplay);
63f388e @tewalds Initial multi-threaded version. Limited to one thread, but it does wo…
authored Jul 7, 2010
337 void add_knowledge(Board & board, Node * node, Node * child);
e1063a1 @tewalds Add an option to decrease rave over time
authored Aug 17, 2010
338 Node * choose_move(const Node * node, int toplay, int remain) const;
23a8f28 @tewalds Fix the race condition in backing up a move by double checking it is …
authored Jul 28, 2010
339 bool do_backup(Node * node, Node * backup, int toplay);
ce707ea @tewalds Refactor experience and rave to allow multiple rollouts per simulation
authored Dec 18, 2010
340 void update_rave(const Node * node, int toplay);
9df0bbf @tewalds Add a mersenne twister random number generator, and use it to reduce …
authored Sep 27, 2010
341 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 Jul 7, 2010
342
ce707ea @tewalds Refactor experience and rave to allow multiple rollouts per simulation
authored Dec 18, 2010
343 int rollout(Board & board, Move move, int depth);
9d27a53 @tewalds Add an option to only check for instant wins for a limited amount of …
authored Sep 26, 2010
344 Move rollout_choose_move(Board & board, const Move & prev, int & doinstwin);
63f388e @tewalds Initial multi-threaded version. Limited to one thread, but it does wo…
authored Jul 7, 2010
345 Move rollout_pattern(const Board & board, const Move & move);
346 };
347
3b07ddf @tewalds Fix the read/write lock system to not starve the writer, simplifiy th…
authored Jul 24, 2010
348
cb365ad Allow the explore and ravefactor values to be set over gtp
Timo Ewalds authored Feb 28, 2010
349 public:
6beda47 Make the minimum rave_factor a constant
Timo Ewalds authored Mar 27, 2010
350
351 static const float min_rave = 0.1;
352
63f388e @tewalds Initial multi-threaded version. Limited to one thread, but it does wo…
authored Jul 7, 2010
353 bool ponder; //think during opponents time?
4da2397 @tewalds Make the number of threads configurable
authored Jul 10, 2010
354 int numthreads; //number of player threads to run
20d6697 @tewalds Make the memory limit easily configurable
authored Aug 26, 2010
355 u64 maxmem; //maximum memory for the tree in bytes
cc6d3a1 @tewalds Allow different final move selection options, keep the current defaul…
authored Aug 6, 2010
356 //final move selection
357 float msrave; //rave factor in final move selection, -1 means use number instead of value
358 float msexplore; //the UCT constant in final move selection
0ec1b32 Prepare for new knowledge initialization code
Timo Ewalds authored Apr 17, 2010
359 //tree traversal
18c886f add a simpler move struct, add a basic, though likely incomplete, RAV…
Timo Ewalds authored Feb 26, 2010
360 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 Mar 27, 2010
361 float ravefactor; //big numbers favour rave scores, small ignore it
e1063a1 @tewalds Add an option to decrease rave over time
authored Aug 18, 2010
362 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 Aug 10, 2010
363 bool knowledge; //whether to include knowledge
2530d36 @tewalds Switch from skiprave once in so many times, to use rave and explorati…
authored Sep 24, 2010
364 float userave; //what probability to use rave
365 float useexplore; //what probability to use UCT exploration
dc02794 @tewalds Reorder variables
authored Aug 5, 2010
366 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 Dec 18, 2010
367 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 Dec 18, 2010
368 float dynwiden; //dynamic widening, look at first log_dynwiden(experience) number of children, 0 to disable
369 float logdynwiden; // = log(dynwiden), cached for performance
dc02794 @tewalds Reorder variables
authored Aug 5, 2010
370 //tree building
4b36b92 Add an option to only use short rollouts, for higher quality rave upd…
Timo Ewalds authored May 4, 2010
371 bool shortrave; //only update rave values on short rollouts
dca42bd Make keeping tree optional
Timo Ewalds authored Mar 29, 2010
372 bool keeptree; //reuse the tree from the previous move
4d2b548 @tewalds Allow solving to deeper levels at node expansion
authored May 26, 2010
373 int minimax; //solve the minimax tree within the uct tree
d3bcd3f @tewalds Option to check for a draw at child creation.
authored Dec 16, 2010
374 bool detectdraw; //look for draws early, slow
4214b7b @tewalds Fix two warnings, one lack of return, one signed/unsigned comparison
authored Jun 23, 2010
375 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 Oct 5, 2010
376 bool prunesymmetry; //prune symmetric children from the move list, useful for proving but likely not for playing
0ec1b32 Prepare for new knowledge initialization code
Timo Ewalds authored Apr 17, 2010
377 //knowledge
61dbdce @tewalds Change the way knowledge is used. Let each knowledge paramater be tun…
authored Aug 10, 2010
378 int localreply; //boost for a local reply, ie a move near the previous move
379 int locality; //boost for playing near previous stones
380 int connect; //boost for having connections to edges and corners
699b9f2 @tewalds Add a size of group heuristic
authored Sep 30, 2010
381 int size; //boost for large groups
61dbdce @tewalds Change the way knowledge is used. Let each knowledge paramater be tun…
authored Aug 10, 2010
382 int bridge; //boost replying to a probe at a bridge
7e65edb @tewalds Add a lower bound distance heuristic, optionally used as knowledge. A…
authored Sep 29, 2010
383 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 Apr 17, 2010
384 //rollout
f10b673 @tewalds Let the random moves in the rollout be weighted by the root's rave va…
authored Jun 16, 2010
385 bool weightedrandom; //use a weighted shuffle for move ordering, based on the rave results
7e65edb @tewalds Add a lower bound distance heuristic, optionally used as knowledge. A…
authored Sep 29, 2010
386 bool weightedknow; //use knowledge in the weighted random values
96a004c @tewalds Add an option to limit the ring depth
authored Oct 1, 2010
387 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 Oct 1, 2010
388 float checkringdepth; //how deep to allow rings as a win condition in a rollout
ff9a09b Parameterize a few features
Timo Ewalds authored Mar 5, 2010
389 bool rolloutpattern; //play the response to a virtual connection threat in rollouts
6df57e1 @tewalds Make last good reply wins vs wins+losses options
authored Jul 10, 2010
390 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 Sep 26, 2010
391 int instantwin; //look for instant wins in rollouts
392 int instwindepth; //how deep to look for instant wins
0ec1b32 Prepare for new knowledge initialization code
Timo Ewalds authored Apr 17, 2010
393
ced4d1c Keep the tree between moves. For now that means turning off the solve…
Timo Ewalds authored Mar 28, 2010
394 Board rootboard;
63f388e @tewalds Initial multi-threaded version. Limited to one thread, but it does wo…
authored Jul 7, 2010
395 Node root;
1fdcd7e @tewalds Switch the player to use the compact tree
authored Nov 29, 2010
396 uword nodes;
2f657fa @tewalds Make the garbage collection start closer to last time, decaying slowl…
authored Oct 5, 2010
397 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 Mar 28, 2010
398
1fdcd7e @tewalds Switch the player to use the compact tree
authored Nov 29, 2010
399 CompactTree<Node> ctmem;
400
bca6d7d @tewalds Rename logfile and logname to solved_logfile and solved_logname, sinc…
authored Nov 8, 2010
401 string solved_logname;
402 FILE * solved_logfile;
5da2af0 @tewalds Garbage collect solved nodes, after optionally logging them to a file
authored Oct 7, 2010
403
2027a9e @tewalds Switch the player thread synchronization to use a threadstate with at…
authored Dec 16, 2010
404 enum ThreadState {
405 Thread_Cancelled, //threads should exit
406 Thread_Wait_Start, //threads are waiting to start
407 Thread_Running, //threads are running
408 Thread_GC, //one thread is running garbage collection, the rest are waiting
409 Thread_GC_End, //once done garbage collecting, go to wait_end instead of back to running
410 Thread_Wait_End, //threads are waiting to end
411 };
412 volatile ThreadState threadstate;
63f388e @tewalds Initial multi-threaded version. Limited to one thread, but it does wo…
authored Jul 7, 2010
413 vector<PlayerThread *> threads;
2027a9e @tewalds Switch the player thread synchronization to use a threadstate with at…
authored Dec 17, 2010
414 Barrier runbarrier, gcbarrier;
302209c Commit the beginnings of a UCT MCTS player
Timo Ewalds authored Feb 23, 2010
415
bdc8b7d Add some version of time control...
Timo Ewalds authored Feb 25, 2010
416 double time_used;
417
302209c Commit the beginnings of a UCT MCTS player
Timo Ewalds authored Feb 23, 2010
418 Player() {
ced4d1c Keep the tree between moves. For now that means turning off the solve…
Timo Ewalds authored Mar 28, 2010
419 nodes = 0;
248cf13 @tewalds Reduce the minimum gclimit to 5
authored Nov 29, 2010
420 gclimit = 5;
8a654dd Allow the player to be reused multiple times
Timo Ewalds authored Feb 28, 2010
421 time_used = 0;
141e49f The player should first consult the solver for some tactics. Spend 20…
Timo Ewalds authored Mar 4, 2010
422
bca6d7d @tewalds Rename logfile and logname to solved_logfile and solved_logname, sinc…
authored Nov 9, 2010
423 solved_logfile = NULL;
5da2af0 @tewalds Garbage collect solved nodes, after optionally logging them to a file
authored Oct 7, 2010
424
0432b72 @tewalds Add locking around children creation
authored Jul 10, 2010
425 ponder = false;
dff9d7d @tewalds Switch the atomic macros into template functions, which need some ext…
authored Aug 21, 2010
426 //#ifdef SINGLE_THREAD ... make sure only 1 thread
4da2397 @tewalds Make the number of threads configurable
authored Jul 10, 2010
427 numthreads = 1;
1fdcd7e @tewalds Switch the player to use the compact tree
authored Nov 29, 2010
428 maxmem = 1000*1024*1024;
cc6d3a1 @tewalds Allow different final move selection options, keep the current defaul…
authored Aug 6, 2010
429
6a49f8c @tewalds Make number of wins the default final move selection policy
authored Sep 10, 2010
430 msrave = -2;
431 msexplore = 0;
cc6d3a1 @tewalds Allow different final move selection options, keep the current defaul…
authored Aug 6, 2010
432
b7fba07 @tewalds Update defaults
authored Jun 26, 2010
433 explore = 0;
d03e453 @tewalds Update some default params with recent results
authored Aug 26, 2010
434 ravefactor = 500;
435 decrrave = 200;
61dbdce @tewalds Change the way knowledge is used. Let each knowledge paramater be tun…
authored Aug 10, 2010
436 knowledge = true;
2530d36 @tewalds Switch from skiprave once in so many times, to use rave and explorati…
authored Sep 24, 2010
437 userave = 1;
438 useexplore = 1;
dc02794 @tewalds Reorder variables
authored Aug 5, 2010
439 fpurgency = 1;
ce707ea @tewalds Refactor experience and rave to allow multiple rollouts per simulation
authored Dec 18, 2010
440 rollouts = 1;
97c23c4 @tewalds Add dynamic widening, so only consider the first few children, accord…
authored Dec 19, 2010
441 dynwiden = 0;
cc6d3a1 @tewalds Allow different final move selection options, keep the current defaul…
authored Aug 6, 2010
442
4b36b92 Add an option to only use short rollouts, for higher quality rave upd…
Timo Ewalds authored May 4, 2010
443 shortrave = false;
5e20d95 formatting, and disable locality by default
Timo Ewalds authored Apr 17, 2010
444 keeptree = true;
d226d91 @tewalds Enable forced move checking by default
authored May 31, 2010
445 minimax = 2;
d3bcd3f @tewalds Option to check for a draw at child creation.
authored Dec 17, 2010
446 detectdraw = false;
309f0ce @tewalds Allow the number of visits per expansion to be increased for low memo…
authored May 26, 2010
447 visitexpand = 1;
f78a468 @tewalds Add an option to prune symmetries in the player tree, useful mainly f…
authored Oct 5, 2010
448 prunesymmetry = false;
cc6d3a1 @tewalds Allow different final move selection options, keep the current defaul…
authored Aug 6, 2010
449
61dbdce @tewalds Change the way knowledge is used. Let each knowledge paramater be tun…
authored Aug 10, 2010
450 localreply = 0;
451 locality = 0;
b295851 @tewalds Set new defaults
authored Aug 26, 2010
452 connect = 20;
699b9f2 @tewalds Add a size of group heuristic
authored Sep 30, 2010
453 size = 0;
b295851 @tewalds Set new defaults
authored Aug 27, 2010
454 bridge = 25;
7e65edb @tewalds Add a lower bound distance heuristic, optionally used as knowledge. A…
authored Sep 29, 2010
455 dists = 0;
cc6d3a1 @tewalds Allow different final move selection options, keep the current defaul…
authored Aug 6, 2010
456
f10b673 @tewalds Let the random moves in the rollout be weighted by the root's rave va…
authored Jun 17, 2010
457 weightedrandom = false;
7e65edb @tewalds Add a lower bound distance heuristic, optionally used as knowledge. A…
authored Sep 29, 2010
458 weightedknow = false;
96a004c @tewalds Add an option to limit the ring depth
authored Oct 1, 2010
459 checkrings = 1.0;
460 checkringdepth = 1000;
d03e453 @tewalds Update some default params with recent results
authored Aug 26, 2010
461 rolloutpattern = false;
462 lastgoodreply = false;
463 instantwin = 0;
9d27a53 @tewalds Add an option to only check for instant wins for a limited amount of …
authored Sep 26, 2010
464 instwindepth = 1000;
bd431b7 @tewalds Remove param defaults. Since the values aren't board size dependent r…
authored Jul 30, 2010
465
edd3a86 @tewalds Initialize maxnodes properly, given ponder uses it
authored Sep 10, 2010
466
467 set_maxmem(maxmem);
468
bd431b7 @tewalds Remove param defaults. Since the values aren't board size dependent r…
authored Jul 30, 2010
469 //no threads started until a board is set
2027a9e @tewalds Switch the player thread synchronization to use a threadstate with at…
authored Dec 17, 2010
470 threadstate = Thread_Wait_Start;
302209c Commit the beginnings of a UCT MCTS player
Timo Ewalds authored Feb 23, 2010
471 }
3b07ddf @tewalds Fix the read/write lock system to not starve the writer, simplifiy th…
authored Jul 24, 2010
472 ~Player(){
2027a9e @tewalds Switch the player thread synchronization to use a threadstate with at…
authored Dec 17, 2010
473 stop_threads();
474
f60e900 @tewalds Switch back to using the normal read write lock now that writer starv…
authored Oct 5, 2010
475 numthreads = 0;
476 reset_threads(); //shut down the theads properly
477
bca6d7d @tewalds Rename logfile and logname to solved_logfile and solved_logname, sinc…
authored Nov 9, 2010
478 if(solved_logfile){
5da2af0 @tewalds Garbage collect solved nodes, after optionally logging them to a file
authored Oct 7, 2010
479 Board copy = rootboard;
480 garbage_collect(copy, & root, 0);
bca6d7d @tewalds Rename logfile and logname to solved_logfile and solved_logname, sinc…
authored Nov 9, 2010
481 fclose(solved_logfile);
5da2af0 @tewalds Garbage collect solved nodes, after optionally logging them to a file
authored Oct 7, 2010
482 }
483
1fdcd7e @tewalds Switch the player to use the compact tree
authored Nov 29, 2010
484 root.dealloc(ctmem);
485 ctmem.compact();
3b07ddf @tewalds Fix the read/write lock system to not starve the writer, simplifiy th…
authored Jul 24, 2010
486 }
2027a9e @tewalds Switch the player thread synchronization to use a threadstate with at…
authored Dec 17, 2010
487 void timedout() {
488 CAS(threadstate, Thread_Running, Thread_Wait_End);
489 CAS(threadstate, Thread_GC, Thread_GC_End);
490 }
302209c Commit the beginnings of a UCT MCTS player
Timo Ewalds authored Feb 23, 2010
491
edd3a86 @tewalds Initialize maxnodes properly, given ponder uses it
authored Sep 10, 2010
492 void set_maxmem(u64 m){
493 maxmem = m;
494 }
495
fad70d0 @tewalds Fix another race condition...
authored Dec 18, 2010
496 string statestring(){
497 switch(threadstate){
498 case Thread_Cancelled: return "Thread_Wait_Cancelled";
499 case Thread_Wait_Start: return "Thread_Wait_Start";
500 case Thread_Running: return "Thread_Running";
501 case Thread_GC: return "Thread_GC";
502 case Thread_GC_End: return "Thread_GC_End";
503 case Thread_Wait_End: return "Thread_Wait_End";
504 }
505 }
506
2027a9e @tewalds Switch the player thread synchronization to use a threadstate with at…
authored Dec 17, 2010
507 void stop_threads(){
508 if(threadstate != Thread_Wait_Start){
509 timedout();
510 runbarrier.wait();
b36db9c @tewalds Just force it into the Wait_Start state directly, it's going there an…
authored Dec 17, 2010
511 CAS(threadstate, Thread_Wait_End, Thread_Wait_Start);
e427a47 @tewalds Hopefully fix a race condition error
authored Dec 18, 2010
512 assert(threadstate == Thread_Wait_Start);
2027a9e @tewalds Switch the player thread synchronization to use a threadstate with at…
authored Dec 17, 2010
513 }
514 }
515
516 void start_threads(){
517 assert(threadstate == Thread_Wait_Start);
518 runbarrier.wait();
e427a47 @tewalds Hopefully fix a race condition error
authored Dec 18, 2010
519 CAS(threadstate, Thread_Wait_Start, Thread_Running);
2027a9e @tewalds Switch the player thread synchronization to use a threadstate with at…
authored Dec 17, 2010
520 }
521
522 void reset_threads(){ //start and end with threadstate = Thread_Wait_Start
523 assert(threadstate == Thread_Wait_Start);
f60e900 @tewalds Switch back to using the normal read write lock now that writer starv…
authored Oct 5, 2010
524
fad70d0 @tewalds Fix another race condition...
authored Dec 18, 2010
525 //wait for them to all get to the barrier
526 runbarrier.wait();
527
9e03444 @tewalds reset threads can decrease the number of threads, and restarts thread…
authored Jul 26, 2010
528 //kill all the threads
fad70d0 @tewalds Fix another race condition...
authored Dec 18, 2010
529 threadstate = Thread_Cancelled;
2fddb46 @tewalds Fix two warnings, one of which causes segfaults in some cases
authored Aug 1, 2010
530 for(unsigned int i = 0; i < threads.size(); i++)
9e03444 @tewalds reset threads can decrease the number of threads, and restarts thread…
authored Jul 26, 2010
531 threads[i]->cancel();
532
533 //make sure they exited cleanly
2fddb46 @tewalds Fix two warnings, one of which causes segfaults in some cases
authored Aug 1, 2010
534 for(unsigned int i = 0; i < threads.size(); i++)
9e03444 @tewalds reset threads can decrease the number of threads, and restarts thread…
authored Jul 26, 2010
535 threads[i]->join();
536
537 threads.clear();
538
2027a9e @tewalds Switch the player thread synchronization to use a threadstate with at…
authored Dec 17, 2010
539 threadstate = Thread_Wait_Start;
540
541 runbarrier.reset(numthreads + 1);
4f7cadb @tewalds Use a barrier instead of the rwlock to avoid a race condition where e…
authored Oct 6, 2010
542 gcbarrier.reset(numthreads);
a885585 @tewalds Hopefully fix a race condition that sometimes locked up the process w…
authored Aug 7, 2010
543
9e03444 @tewalds reset threads can decrease the number of threads, and restarts thread…
authored Jul 26, 2010
544 //start new threads
545 for(int i = 0; i < numthreads; i++)
4da2397 @tewalds Make the number of threads configurable
authored Jul 10, 2010
546 threads.push_back(new PlayerUCT(this));
3778fc2 @tewalds A few fixes to multi-threading, allow ponder
authored Jul 9, 2010
547 }
548
2da3341 @tewalds Allow multiple threads to be created, allow ponder to be switched on/off
authored Jul 11, 2010
549 void set_ponder(bool p){
550 if(ponder != p){
551 ponder = p;
2027a9e @tewalds Switch the player thread synchronization to use a threadstate with at…
authored Dec 17, 2010
552 stop_threads();
553
554 if(ponder)
555 start_threads();
3778fc2 @tewalds A few fixes to multi-threading, allow ponder
authored Jul 9, 2010
556 }
557 }
558
ced4d1c Keep the tree between moves. For now that means turning off the solve…
Timo Ewalds authored Mar 28, 2010
559 void set_board(const Board & board){
2027a9e @tewalds Switch the player thread synchronization to use a threadstate with at…
authored Dec 17, 2010
560 stop_threads();
3778fc2 @tewalds A few fixes to multi-threading, allow ponder
authored Jul 9, 2010
561
bca6d7d @tewalds Rename logfile and logname to solved_logfile and solved_logname, sinc…
authored Nov 9, 2010
562 if(solved_logfile){
5da2af0 @tewalds Garbage collect solved nodes, after optionally logging them to a file
authored Oct 7, 2010
563 Board copy = rootboard;
564 garbage_collect(copy, & root, 0);
565 }
566
ced4d1c Keep the tree between moves. For now that means turning off the solve…
Timo Ewalds authored Mar 28, 2010
567 rootboard = board;
1fdcd7e @tewalds Switch the player to use the compact tree
authored Nov 29, 2010
568 nodes -= root.dealloc(ctmem);
ced4d1c Keep the tree between moves. For now that means turning off the solve…
Timo Ewalds authored Mar 28, 2010
569 root = Node();
b930ead Set the parameters based on all the recent testing, changing by board…
Timo Ewalds authored Apr 24, 2010
570
fad70d0 @tewalds Fix another race condition...
authored Dec 18, 2010
571 reset_threads(); //needed since the threads aren't started before a board it set
2da3341 @tewalds Allow multiple threads to be created, allow ponder to be switched on/off
authored Jul 11, 2010
572
2027a9e @tewalds Switch the player thread synchronization to use a threadstate with at…
authored Dec 17, 2010
573 if(ponder)
574 start_threads();
ced4d1c Keep the tree between moves. For now that means turning off the solve…
Timo Ewalds authored Mar 28, 2010
575 }
576 void move(const Move & m){
2027a9e @tewalds Switch the player thread synchronization to use a threadstate with at…
authored Dec 17, 2010
577 stop_threads();
63f388e @tewalds Initial multi-threaded version. Limited to one thread, but it does wo…
authored Jul 7, 2010
578
bca6d7d @tewalds Rename logfile and logname to solved_logfile and solved_logname, sinc…
authored Nov 9, 2010
579 if(solved_logfile){
5da2af0 @tewalds Garbage collect solved nodes, after optionally logging them to a file
authored Oct 7, 2010
580 Board copy = rootboard;
581 garbage_collect(copy, & root, 0);
582 }
583
c826f21 @tewalds Move the uniqueness depth check into the board, always update the has…
authored Sep 17, 2010
584 rootboard.move(m, true, true);
9d34d4e Clean up keeping the subtree...
Timo Ewalds authored Apr 9, 2010
585
3b07ddf @tewalds Fix the read/write lock system to not starve the writer, simplifiy th…
authored Jul 24, 2010
586 uword nodesbefore = nodes;
61a6b44 Output the amount of the tree that is saved by keeping the tree
Timo Ewalds authored Apr 10, 2010
587
637ca46 @tewalds Don't keep the tree if there is none to keep
authored Nov 29, 2010
588 if(keeptree && root.children.num() > 0){
9d34d4e Clean up keeping the subtree...
Timo Ewalds authored Apr 9, 2010
589 Node child;
590
74af2df @tewalds Move children pointer to be managed in a class, hopefully remove the …
authored May 26, 2010
591 for(Node * i = root.children.begin(); i != root.children.end(); i++){
592 if(i->move == m){
593 child = *i; //copy the child experience to temp
594 child.swap_tree(*i); //move the child tree to temp
9d34d4e Clean up keeping the subtree...
Timo Ewalds authored Apr 9, 2010
595 break;
596 }
597 }
598
1fdcd7e @tewalds Switch the player to use the compact tree
authored Nov 29, 2010
599 nodes -= root.dealloc(ctmem);
9d34d4e Clean up keeping the subtree...
Timo Ewalds authored Apr 9, 2010
600 root = child;
601 root.swap_tree(child);
61a6b44 Output the amount of the tree that is saved by keeping the tree
Timo Ewalds authored Apr 10, 2010
602
603 if(nodesbefore > 0)
b1c50a0 @tewalds Switch from fprintf(stderr... to logerr(string), clean up tons of war…
authored Dec 1, 2010
604 logerr("Nodes before: " + to_str(nodesbefore) + ", after: " + to_str(nodes) + ", saved " + to_str(100.0*nodes/nodesbefore, 1) + "% of the tree\n");
dca42bd Make keeping tree optional
Timo Ewalds authored Mar 29, 2010
605 }else{
1fdcd7e @tewalds Switch the player to use the compact tree
authored Nov 29, 2010
606 nodes -= root.dealloc(ctmem);
dca42bd Make keeping tree optional
Timo Ewalds authored Mar 29, 2010
607 root = Node();
6a97002 Don't forget to set the previous move...
Timo Ewalds authored Apr 17, 2010
608 root.move = m;
dca42bd Make keeping tree optional
Timo Ewalds authored Mar 29, 2010
609 }
61a6b44 Output the amount of the tree that is saved by keeping the tree
Timo Ewalds authored Apr 10, 2010
610 assert(nodes == root.size());
63f388e @tewalds Initial multi-threaded version. Limited to one thread, but it does wo…
authored Jul 7, 2010
611
2dd6821 @tewalds Don't bother running the solver anymore, instead just let the threads…
authored Sep 22, 2010
612 root.exp.addwins(visitexpand+1); //+1 to compensate for the virtual loss
8efcfbc @tewalds Switch from unknown = -1 to unknown = -3 so that black_or_win and whi…
authored Dec 17, 2010
613 if(rootboard.won() < 0)
614 root.outcome = -3;
2dd6821 @tewalds Don't bother running the solver anymore, instead just let the threads…
authored Sep 22, 2010
615
2027a9e @tewalds Switch the player thread synchronization to use a threadstate with at…
authored Dec 17, 2010
616 if(ponder)
617 start_threads();
ced4d1c Keep the tree between moves. For now that means turning off the solve…
Timo Ewalds authored Mar 28, 2010
618 }
619
63f388e @tewalds Initial multi-threaded version. Limited to one thread, but it does wo…
authored Jul 7, 2010
620 double gamelen(){
621 DepthStats len;
622 for(unsigned int i = 0; i < threads.size(); i++)
623 len += threads[i]->gamelen;
624 return len.avg();
625 }
626
5da2af0 @tewalds Garbage collect solved nodes, after optionally logging them to a file
authored Oct 7, 2010
627 bool setlogfile(string name){
bca6d7d @tewalds Rename logfile and logname to solved_logfile and solved_logname, sinc…
authored Nov 9, 2010
628 if(solved_logfile)
629 fclose(solved_logfile);
5da2af0 @tewalds Garbage collect solved nodes, after optionally logging them to a file
authored Oct 7, 2010
630
bca6d7d @tewalds Rename logfile and logname to solved_logfile and solved_logname, sinc…
authored Nov 9, 2010
631 solved_logfile = fopen(name.c_str(), "a");
5da2af0 @tewalds Garbage collect solved nodes, after optionally logging them to a file
authored Oct 7, 2010
632
bca6d7d @tewalds Rename logfile and logname to solved_logfile and solved_logname, sinc…
authored Nov 9, 2010
633 if(solved_logfile)
634 solved_logname = name;
5da2af0 @tewalds Garbage collect solved nodes, after optionally logging them to a file
authored Oct 7, 2010
635 else
bca6d7d @tewalds Rename logfile and logname to solved_logfile and solved_logname, sinc…
authored Nov 9, 2010
636 solved_logname = "";
5da2af0 @tewalds Garbage collect solved nodes, after optionally logging them to a file
authored Oct 7, 2010
637
bca6d7d @tewalds Rename logfile and logname to solved_logfile and solved_logname, sinc…
authored Nov 9, 2010
638 return solved_logfile;
5da2af0 @tewalds Garbage collect solved nodes, after optionally logging them to a file
authored Oct 7, 2010
639 }
640
d9c43c8 @tewalds Flush the solved logfile after each garbage collection to avoid losin…
authored Dec 1, 2010
641 void flushlog(){
642 if(solved_logfile)
643 fflush(solved_logfile);
644 }
645
5da2af0 @tewalds Garbage collect solved nodes, after optionally logging them to a file
authored Oct 7, 2010
646 void u64buf(char * buf, uint64_t val){
647 static const char hexlookup[] = "0123456789abcdef";
648 for(int i = 15; i >= 0; i--){
649 buf[i] = hexlookup[val & 15];
650 val >>= 4;
651 }
652 buf[16] = '\0';
653 }
654
655 void logsolved(hash_t hash, const Node * node){
656 char hashbuf[17];
657 u64buf(hashbuf, hash);
b1c50a0 @tewalds Switch from fprintf(stderr... to logerr(string), clean up tons of war…
authored Dec 1, 2010
658 string s = string("0x") + hashbuf + "," + to_str(node->exp.num()) + "," + to_str(node->outcome) + "\n";
659 fprintf(solved_logfile, "%s", s.c_str());
5da2af0 @tewalds Garbage collect solved nodes, after optionally logging them to a file
authored Oct 7, 2010
660 }
661
bd537b1 @tewalds Move the stats reporting from genmove to the gtp command
authored Nov 20, 2010
662 Node * genmove(double time, int maxruns);
ced4d1c Keep the tree between moves. For now that means turning off the solve…
Timo Ewalds authored Mar 28, 2010
663 vector<Move> get_pv();
5da2af0 @tewalds Garbage collect solved nodes, after optionally logging them to a file
authored Oct 7, 2010
664 void garbage_collect(Board & board, Node * node, unsigned int limit); //destroys the board, so pass in a copy
302209c Commit the beginnings of a UCT MCTS player
Timo Ewalds authored Feb 23, 2010
665
666 protected:
811c718 @tewalds Actually finish a game, deal with the last ply not existing by runnin…
authored Jul 30, 2010
667 Node * return_move(Node * node, int toplay) const;
302209c Commit the beginnings of a UCT MCTS player
Timo Ewalds authored Feb 23, 2010
668 };
669
670 #endif
671
Something went wrong with that request. Please try again.