Skip to content
This repository
Newer
Older
100644 583 lines (492 sloc) 14.308 kb
302209cc »
2010-02-22 Commit the beginnings of a UCT MCTS player
1
2 #ifndef __PLAYER_H_
3 #define __PLAYER_H_
4
141e49fc »
2010-03-03 The player should first consult the solver for some tactics. Spend 20…
5 #include <cmath>
9d34d4ec »
2010-04-09 Clean up keeping the subtree...
6 #include <cassert>
141e49fc »
2010-03-03 The player should first consult the solver for some tactics. Spend 20…
7
3b07ddf5 »
2010-07-24 Fix the read/write lock system to not starve the writer, simplifiy th…
8 #include "types.h"
18c886f4 »
2010-02-26 add a simpler move struct, add a basic, though likely incomplete, RAV…
9 #include "move.h"
302209cc »
2010-02-22 Commit the beginnings of a UCT MCTS player
10 #include "board.h"
11 #include "time.h"
0aa0c763 »
2010-02-28 Factor the stats out into a separate file, display some better stats
12 #include "depthstats.h"
63f388e9 »
2010-07-07 Initial multi-threaded version. Limited to one thread, but it does wo…
13 #include "thread.h"
302209cc »
2010-02-22 Commit the beginnings of a UCT MCTS player
14
4214b7b3 »
2010-06-23 Fix two warnings, one lack of return, one signed/unsigned comparison
15
302209cc »
2010-02-22 Commit the beginnings of a UCT MCTS player
16 class Player {
ed6410cf »
2010-03-28 Deallocate the root properly, fixes a reverse memory leak
17 public:
0d041529 »
2010-04-10 Make ExpPair into a class, use accessor functions...
18 class ExpPair {
f9366a74 »
2010-07-10 Make ExpPair have atomic operations, forced to use int instead of flo…
19 uint32_t s, n;
20 ExpPair(uint32_t S, uint32_t N) : s(S), n(N) { }
0d041529 »
2010-04-10 Make ExpPair into a class, use accessor functions...
21 public:
22 ExpPair() : s(0), n(0) { }
f9366a74 »
2010-07-10 Make ExpPair have atomic operations, forced to use int instead of flo…
23 float avg() const { return 0.5f*s/n; }
0d041529 »
2010-04-10 Make ExpPair into a class, use accessor functions...
24 uint32_t num() const { return n; }
e03f7c04 »
2010-08-07 Add a move selection policy of choosing the one with the most wins, a…
25 uint32_t sum() const { return s/2; }
26
f9366a74 »
2010-07-10 Make ExpPair have atomic operations, forced to use int instead of flo…
27 void addvloss(){ INCR(n); }
28 void addvtie() { INCR(s); }
29 void addvwin() { PLUS(s, 2); }
30
31 void addwins(int num) { n += num; s += 2*num; }
32 void addlosses(int num){ n += num; }
1ec81f99 »
2010-04-17 add experience to each other
33 ExpPair & operator+=(const ExpPair & a){
34 s += a.s;
35 n += a.n;
36 return *this;
37 }
c49f5caa »
2010-04-22 Split knowledge out explicitly
38 ExpPair operator + (const ExpPair & a){
39 return ExpPair(s + a.s, n + a.n);
40 }
0d041529 »
2010-04-10 Make ExpPair into a class, use accessor functions...
41 ExpPair & operator*=(int m){
42 s *= m;
43 n *= m;
6911213e »
2010-04-07 Refactor storing experience in the tree
44 return *this;
45 }
46 };
47
302209cc »
2010-02-22 Commit the beginnings of a UCT MCTS player
48 struct Node {
74af2df0 »
2010-05-26 Move children pointer to be managed in a class, hopefully remove the …
49 class Children {
0432b72b »
2010-07-10 Add locking around children creation
50 static const int LOCK = 1; //needs to be cast to (Node *) at usage point
51
b7fba07c »
2010-06-26 Update defaults
52 uint32_t _num; //can be smaller, but will be padded anyway.
74af2df0 »
2010-05-26 Move children pointer to be managed in a class, hopefully remove the …
53 Node * _children;
54 public:
55 typedef Node * iterator;
8e12915b »
2010-06-23 Clean up the asserts a bit
56 Children() : _num(0), _children(NULL) { }
57 Children(int n) : _num(0), _children(NULL) { alloc(n); }
58 ~Children() { assert_empty(); }
74af2df0 »
2010-05-26 Move children pointer to be managed in a class, hopefully remove the …
59
0432b72b »
2010-07-10 Add locking around children creation
60 void assert_consistent() const { assert((_num == 0) || (_children > (Node *) LOCK)); }
8e12915b »
2010-06-23 Clean up the asserts a bit
61 void assert_empty() const { assert((_num == 0) && (_children == NULL)); }
74af2df0 »
2010-05-26 Move children pointer to be managed in a class, hopefully remove the …
62
0432b72b »
2010-07-10 Add locking around children creation
63 bool lock() { return CAS(_children, NULL, LOCK); }
64 bool unlock() { return CAS(_children, LOCK, NULL); }
65
66 void atomic_set(Children & o){
67 assert(CAS(_children, LOCK, o._children)); //undoes the lock
68 assert(CAS(_num, 0, o._num)); //keeps consistency
69 }
70
74af2df0 »
2010-05-26 Move children pointer to be managed in a class, hopefully remove the …
71 unsigned int alloc(unsigned int n){
72 assert(_num == 0);
73 assert(_children == NULL);
74 assert(n > 0);
75
76 _num = n;
77 _children = new Node[_num];
78
79 return _num;
80 }
81 void neuter(){
82 _children = 0;
83 _num = 0;
84 }
85 unsigned int dealloc(){
86 assert_consistent();
87
88 int n = _num;
89 if(_children){
90 Node * temp = _children; //CAS!
91 neuter();
92 delete[] temp;
93 }
94 return n;
95 }
96 void swap(Children & other){
97 Children temp = other;
98 other = *this;
99 *this = temp;
e98a0915 »
2010-05-26 Simple cleanup and comment
100 temp.neuter(); //to avoid problems with the destructor of temp
74af2df0 »
2010-05-26 Move children pointer to be managed in a class, hopefully remove the …
101 }
102 unsigned int num() const {
103 assert_consistent();
104 return _num;
105 }
106 bool empty() const {
107 return num() == 0;
108 }
109 Node & operator[](unsigned int offset){
0432b72b »
2010-07-10 Add locking around children creation
110 assert(_children > (Node *) LOCK);
74af2df0 »
2010-05-26 Move children pointer to be managed in a class, hopefully remove the …
111 assert(offset >= 0 && offset < _num);
112 return _children[offset];
113 }
114 Node * begin() const {
115 assert_consistent();
116 return _children;
117 }
118 Node * end() const {
119 assert_consistent();
120 return _children + _num;
121 }
122 };
123
124 public:
6911213e »
2010-04-07 Refactor storing experience in the tree
125 ExpPair rave;
126 ExpPair exp;
d27ab80f »
2010-06-23 Switch from an ExpPair to a small int, shrink the Node size by 8 byte…
127 int16_t know;
128 int16_t outcome;
74af2df0 »
2010-05-26 Move children pointer to be managed in a class, hopefully remove the …
129 Move move;
130 Move bestmove; //if outcome is set, then bestmove is the way to get there
131 Children children;
d27ab80f »
2010-06-23 Switch from an ExpPair to a small int, shrink the Node size by 8 byte…
132 //seems to need padding to multiples of 8 bytes or it segfaults?
8e8be5f0 »
2010-04-10 Backup wins in the tree, possibly proving the root
133 //don't forget to update the copy constructor/operator
302209cc »
2010-02-22 Commit the beginnings of a UCT MCTS player
134
d27ab80f »
2010-06-23 Switch from an ExpPair to a small int, shrink the Node size by 8 byte…
135 Node() : know(0), outcome(-1) { }
136 Node(const Move & m, char o = -1) : know(0), outcome(o), move(m) { }
8e8be5f0 »
2010-04-10 Backup wins in the tree, possibly proving the root
137 Node(const Node & n) { *this = n; }
9d34d4ec »
2010-04-09 Clean up keeping the subtree...
138 Node & operator = (const Node & n){
74af2df0 »
2010-05-26 Move children pointer to be managed in a class, hopefully remove the …
139 if(this != & n){ //don't copy to self
9d34d4ec »
2010-04-09 Clean up keeping the subtree...
140 //don't copy to a node that already has children
74af2df0 »
2010-05-26 Move children pointer to be managed in a class, hopefully remove the …
141 assert(children.empty());
9d34d4ec »
2010-04-09 Clean up keeping the subtree...
142
143 rave = n.rave;
144 exp = n.exp;
74af2df0 »
2010-05-26 Move children pointer to be managed in a class, hopefully remove the …
145 know = n.know;
9d34d4ec »
2010-04-09 Clean up keeping the subtree...
146 move = n.move;
8e8be5f0 »
2010-04-10 Backup wins in the tree, possibly proving the root
147 bestmove = n.bestmove;
74af2df0 »
2010-05-26 Move children pointer to be managed in a class, hopefully remove the …
148 outcome = n.outcome;
9d34d4ec »
2010-04-09 Clean up keeping the subtree...
149 }
150 return *this;
151 }
152
153 void swap_tree(Node & n){
74af2df0 »
2010-05-26 Move children pointer to be managed in a class, hopefully remove the …
154 children.swap(n.children);
ced4d1cf »
2010-03-28 Keep the tree between moves. For now that means turning off the solve…
155 }
156
157 void print() const {
c033243d »
2010-04-09 Fix size(), add Node::to_s()
158 printf("%s\n", to_s().c_str());
159 }
160 string to_s() const {
0d041529 »
2010-04-10 Make ExpPair into a class, use accessor functions...
161 return "Node: exp " + to_str(exp.avg(), 2) + "/" + to_str(exp.num()) +
162 ", rave " + to_str(rave.avg(), 2) + "/" + to_str(rave.num()) +
74af2df0 »
2010-05-26 Move children pointer to be managed in a class, hopefully remove the …
163 ", move " + to_str(move.x) + "," + to_str(move.y) + ", " + to_str(children.num());
ced4d1cf »
2010-03-28 Keep the tree between moves. For now that means turning off the solve…
164 }
165
a0fc6cfb »
2010-05-04 Fix warnings about signed/unsigned
166 unsigned int size() const {
74af2df0 »
2010-05-26 Move children pointer to be managed in a class, hopefully remove the …
167 unsigned int num = children.num();
168
169 for(Node * i = children.begin(); i != children.end(); i++)
170 num += i->size();
171
172 return num;
b9d644ed »
2010-04-08 Add a tree size function
173 }
74af2df0 »
2010-05-26 Move children pointer to be managed in a class, hopefully remove the …
174
302209cc »
2010-02-22 Commit the beginnings of a UCT MCTS player
175 ~Node(){
74af2df0 »
2010-05-26 Move children pointer to be managed in a class, hopefully remove the …
176 assert(children.empty());
302209cc »
2010-02-22 Commit the beginnings of a UCT MCTS player
177 }
178
74af2df0 »
2010-05-26 Move children pointer to be managed in a class, hopefully remove the …
179 unsigned int alloc(unsigned int num){
180 return children.alloc(num);
302209cc »
2010-02-22 Commit the beginnings of a UCT MCTS player
181 }
74af2df0 »
2010-05-26 Move children pointer to be managed in a class, hopefully remove the …
182 unsigned int dealloc(){
183 unsigned int num = 0;
f9e6f77b »
2010-04-09 Force the dealloc to be used for deallocation.
184
74af2df0 »
2010-05-26 Move children pointer to be managed in a class, hopefully remove the …
185 for(Node * i = children.begin(); i != children.end(); i++)
186 num += i->dealloc();
187 num += children.dealloc();
f9e6f77b »
2010-04-09 Force the dealloc to be used for deallocation.
188
74af2df0 »
2010-05-26 Move children pointer to be managed in a class, hopefully remove the …
189 return num;
302209cc »
2010-02-22 Commit the beginnings of a UCT MCTS player
190 }
576fa842 »
2010-03-07 Fix a few bugs: use factor instead of scale. Stop assigning rave loss…
191 //*
214afe6a »
2010-03-05 Update to a more standard way of doing rave scores.
192 //new way, more standard way of changing over from rave scores to real scores
61dbdce6 »
2010-08-10 Change the way knowledge is used. Let each knowledge paramater be tun…
193 float value(float ravefactor, bool knowledge, float fpurgency){
b1353365 »
2010-06-23 Use an independent knowledge factor instead of extra experience
194 float val = fpurgency;
195
196 if(ravefactor <= min_rave){
197 if(exp.num() > 0)
198 val = exp.avg();
199 }else if(rave.num() || exp.num()){
200 float alpha = ravefactor/(ravefactor + exp.num());
201 // float alpha = sqrt(ravefactor/(ravefactor + 3*exp.num()));
202 // float alpha = (float)rave.num()/((float)exp.num() + (float)rave.num() + 4.0*exp.num()*rave.num()*ravefactor);
203
204 val = 0;
205 if(rave.num()) val += alpha*rave.avg();
206 if(exp.num()) val += (1-alpha)*exp.avg();
207 }
214afe6a »
2010-03-05 Update to a more standard way of doing rave scores.
208
61dbdce6 »
2010-08-10 Change the way knowledge is used. Let each knowledge paramater be tun…
209 if(knowledge && know > 0)
210 val += 0.01f * know / sqrt((float)(exp.num() + 1));
7cc84b29 »
2010-03-06 Avoid a potential divide by 0, set the explore rate based on tests of…
211
212 return val;
214afe6a »
2010-03-05 Update to a more standard way of doing rave scores.
213 }
576fa842 »
2010-03-07 Fix a few bugs: use factor instead of scale. Stop assigning rave loss…
214 /*/
214afe6a »
2010-03-05 Update to a more standard way of doing rave scores.
215 //my understanding of how fuego does it
22038b14 »
2010-03-27 Major refactoring of UCT/RAVE. Pulled rave updates out of walk_tree. …
216 float value(float ravefactor, float fpurgency){
214afe6a »
2010-03-05 Update to a more standard way of doing rave scores.
217 float val = 0;
218 float weight = 0;
219 if(visits) {
220 val += score;
221 weight += visits;
222 }
576fa842 »
2010-03-07 Fix a few bugs: use factor instead of scale. Stop assigning rave loss…
223 if(ravevisits){
cd8a3a94 »
2010-03-25 Update the fuego based value function, fix a misunderstanding as well…
224 float bias = 1.0/(1.1 + ravevisits/20000.0);
225 val += rave*bias;
226 weight += ravevisits*bias;
214afe6a »
2010-03-05 Update to a more standard way of doing rave scores.
227 }
228 if(weight > 0)
229 return val / weight;
230 else
cd8a3a94 »
2010-03-25 Update the fuego based value function, fix a misunderstanding as well…
231 return fpurgency;
232 }
233
234 //based directly on fuego
22038b14 »
2010-03-27 Major refactoring of UCT/RAVE. Pulled rave updates out of walk_tree. …
235 float value(float ravefactor, float fpurgency){
cd8a3a94 »
2010-03-25 Update the fuego based value function, fix a misunderstanding as well…
236 float val = 0.f;
237 float weightSum = 0.f;
238 bool hasValue = false;
239 if(visits){
240 val += score;
241 weightSum += visits;
242 hasValue = true;
243 }
244 if(ravevisits){
245 float weight = ravevisits / ( 1.1 + ravevisits/20000.);
246 val += weight * rave / ravevisits;
247 weightSum += weight;
248 hasValue = true;
249 }
250 if(hasValue)
251 return val / weightSum;
252 else
253 return fpurgency;
214afe6a »
2010-03-05 Update to a more standard way of doing rave scores.
254 }
cd8a3a94 »
2010-03-25 Update the fuego based value function, fix a misunderstanding as well…
255
214afe6a »
2010-03-05 Update to a more standard way of doing rave scores.
256 //*/
302209cc »
2010-02-22 Commit the beginnings of a UCT MCTS player
257 };
258
7149ea6e »
2010-03-05 Add an option to make the rave scores scale from 2 down to 0
259 struct RaveMoveList {
11996069 »
2010-04-18 Some cleanups to rave...
260 struct RaveMove : public Move {
609a9713 »
2010-03-09 Fix rave values so it updates wins to the winner and losses to the lo…
261 char player;
262
f9366a74 »
2010-07-10 Make ExpPair have atomic operations, forced to use int instead of flo…
263 RaveMove(const Move & m, char p = 0) : Move(m), player(p) { }
609a9713 »
2010-03-09 Fix rave values so it updates wins to the winner and losses to the lo…
264 };
71d4142e »
2010-04-18 Rewrite update_rave to use iterators, which makes it a bit faster, an…
265 typedef vector<RaveMove>::const_iterator iterator;
609a9713 »
2010-03-09 Fix rave values so it updates wins to the winner and losses to the lo…
266
267 vector<RaveMove> list;
7149ea6e »
2010-03-05 Add an option to make the rave scores scale from 2 down to 0
268
269 RaveMoveList(int s = 0){
270 list.reserve(s);
271 }
272
11996069 »
2010-04-18 Some cleanups to rave...
273 void add(const Move & move, char player){
f9366a74 »
2010-07-10 Make ExpPair have atomic operations, forced to use int instead of flo…
274 list.push_back(RaveMove(move, player));
7149ea6e »
2010-03-05 Add an option to make the rave scores scale from 2 down to 0
275 }
276 void clear(){
277 list.clear();
278 }
22038b14 »
2010-03-27 Major refactoring of UCT/RAVE. Pulled rave updates out of walk_tree. …
279 unsigned int size() const {
7149ea6e »
2010-03-05 Add an option to make the rave scores scale from 2 down to 0
280 return list.size();
281 }
609a9713 »
2010-03-09 Fix rave values so it updates wins to the winner and losses to the lo…
282 const RaveMove & operator[](int i) const {
7149ea6e »
2010-03-05 Add an option to make the rave scores scale from 2 down to 0
283 return list[i];
284 }
71d4142e »
2010-04-18 Rewrite update_rave to use iterators, which makes it a bit faster, an…
285 iterator begin() const {
286 return list.begin();
287 }
288 iterator end() const {
289 return list.end();
290 }
7149ea6e »
2010-03-05 Add an option to make the rave scores scale from 2 down to 0
291 //sort in y,x order
f9366a74 »
2010-07-10 Make ExpPair have atomic operations, forced to use int instead of flo…
292 void clean(){
576fa842 »
2010-03-07 Fix a few bugs: use factor instead of scale. Stop assigning rave loss…
293 sort(list.begin(), list.end()); //sort in y,x order
7149ea6e »
2010-03-05 Add an option to make the rave scores scale from 2 down to 0
294 }
295 };
296
63f388e9 »
2010-07-07 Initial multi-threaded version. Limited to one thread, but it does wo…
297 class PlayerThread {
298 protected:
2da33412 »
2010-07-10 Allow multiple threads to be created, allow ponder to be switched on/off
299 public:
63f388e9 »
2010-07-07 Initial multi-threaded version. Limited to one thread, but it does wo…
300 Thread thread;
301 Player * player;
9e034448 »
2010-07-26 reset threads can decrease the number of threads, and restarts thread…
302 bool cancelled;
3778fc2d »
2010-07-09 A few fixes to multi-threading, allow ponder
303 public:
ee53b230 »
2010-07-30 Let maxruns work again. It doesn't make much sense with ponder, and w…
304 int runs, maxruns;
63f388e9 »
2010-07-07 Initial multi-threaded version. Limited to one thread, but it does wo…
305 DepthStats treelen, gamelen;
306
ee53b230 »
2010-07-30 Let maxruns work again. It doesn't make much sense with ponder, and w…
307 PlayerThread() : cancelled(false), runs(0), maxruns(0) {}
63f388e9 »
2010-07-07 Initial multi-threaded version. Limited to one thread, but it does wo…
308 virtual void reset() { }
9e034448 »
2010-07-26 reset threads can decrease the number of threads, and restarts thread…
309 void cancel(){ cancelled = true; }
310 int join(){ return thread.join(); }
63f388e9 »
2010-07-07 Initial multi-threaded version. Limited to one thread, but it does wo…
311 };
312
313 class PlayerUCT : public PlayerThread {
314 Move goodreply[2][361]; //361 is big enough for size 10 (ie 19x19), but no bigger...
315
316 public:
317 PlayerUCT(Player * p) {
9e034448 »
2010-07-26 reset threads can decrease the number of threads, and restarts thread…
318 PlayerThread();
63f388e9 »
2010-07-07 Initial multi-threaded version. Limited to one thread, but it does wo…
319 player = p;
320 reset();
321 thread(bind(&PlayerUCT::run, this));
322 }
323
324 void reset(){
325 runs = 0;
326 treelen.reset();
327 gamelen.reset();
328
329 for(int p = 0; p < 2; p++)
330 for(int i = 0; i < 361; i++)
331 goodreply[p][i] = M_UNKNOWN;
332 }
333
334 private:
335 void run();
336 int walk_tree(Board & board, Node * node, RaveMoveList & movelist, int depth);
81444d82 »
2010-07-10 Refactor creating children into a separate function
337 int create_children(Board & board, Node * node, int toplay);
63f388e9 »
2010-07-07 Initial multi-threaded version. Limited to one thread, but it does wo…
338 void add_knowledge(Board & board, Node * node, Node * child);
e1063a15 »
2010-08-17 Add an option to decrease rave over time
339 Node * choose_move(const Node * node, int toplay, int remain) const;
23a8f28e »
2010-07-28 Fix the race condition in backing up a move by double checking it is …
340 bool do_backup(Node * node, Node * backup, int toplay);
63f388e9 »
2010-07-07 Initial multi-threaded version. Limited to one thread, but it does wo…
341 void update_rave(const Node * node, const RaveMoveList & movelist, int won, int toplay);
342 bool test_bridge_probe(const Board & board, const Move & move, const Move & test);
343
344 int rollout(Board & board, RaveMoveList & movelist, Move move, int depth);
345 Move rollout_choose_move(Board & board, const Move & prev);
346 Move rollout_pattern(const Board & board, const Move & move);
347 };
348
3b07ddf5 »
2010-07-24 Fix the read/write lock system to not starve the writer, simplifiy th…
349 class Sync {
350 RWLock lock; // stop the thread runners from doing work
351 CondVar cond; // tell the master thread that the threads are done
352 volatile bool stop; // write lock asked
353 volatile bool writelock; //is the write lock
354
355 public:
356 Sync() : stop(false), writelock(false) { }
357
358 int wrlock(){ //aquire the write lock, set stop, blocks
359 assert(writelock == false);
360
361 // fprintf(stderr, "ask write lock\n");
362
363 CAS(stop, false, true);
364 int r = lock.wrlock();
365 writelock = true;
366 CAS(stop, true, false);
367 // fprintf(stderr, "got write lock\n");
368 return r;
369 }
370 int rdlock(){ //aquire the read lock, blocks
371 // fprintf(stderr, "Ask for read lock\n");
9e034448 »
2010-07-26 reset threads can decrease the number of threads, and restarts thread…
372 if(stop){ //spin on the read lock so that the write lock isn't starved
3b07ddf5 »
2010-07-24 Fix the read/write lock system to not starve the writer, simplifiy th…
373 // fprintf(stderr, "Spinning on read lock\n");
374 while(stop)
375 continue;
376 // fprintf(stderr, "Done spinning on read lock\n");
377 }
378 int ret = lock.rdlock();
379 // fprintf(stderr, "Got a read lock\n");
380 return ret;
381 }
382 int relock(){ //succeeds if stop isn't requested
383 return (stop == false);
384 }
385 int unlock(){ //unlocks the lock
386 if(writelock){
387 // fprintf(stderr, "unlock read lock\n");
388 }else{
389 // fprintf(stderr, "unlock write lock\n");
390 }
391 writelock = false;
392 return lock.unlock();
393 }
394 int done(){ //signals that the timeout happened or solved
395 return cond.broadcast();
396 }
397 int wait(){ //waits for the signal
398 cond.lock(); //lock the signal that defines the end condition
2fddb463 »
2010-08-01 Fix two warnings, one of which causes segfaults in some cases
399 int ret = cond.wait(); //wait a signal to end (could be from the timer)
3b07ddf5 »
2010-07-24 Fix the read/write lock system to not starve the writer, simplifiy th…
400 cond.unlock();
2fddb463 »
2010-08-01 Fix two warnings, one of which causes segfaults in some cases
401 return ret;
3b07ddf5 »
2010-07-24 Fix the read/write lock system to not starve the writer, simplifiy th…
402 }
403 };
404
cb365ad3 »
2010-02-28 Allow the explore and ravefactor values to be set over gtp
405 public:
6beda471 »
2010-03-27 Make the minimum rave_factor a constant
406
407 static const float min_rave = 0.1;
408
63f388e9 »
2010-07-07 Initial multi-threaded version. Limited to one thread, but it does wo…
409 bool ponder; //think during opponents time?
4da2397b »
2010-07-10 Make the number of threads configurable
410 int numthreads; //number of player threads to run
cc6d3a1b »
2010-08-06 Allow different final move selection options, keep the current defaul…
411 //final move selection
412 float msrave; //rave factor in final move selection, -1 means use number instead of value
413 float msexplore; //the UCT constant in final move selection
0ec1b327 »
2010-04-17 Prepare for new knowledge initialization code
414 //tree traversal
18c886f4 »
2010-02-26 add a simpler move struct, add a basic, though likely incomplete, RAV…
415 float explore; //greater than one favours exploration, smaller than one favours exploitation
22038b14 »
2010-03-27 Major refactoring of UCT/RAVE. Pulled rave updates out of walk_tree. …
416 float ravefactor; //big numbers favour rave scores, small ignore it
e1063a15 »
2010-08-17 Add an option to decrease rave over time
417 float decrrave; //decrease rave over time, add this value for each empty position on the board
61dbdce6 »
2010-08-10 Change the way knowledge is used. Let each knowledge paramater be tun…
418 bool knowledge; //whether to include knowledge
8d2523bd »
2010-03-11 Allow the first play urgency to be configured
419 int skiprave; //how often to skip rave, skip once in this many checks
dc027945 »
2010-08-05 Reorder variables
420 float fpurgency; //what value to return for a move that hasn't been played yet
421 //tree building
4b36b92c »
2010-05-04 Add an option to only use short rollouts, for higher quality rave upd…
422 bool shortrave; //only update rave values on short rollouts
dca42bd0 »
2010-03-29 Make keeping tree optional
423 bool keeptree; //reuse the tree from the previous move
4d2b548a »
2010-05-26 Allow solving to deeper levels at node expansion
424 int minimax; //solve the minimax tree within the uct tree
4214b7b3 »
2010-06-23 Fix two warnings, one lack of return, one signed/unsigned comparison
425 uint visitexpand;//number of visits before expanding a node
0ec1b327 »
2010-04-17 Prepare for new knowledge initialization code
426 //knowledge
61dbdce6 »
2010-08-10 Change the way knowledge is used. Let each knowledge paramater be tun…
427 int localreply; //boost for a local reply, ie a move near the previous move
428 int locality; //boost for playing near previous stones
429 int connect; //boost for having connections to edges and corners
430 int bridge; //boost replying to a probe at a bridge
0ec1b327 »
2010-04-17 Prepare for new knowledge initialization code
431 //rollout
f10b6738 »
2010-06-16 Let the random moves in the rollout be weighted by the root's rave va…
432 bool weightedrandom; //use a weighted shuffle for move ordering, based on the rave results
ff9a09be »
2010-03-05 Parameterize a few features
433 bool rolloutpattern; //play the response to a virtual connection threat in rollouts
f10b6738 »
2010-06-16 Let the random moves in the rollout be weighted by the root's rave va…
434 int instantwin; //look for instant wins in rollouts
6df57e13 »
2010-07-10 Make last good reply wins vs wins+losses options
435 int lastgoodreply; //use the last-good-reply rollout heuristic
0ec1b327 »
2010-04-17 Prepare for new knowledge initialization code
436
ced4d1cf »
2010-03-28 Keep the tree between moves. For now that means turning off the solve…
437 Board rootboard;
63f388e9 »
2010-07-07 Initial multi-threaded version. Limited to one thread, but it does wo…
438 Node root;
3b07ddf5 »
2010-07-24 Fix the read/write lock system to not starve the writer, simplifiy th…
439 uword nodes, maxnodes;
ced4d1cf »
2010-03-28 Keep the tree between moves. For now that means turning off the solve…
440
63f388e9 »
2010-07-07 Initial multi-threaded version. Limited to one thread, but it does wo…
441 vector<PlayerThread *> threads;
3b07ddf5 »
2010-07-24 Fix the read/write lock system to not starve the writer, simplifiy th…
442 Sync sync;
302209cc »
2010-02-22 Commit the beginnings of a UCT MCTS player
443
bdc8b7da »
2010-02-25 Add some version of time control...
444 double time_used;
445
302209cc »
2010-02-22 Commit the beginnings of a UCT MCTS player
446 Player() {
ced4d1cf »
2010-03-28 Keep the tree between moves. For now that means turning off the solve…
447 nodes = 0;
8a654dd8 »
2010-02-28 Allow the player to be reused multiple times
448 time_used = 0;
141e49fc »
2010-03-03 The player should first consult the solver for some tactics. Spend 20…
449
0432b72b »
2010-07-10 Add locking around children creation
450 ponder = false;
4da2397b »
2010-07-10 Make the number of threads configurable
451 numthreads = 1;
cc6d3a1b »
2010-08-06 Allow different final move selection options, keep the current defaul…
452
453 msrave = -1;
454 msexplore = 1.0;
455
b7fba07c »
2010-06-26 Update defaults
456 explore = 0;
457 ravefactor = 1000;
e1063a15 »
2010-08-17 Add an option to decrease rave over time
458 decrrave = 0;
61dbdce6 »
2010-08-10 Change the way knowledge is used. Let each knowledge paramater be tun…
459 knowledge = true;
5e20d954 »
2010-04-17 formatting, and disable locality by default
460 skiprave = 0;
dc027945 »
2010-08-05 Reorder variables
461 fpurgency = 1;
cc6d3a1b »
2010-08-06 Allow different final move selection options, keep the current defaul…
462
4b36b92c »
2010-05-04 Add an option to only use short rollouts, for higher quality rave upd…
463 shortrave = false;
5e20d954 »
2010-04-17 formatting, and disable locality by default
464 keeptree = true;
d226d919 »
2010-05-31 Enable forced move checking by default
465 minimax = 2;
309f0ce3 »
2010-05-26 Allow the number of visits per expansion to be increased for low memo…
466 visitexpand = 1;
cc6d3a1b »
2010-08-06 Allow different final move selection options, keep the current defaul…
467
61dbdce6 »
2010-08-10 Change the way knowledge is used. Let each knowledge paramater be tun…
468 localreply = 0;
469 locality = 0;
470 connect = 20;
471 bridge = 10;
cc6d3a1b »
2010-08-06 Allow different final move selection options, keep the current defaul…
472
f10b6738 »
2010-06-16 Let the random moves in the rollout be weighted by the root's rave va…
473 weightedrandom = false;
b930eada »
2010-04-24 Set the parameters based on all the recent testing, changing by board…
474 rolloutpattern = true;
f08fab72 »
2010-06-07 Add the last-good-reply rollout heuristic, disable swap during rollou…
475 lastgoodreply = false;
476 instantwin = 0;
bd431b73 »
2010-07-30 Remove param defaults. Since the values aren't board size dependent r…
477
478 //no threads started until a board is set
479
480 if(!ponder)
481 sync.wrlock();
302209cc »
2010-02-22 Commit the beginnings of a UCT MCTS player
482 }
3b07ddf5 »
2010-07-24 Fix the read/write lock system to not starve the writer, simplifiy th…
483 ~Player(){
484 if(ponder)
485 sync.wrlock();
486 root.dealloc();
487 }
488 void timedout() { sync.done(); }
302209cc »
2010-02-22 Commit the beginnings of a UCT MCTS player
489
2da33412 »
2010-07-10 Allow multiple threads to be created, allow ponder to be switched on/off
490 void reset_threads(){ //better have the write lock before calling this
9e034448 »
2010-07-26 reset threads can decrease the number of threads, and restarts thread…
491 //kill all the threads
2fddb463 »
2010-08-01 Fix two warnings, one of which causes segfaults in some cases
492 for(unsigned int i = 0; i < threads.size(); i++)
9e034448 »
2010-07-26 reset threads can decrease the number of threads, and restarts thread…
493 threads[i]->cancel();
494
a8855851 »
2010-08-07 Hopefully fix a race condition that sometimes locked up the process w…
495 sync.unlock(); //let the runners run and exit since rdlock is not a cancellation point
9e034448 »
2010-07-26 reset threads can decrease the number of threads, and restarts thread…
496
497 //make sure they exited cleanly
2fddb463 »
2010-08-01 Fix two warnings, one of which causes segfaults in some cases
498 for(unsigned int i = 0; i < threads.size(); i++)
9e034448 »
2010-07-26 reset threads can decrease the number of threads, and restarts thread…
499 threads[i]->join();
500
501 threads.clear();
502
a8855851 »
2010-08-07 Hopefully fix a race condition that sometimes locked up the process w…
503 sync.wrlock(); //lock so the new threads don't run
504
9e034448 »
2010-07-26 reset threads can decrease the number of threads, and restarts thread…
505 //start new threads
506 for(int i = 0; i < numthreads; i++)
4da2397b »
2010-07-10 Make the number of threads configurable
507 threads.push_back(new PlayerUCT(this));
3778fc2d »
2010-07-09 A few fixes to multi-threading, allow ponder
508 }
509
2da33412 »
2010-07-10 Allow multiple threads to be created, allow ponder to be switched on/off
510 void set_ponder(bool p){
511 if(ponder != p){
3b07ddf5 »
2010-07-24 Fix the read/write lock system to not starve the writer, simplifiy th…
512 if(p) sync.unlock();
513 else sync.wrlock();
2da33412 »
2010-07-10 Allow multiple threads to be created, allow ponder to be switched on/off
514 ponder = p;
3778fc2d »
2010-07-09 A few fixes to multi-threading, allow ponder
515 }
516 }
517
ced4d1cf »
2010-03-28 Keep the tree between moves. For now that means turning off the solve…
518 void set_board(const Board & board){
3778fc2d »
2010-07-09 A few fixes to multi-threading, allow ponder
519 if(ponder)
3b07ddf5 »
2010-07-24 Fix the read/write lock system to not starve the writer, simplifiy th…
520 sync.wrlock();
3778fc2d »
2010-07-09 A few fixes to multi-threading, allow ponder
521
ced4d1cf »
2010-03-28 Keep the tree between moves. For now that means turning off the solve…
522 rootboard = board;
ed6410cf »
2010-03-28 Deallocate the root properly, fixes a reverse memory leak
523 nodes -= root.dealloc();
ced4d1cf »
2010-03-28 Keep the tree between moves. For now that means turning off the solve…
524 root = Node();
b930eada »
2010-04-24 Set the parameters based on all the recent testing, changing by board…
525
2da33412 »
2010-07-10 Allow multiple threads to be created, allow ponder to be switched on/off
526 reset_threads();
527
3778fc2d »
2010-07-09 A few fixes to multi-threading, allow ponder
528 if(ponder)
3b07ddf5 »
2010-07-24 Fix the read/write lock system to not starve the writer, simplifiy th…
529 sync.unlock();
ced4d1cf »
2010-03-28 Keep the tree between moves. For now that means turning off the solve…
530 }
531 void move(const Move & m){
63f388e9 »
2010-07-07 Initial multi-threaded version. Limited to one thread, but it does wo…
532 if(ponder)
3b07ddf5 »
2010-07-24 Fix the read/write lock system to not starve the writer, simplifiy th…
533 sync.wrlock();
63f388e9 »
2010-07-07 Initial multi-threaded version. Limited to one thread, but it does wo…
534
ce05c67c »
2010-04-17 Actually update the locality scores...
535 rootboard.move(m, true);
9d34d4ec »
2010-04-09 Clean up keeping the subtree...
536
3b07ddf5 »
2010-07-24 Fix the read/write lock system to not starve the writer, simplifiy th…
537 uword nodesbefore = nodes;
61a6b449 »
2010-04-10 Output the amount of the tree that is saved by keeping the tree
538
dca42bd0 »
2010-03-29 Make keeping tree optional
539 if(keeptree){
9d34d4ec »
2010-04-09 Clean up keeping the subtree...
540 Node child;
541
74af2df0 »
2010-05-26 Move children pointer to be managed in a class, hopefully remove the …
542 for(Node * i = root.children.begin(); i != root.children.end(); i++){
543 if(i->move == m){
544 child = *i; //copy the child experience to temp
545 child.swap_tree(*i); //move the child tree to temp
9d34d4ec »
2010-04-09 Clean up keeping the subtree...
546 break;
547 }
548 }
549
dca42bd0 »
2010-03-29 Make keeping tree optional
550 nodes -= root.dealloc();
9d34d4ec »
2010-04-09 Clean up keeping the subtree...
551 root = child;
552 root.swap_tree(child);
61a6b449 »
2010-04-10 Output the amount of the tree that is saved by keeping the tree
553
554 if(nodesbefore > 0)
3b07ddf5 »
2010-07-24 Fix the read/write lock system to not starve the writer, simplifiy th…
555 fprintf(stderr, "Nodes before: %u, after: %u, saved %.1f%% of the tree\n", nodesbefore, nodes, 100.0*nodes/nodesbefore);
dca42bd0 »
2010-03-29 Make keeping tree optional
556 }else{
557 nodes -= root.dealloc();
558 root = Node();
6a970024 »
2010-04-17 Don't forget to set the previous move...
559 root.move = m;
dca42bd0 »
2010-03-29 Make keeping tree optional
560 }
61a6b449 »
2010-04-10 Output the amount of the tree that is saved by keeping the tree
561 assert(nodes == root.size());
63f388e9 »
2010-07-07 Initial multi-threaded version. Limited to one thread, but it does wo…
562
563 if(ponder)
3b07ddf5 »
2010-07-24 Fix the read/write lock system to not starve the writer, simplifiy th…
564 sync.unlock();
ced4d1cf »
2010-03-28 Keep the tree between moves. For now that means turning off the solve…
565 }
566
63f388e9 »
2010-07-07 Initial multi-threaded version. Limited to one thread, but it does wo…
567 double gamelen(){
568 DepthStats len;
569 for(unsigned int i = 0; i < threads.size(); i++)
570 len += threads[i]->gamelen;
571 return len.avg();
572 }
573
574 Move genmove(double time, int maxruns, uint64_t memlimit);
ced4d1cf »
2010-03-28 Keep the tree between moves. For now that means turning off the solve…
575 vector<Move> get_pv();
302209cc »
2010-02-22 Commit the beginnings of a UCT MCTS player
576
577 protected:
811c7186 »
2010-07-30 Actually finish a game, deal with the last ply not existing by runnin…
578 Node * return_move(Node * node, int toplay) const;
302209cc »
2010-02-22 Commit the beginnings of a UCT MCTS player
579 };
580
581 #endif
582
Something went wrong with that request. Please try again.