Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 497 lines (436 sloc) 12.477 kb
302209cc » Timo Ewalds
2010-02-22 Commit the beginnings of a UCT MCTS player
1
2 #ifndef __PLAYER_H_
3 #define __PLAYER_H_
4
141e49fc » Timo Ewalds
2010-03-03 The player should first consult the solver for some tactics. Spend 20…
5 #include <stdint.h>
6 #include <cmath>
9d34d4ec » Timo Ewalds
2010-04-09 Clean up keeping the subtree...
7 #include <cassert>
141e49fc » Timo Ewalds
2010-03-03 The player should first consult the solver for some tactics. Spend 20…
8
18c886f4 » Timo Ewalds
2010-02-26 add a simpler move struct, add a basic, though likely incomplete, RAV…
9 #include "move.h"
302209cc » Timo Ewalds
2010-02-22 Commit the beginnings of a UCT MCTS player
10 #include "board.h"
11 #include "time.h"
12 #include "timer.h"
0aa0c763 » Timo Ewalds
2010-02-28 Factor the stats out into a separate file, display some better stats
13 #include "depthstats.h"
141e49fc » Timo Ewalds
2010-03-03 The player should first consult the solver for some tactics. Spend 20…
14 #include "solver.h"
302209cc » Timo Ewalds
2010-02-22 Commit the beginnings of a UCT MCTS player
15
16 class Player {
ed6410cf » Timo Ewalds
2010-03-28 Deallocate the root properly, fixes a reverse memory leak
17 public:
06950e84 » Timo Ewalds
2010-04-10 Add a version of ExpPair that updates the value incrementally, and al…
18 //*
0d041529 » Timo Ewalds
2010-04-10 Make ExpPair into a class, use accessor functions...
19 class ExpPair {
20 float s;
21 uint32_t n;
22 public:
23 ExpPair() : s(0), n(0) { }
24 ExpPair(float S, uint32_t N) : s(S), n(N) { }
25 float avg() const { return s/n; }
26 float sum() const { return s; }
27 uint32_t num() const { return n; }
1711836a » Timo Ewalds
2010-04-22 Add the option to add losses instead of just wins
28 void addwins(int num){ add(num, num); }
29 void addlosses(int num){ add(0, num); }
1ec81f99 » Timo Ewalds
2010-04-17 add experience to each other
30 void add(float val, int num){
31 s += val;
32 n += num;
33 }
34 ExpPair & operator+=(const ExpPair & a){
35 s += a.s;
36 n += a.n;
37 return *this;
38 }
0d041529 » Timo Ewalds
2010-04-10 Make ExpPair into a class, use accessor functions...
39 ExpPair & operator+=(float nv){
40 s += nv;
41 n++;
6911213e » Timo Ewalds
2010-04-07 Refactor storing experience in the tree
42 return *this;
43 }
c49f5caa » Timo Ewalds
2010-04-22 Split knowledge out explicitly
44 ExpPair operator + (const ExpPair & a){
45 return ExpPair(s + a.s, n + a.n);
46 }
0d041529 » Timo Ewalds
2010-04-10 Make ExpPair into a class, use accessor functions...
47 ExpPair & operator*=(int m){
48 s *= m;
49 n *= m;
6911213e » Timo Ewalds
2010-04-07 Refactor storing experience in the tree
50 return *this;
51 }
52 };
06950e84 » Timo Ewalds
2010-04-10 Add a version of ExpPair that updates the value incrementally, and al…
53 /*/
54 class ExpPair {
aa844d59 » Timo Ewalds
2010-04-25 Update recency weighted ExpPair to work with knowledge...
55 static const float k = 10000;
06950e84 » Timo Ewalds
2010-04-10 Add a version of ExpPair that updates the value incrementally, and al…
56 float v;
57 uint32_t n;
58 public:
59 ExpPair() : v(0), n(0) { }
60 ExpPair(float S, uint32_t N) : v(S/N), n(N) { }
61 float avg() const { return v; }
62 float sum() const { return v*n; }
63 uint32_t num() const { return n; }
aa844d59 » Timo Ewalds
2010-04-25 Update recency weighted ExpPair to work with knowledge...
64 void addwins(int num){ add(num, num); }
65 void addlosses(int num){ add(0, num); }
66 void add(float val, int num){
67 *this += ExpPair(val, num);
68 }
69 ExpPair & operator+=(const ExpPair & a){
70 //there's got to be a better way...
71 for(int i = 0; i < a.n; i++)
72 *this += a.v;
73 return *this;
74 }
06950e84 » Timo Ewalds
2010-04-10 Add a version of ExpPair that updates the value incrementally, and al…
75 ExpPair & operator+=(float nv){
76 n++;
aa844d59 » Timo Ewalds
2010-04-25 Update recency weighted ExpPair to work with knowledge...
77 // v += (nv - v)/n;
78 v += (nv - v)/(n < k ? n : k);
06950e84 » Timo Ewalds
2010-04-10 Add a version of ExpPair that updates the value incrementally, and al…
79 return *this;
80 }
aa844d59 » Timo Ewalds
2010-04-25 Update recency weighted ExpPair to work with knowledge...
81 ExpPair operator + (const ExpPair & a){
82 ExpPair ret = *this;
83 ret += a;
84 return ret;
85 }
06950e84 » Timo Ewalds
2010-04-10 Add a version of ExpPair that updates the value incrementally, and al…
86 ExpPair & operator*=(int m){
87 n *= m;
88 return *this;
89 }
90 };
91 //*/
6911213e » Timo Ewalds
2010-04-07 Refactor storing experience in the tree
92
302209cc » Timo Ewalds
2010-02-22 Commit the beginnings of a UCT MCTS player
93 struct Node {
74af2df0 »
2010-05-26 Move children pointer to be managed in a class, hopefully remove the …
94 class Children {
95 uint16_t _num;
96 Node * _children;
97 public:
98 typedef Node * iterator;
99 Children() : _num(0), _children(NULL) { }
100 Children(int n) { alloc(n); }
101 ~Children() { assert(_num == 0 && _children == NULL); }
102
103 void assert_consistent() const { assert((_num == 0) == (_children == NULL)); };
104 void assert_empty() const { assert(empty()); }
105
106 unsigned int alloc(unsigned int n){
107 assert(_num == 0);
108 assert(_children == NULL);
109 assert(n > 0);
110
111 _num = n;
112 _children = new Node[_num];
113
114 return _num;
115 }
116 void neuter(){
117 _children = 0;
118 _num = 0;
119 }
120 unsigned int dealloc(){
121 assert_consistent();
122
123 int n = _num;
124 if(_children){
125 Node * temp = _children; //CAS!
126 neuter();
127 delete[] temp;
128 }
129 return n;
130 }
131 void swap(Children & other){
132 Children temp = other;
133 other = *this;
134 *this = temp;
e98a0915 »
2010-05-26 Simple cleanup and comment
135 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 …
136 }
137 unsigned int num() const {
138 assert_consistent();
139 return _num;
140 }
141 bool empty() const {
142 return num() == 0;
143 }
144 Node & operator[](unsigned int offset){
145 assert(_children);
146 assert(offset >= 0 && offset < _num);
147 return _children[offset];
148 }
149 Node * begin() const {
150 assert_consistent();
151 return _children;
152 }
153 Node * end() const {
154 assert_consistent();
155 return _children + _num;
156 }
157 };
158
159 public:
6911213e » Timo Ewalds
2010-04-07 Refactor storing experience in the tree
160 ExpPair rave;
161 ExpPair exp;
c49f5caa » Timo Ewalds
2010-04-22 Split knowledge out explicitly
162 ExpPair know;
74af2df0 »
2010-05-26 Move children pointer to be managed in a class, hopefully remove the …
163 Move move;
164 Move bestmove; //if outcome is set, then bestmove is the way to get there
8e8be5f0 » Timo Ewalds
2010-04-10 Backup wins in the tree, possibly proving the root
165 int16_t outcome;
74af2df0 »
2010-05-26 Move children pointer to be managed in a class, hopefully remove the …
166 Children children;
8e8be5f0 » Timo Ewalds
2010-04-10 Backup wins in the tree, possibly proving the root
167 //don't forget to update the copy constructor/operator
302209cc » Timo Ewalds
2010-02-22 Commit the beginnings of a UCT MCTS player
168
74af2df0 »
2010-05-26 Move children pointer to be managed in a class, hopefully remove the …
169 Node() : outcome(-1) { }
170 Node(const Move & m, char o = -1) : move(m), outcome(o) { }
8e8be5f0 » Timo Ewalds
2010-04-10 Backup wins in the tree, possibly proving the root
171 Node(const Node & n) { *this = n; }
9d34d4ec » Timo Ewalds
2010-04-09 Clean up keeping the subtree...
172 Node & operator = (const Node & n){
74af2df0 »
2010-05-26 Move children pointer to be managed in a class, hopefully remove the …
173 if(this != & n){ //don't copy to self
9d34d4ec » Timo Ewalds
2010-04-09 Clean up keeping the subtree...
174 //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 …
175 assert(children.empty());
9d34d4ec » Timo Ewalds
2010-04-09 Clean up keeping the subtree...
176
177 rave = n.rave;
178 exp = n.exp;
74af2df0 »
2010-05-26 Move children pointer to be managed in a class, hopefully remove the …
179 know = n.know;
9d34d4ec » Timo Ewalds
2010-04-09 Clean up keeping the subtree...
180 move = n.move;
8e8be5f0 » Timo Ewalds
2010-04-10 Backup wins in the tree, possibly proving the root
181 bestmove = n.bestmove;
74af2df0 »
2010-05-26 Move children pointer to be managed in a class, hopefully remove the …
182 outcome = n.outcome;
9d34d4ec » Timo Ewalds
2010-04-09 Clean up keeping the subtree...
183 }
184 return *this;
185 }
186
187 void swap_tree(Node & n){
74af2df0 »
2010-05-26 Move children pointer to be managed in a class, hopefully remove the …
188 children.swap(n.children);
ced4d1cf » Timo Ewalds
2010-03-28 Keep the tree between moves. For now that means turning off the solve…
189 }
190
191 void print() const {
c033243d » Timo Ewalds
2010-04-09 Fix size(), add Node::to_s()
192 printf("%s\n", to_s().c_str());
193 }
194 string to_s() const {
0d041529 » Timo Ewalds
2010-04-10 Make ExpPair into a class, use accessor functions...
195 return "Node: exp " + to_str(exp.avg(), 2) + "/" + to_str(exp.num()) +
196 ", 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 …
197 ", move " + to_str(move.x) + "," + to_str(move.y) + ", " + to_str(children.num());
ced4d1cf » Timo Ewalds
2010-03-28 Keep the tree between moves. For now that means turning off the solve…
198 }
199
a0fc6cfb » Timo Ewalds
2010-05-04 Fix warnings about signed/unsigned
200 unsigned int size() const {
74af2df0 »
2010-05-26 Move children pointer to be managed in a class, hopefully remove the …
201 unsigned int num = children.num();
202
203 for(Node * i = children.begin(); i != children.end(); i++)
204 num += i->size();
205
206 return num;
b9d644ed » Timo Ewalds
2010-04-08 Add a tree size function
207 }
74af2df0 »
2010-05-26 Move children pointer to be managed in a class, hopefully remove the …
208
9878c2eb » Timo Ewalds
2010-04-21 Disable proof number search proofs properly
209 /*
8b97aa58 » Timo Ewalds
2010-03-07 Include the proof tree in the player tree size
210 int construct(const Solver::PNSNode * n, int pnsscore){
12ee6f88 » Timo Ewalds
2010-03-09 Switch the solver to use Move instead of individual x and y for a few…
211 move = n->move;
141e49fc » Timo Ewalds
2010-03-03 The player should first consult the solver for some tactics. Spend 20…
212
213 if(n->delta == 0){ //a win!
6911213e » Timo Ewalds
2010-04-07 Refactor storing experience in the tree
214 exp = ExpPair(1000, 1000);
141e49fc » Timo Ewalds
2010-03-03 The player should first consult the solver for some tactics. Spend 20…
215 }else if(n->phi == 0){ //a loss or tie
216 //set high but not insurmountable visits just in case it is a tie
6911213e » Timo Ewalds
2010-04-07 Refactor storing experience in the tree
217 exp = ExpPair(0, 100);
0d545c20 » Timo Ewalds
2010-03-09 Fix proof score initialization to be in the right range, and fix the …
218 }else if(pnsscore > 0){
219 if(n->phi >= n->delta)
6911213e » Timo Ewalds
2010-04-07 Refactor storing experience in the tree
220 exp = (ExpPair((1 - n->delta/(2*n->phi)), 1) *= pnsscore);
0d545c20 » Timo Ewalds
2010-03-09 Fix proof score initialization to be in the right range, and fix the …
221 else
6911213e » Timo Ewalds
2010-04-07 Refactor storing experience in the tree
222 exp = (ExpPair((n->phi/(2*n->delta)), 1) *= pnsscore);
141e49fc » Timo Ewalds
2010-03-03 The player should first consult the solver for some tactics. Spend 20…
223 }
224
225 numchildren = n->numchildren;
226 children = NULL;
227
9d34d4ec » Timo Ewalds
2010-04-09 Clean up keeping the subtree...
228 int num = numchildren;
141e49fc » Timo Ewalds
2010-03-03 The player should first consult the solver for some tactics. Spend 20…
229 if(numchildren){
230 children = new Node[numchildren];
231 for(int i = 0; i < numchildren; i++)
8b97aa58 » Timo Ewalds
2010-03-07 Include the proof tree in the player tree size
232 num += children[i].construct(& n->children[i], pnsscore);
141e49fc » Timo Ewalds
2010-03-03 The player should first consult the solver for some tactics. Spend 20…
233 }
8b97aa58 » Timo Ewalds
2010-03-07 Include the proof tree in the player tree size
234 return num;
141e49fc » Timo Ewalds
2010-03-03 The player should first consult the solver for some tactics. Spend 20…
235 }
9878c2eb » Timo Ewalds
2010-04-21 Disable proof number search proofs properly
236 */
302209cc » Timo Ewalds
2010-02-22 Commit the beginnings of a UCT MCTS player
237 ~Node(){
74af2df0 »
2010-05-26 Move children pointer to be managed in a class, hopefully remove the …
238 assert(children.empty());
302209cc » Timo Ewalds
2010-02-22 Commit the beginnings of a UCT MCTS player
239 }
240
74af2df0 »
2010-05-26 Move children pointer to be managed in a class, hopefully remove the …
241 unsigned int alloc(unsigned int num){
242 return children.alloc(num);
302209cc » Timo Ewalds
2010-02-22 Commit the beginnings of a UCT MCTS player
243 }
74af2df0 »
2010-05-26 Move children pointer to be managed in a class, hopefully remove the …
244 unsigned int dealloc(){
245 unsigned int num = 0;
f9e6f77b » Timo Ewalds
2010-04-09 Force the dealloc to be used for deallocation.
246
74af2df0 »
2010-05-26 Move children pointer to be managed in a class, hopefully remove the …
247 for(Node * i = children.begin(); i != children.end(); i++)
248 num += i->dealloc();
249 num += children.dealloc();
f9e6f77b » Timo Ewalds
2010-04-09 Force the dealloc to be used for deallocation.
250
74af2df0 »
2010-05-26 Move children pointer to be managed in a class, hopefully remove the …
251 return num;
302209cc » Timo Ewalds
2010-02-22 Commit the beginnings of a UCT MCTS player
252 }
253
576fa842 » Timo Ewalds
2010-03-07 Fix a few bugs: use factor instead of scale. Stop assigning rave loss…
254 //*
214afe6a » Timo Ewalds
2010-03-05 Update to a more standard way of doing rave scores.
255 //new way, more standard way of changing over from rave scores to real scores
22038b14 » Timo Ewalds
2010-03-27 Major refactoring of UCT/RAVE. Pulled rave updates out of walk_tree. …
256 float value(float ravefactor, float fpurgency){
c49f5caa » Timo Ewalds
2010-04-22 Split knowledge out explicitly
257 ExpPair efexp = exp + know;
258
6beda471 » Timo Ewalds
2010-03-27 Make the minimum rave_factor a constant
259 if(ravefactor <= min_rave)
c49f5caa » Timo Ewalds
2010-04-22 Split knowledge out explicitly
260 return (efexp.num() == 0 ? fpurgency : efexp.avg());
22038b14 » Timo Ewalds
2010-03-27 Major refactoring of UCT/RAVE. Pulled rave updates out of walk_tree. …
261
c49f5caa » Timo Ewalds
2010-04-22 Split knowledge out explicitly
262 if(rave.num() == 0 && efexp.num() == 0)
8d2523bd » Timo Ewalds
2010-03-11 Allow the first play urgency to be configured
263 return fpurgency;
214afe6a » Timo Ewalds
2010-03-05 Update to a more standard way of doing rave scores.
264
c49f5caa » Timo Ewalds
2010-04-22 Split knowledge out explicitly
265 float alpha = ravefactor/(ravefactor + efexp.num());
0d041529 » Timo Ewalds
2010-04-10 Make ExpPair into a class, use accessor functions...
266 // float alpha = sqrt(ravefactor/(ravefactor + 3*exp.num()));
267 // float alpha = (float)rave.num()/((float)exp.num() + (float)rave.num() + 4.0*exp.num()*rave.num()*ravefactor);
214afe6a » Timo Ewalds
2010-03-05 Update to a more standard way of doing rave scores.
268
7cc84b29 » Timo Ewalds
2010-03-06 Avoid a potential divide by 0, set the explore rate based on tests of…
269 float val = 0;
0d041529 » Timo Ewalds
2010-04-10 Make ExpPair into a class, use accessor functions...
270 if(rave.num()) val += alpha*rave.avg();
c49f5caa » Timo Ewalds
2010-04-22 Split knowledge out explicitly
271 if(efexp.num())val += (1-alpha)*efexp.avg();
7cc84b29 » Timo Ewalds
2010-03-06 Avoid a potential divide by 0, set the explore rate based on tests of…
272
273 return val;
214afe6a » Timo Ewalds
2010-03-05 Update to a more standard way of doing rave scores.
274 }
576fa842 » Timo Ewalds
2010-03-07 Fix a few bugs: use factor instead of scale. Stop assigning rave loss…
275 /*/
214afe6a » Timo Ewalds
2010-03-05 Update to a more standard way of doing rave scores.
276 //my understanding of how fuego does it
22038b14 » Timo Ewalds
2010-03-27 Major refactoring of UCT/RAVE. Pulled rave updates out of walk_tree. …
277 float value(float ravefactor, float fpurgency){
214afe6a » Timo Ewalds
2010-03-05 Update to a more standard way of doing rave scores.
278 float val = 0;
279 float weight = 0;
280 if(visits) {
281 val += score;
282 weight += visits;
283 }
576fa842 » Timo Ewalds
2010-03-07 Fix a few bugs: use factor instead of scale. Stop assigning rave loss…
284 if(ravevisits){
cd8a3a94 » Timo Ewalds
2010-03-25 Update the fuego based value function, fix a misunderstanding as well…
285 float bias = 1.0/(1.1 + ravevisits/20000.0);
286 val += rave*bias;
287 weight += ravevisits*bias;
214afe6a » Timo Ewalds
2010-03-05 Update to a more standard way of doing rave scores.
288 }
289 if(weight > 0)
290 return val / weight;
291 else
cd8a3a94 » Timo Ewalds
2010-03-25 Update the fuego based value function, fix a misunderstanding as well…
292 return fpurgency;
293 }
294
295 //based directly on fuego
22038b14 » Timo Ewalds
2010-03-27 Major refactoring of UCT/RAVE. Pulled rave updates out of walk_tree. …
296 float value(float ravefactor, float fpurgency){
cd8a3a94 » Timo Ewalds
2010-03-25 Update the fuego based value function, fix a misunderstanding as well…
297 float val = 0.f;
298 float weightSum = 0.f;
299 bool hasValue = false;
300 if(visits){
301 val += score;
302 weightSum += visits;
303 hasValue = true;
304 }
305 if(ravevisits){
306 float weight = ravevisits / ( 1.1 + ravevisits/20000.);
307 val += weight * rave / ravevisits;
308 weightSum += weight;
309 hasValue = true;
310 }
311 if(hasValue)
312 return val / weightSum;
313 else
314 return fpurgency;
214afe6a » Timo Ewalds
2010-03-05 Update to a more standard way of doing rave scores.
315 }
cd8a3a94 » Timo Ewalds
2010-03-25 Update the fuego based value function, fix a misunderstanding as well…
316
214afe6a » Timo Ewalds
2010-03-05 Update to a more standard way of doing rave scores.
317 //*/
302209cc » Timo Ewalds
2010-02-22 Commit the beginnings of a UCT MCTS player
318 };
319
7149ea6e » Timo Ewalds
2010-03-05 Add an option to make the rave scores scale from 2 down to 0
320 struct RaveMoveList {
11996069 » Timo Ewalds
2010-04-18 Some cleanups to rave...
321 struct RaveMove : public Move {
609a9713 » Timo Ewalds
2010-03-09 Fix rave values so it updates wins to the winner and losses to the lo…
322 char player;
323 float score;
324
11996069 » Timo Ewalds
2010-04-18 Some cleanups to rave...
325 RaveMove(const Move & m, char p = 0, float s = 1) : Move(m), player(p), score(s) { }
609a9713 » Timo Ewalds
2010-03-09 Fix rave values so it updates wins to the winner and losses to the lo…
326 };
71d4142e » Timo Ewalds
2010-04-18 Rewrite update_rave to use iterators, which makes it a bit faster, an…
327 typedef vector<RaveMove>::const_iterator iterator;
609a9713 » Timo Ewalds
2010-03-09 Fix rave values so it updates wins to the winner and losses to the lo…
328
329 vector<RaveMove> list;
7149ea6e » Timo Ewalds
2010-03-05 Add an option to make the rave scores scale from 2 down to 0
330
331 RaveMoveList(int s = 0){
332 list.reserve(s);
333 }
334
11996069 » Timo Ewalds
2010-04-18 Some cleanups to rave...
335 void add(const Move & move, char player){
336 list.push_back(RaveMove(move, player, 1));
7149ea6e » Timo Ewalds
2010-03-05 Add an option to make the rave scores scale from 2 down to 0
337 }
338 void clear(){
339 list.clear();
340 }
22038b14 » Timo Ewalds
2010-03-27 Major refactoring of UCT/RAVE. Pulled rave updates out of walk_tree. …
341 unsigned int size() const {
7149ea6e » Timo Ewalds
2010-03-05 Add an option to make the rave scores scale from 2 down to 0
342 return list.size();
343 }
609a9713 » Timo Ewalds
2010-03-09 Fix rave values so it updates wins to the winner and losses to the lo…
344 const RaveMove & operator[](int i) const {
7149ea6e » Timo Ewalds
2010-03-05 Add an option to make the rave scores scale from 2 down to 0
345 return list[i];
346 }
71d4142e » Timo Ewalds
2010-04-18 Rewrite update_rave to use iterators, which makes it a bit faster, an…
347 iterator begin() const {
348 return list.begin();
349 }
350 iterator end() const {
351 return list.end();
352 }
353
7149ea6e » Timo Ewalds
2010-03-05 Add an option to make the rave scores scale from 2 down to 0
354 //remove the moves that were played by the loser
355 //sort in y,x order
11996069 » Timo Ewalds
2010-04-18 Some cleanups to rave...
356 void clean(bool scale){
7149ea6e » Timo Ewalds
2010-03-05 Add an option to make the rave scores scale from 2 down to 0
357 if(scale){
11996069 » Timo Ewalds
2010-04-18 Some cleanups to rave...
358 float base = 2; //2 instead of 1 so the average of wins stays at 1
359 float factor = 2*base/(list.size()+1); //+1 to keep it from going negative, 4 = base*2 since half the values are skipped
7149ea6e » Timo Ewalds
2010-03-05 Add an option to make the rave scores scale from 2 down to 0
360
11996069 » Timo Ewalds
2010-04-18 Some cleanups to rave...
361 for(unsigned int i = 0; i < list.size(); i++)
362 list[i].score = base - i/2*factor;
609a9713 » Timo Ewalds
2010-03-09 Fix rave values so it updates wins to the winner and losses to the lo…
363 }
7149ea6e » Timo Ewalds
2010-03-05 Add an option to make the rave scores scale from 2 down to 0
364
576fa842 » Timo Ewalds
2010-03-07 Fix a few bugs: use factor instead of scale. Stop assigning rave loss…
365 sort(list.begin(), list.end()); //sort in y,x order
7149ea6e » Timo Ewalds
2010-03-05 Add an option to make the rave scores scale from 2 down to 0
366 }
367 };
368
cb365ad3 » Timo Ewalds
2010-02-28 Allow the explore and ravefactor values to be set over gtp
369 public:
6beda471 » Timo Ewalds
2010-03-27 Make the minimum rave_factor a constant
370
371 static const float min_rave = 0.1;
372
b930eada » Timo Ewalds
2010-04-24 Set the parameters based on all the recent testing, changing by board…
373 bool defaults; //use the default settings on board reset
0ec1b327 » Timo Ewalds
2010-04-17 Prepare for new knowledge initialization code
374 float prooftime; //fraction of time spent in proof number search, looking for a provable win and losses to avoid
375 //tree traversal
18c886f4 » Timo Ewalds
2010-02-26 add a simpler move struct, add a basic, though likely incomplete, RAV…
376 float explore; //greater than one favours exploration, smaller than one favours exploitation
22038b14 » Timo Ewalds
2010-03-27 Major refactoring of UCT/RAVE. Pulled rave updates out of walk_tree. …
377 float ravefactor; //big numbers favour rave scores, small ignore it
7149ea6e » Timo Ewalds
2010-03-05 Add an option to make the rave scores scale from 2 down to 0
378 bool ravescale; //scale rave numbers from 2 down to 0 in decreasing order of move recency instead of always 1
2fd58ebd » Timo Ewalds
2010-03-09 Add the good opponent moves are good moves for me heuristic
379 bool opmoves; //take the opponents rave updates too, a good move for my opponent is a good move for me.
8d2523bd » Timo Ewalds
2010-03-11 Allow the first play urgency to be configured
380 int skiprave; //how often to skip rave, skip once in this many checks
4b36b92c » Timo Ewalds
2010-05-04 Add an option to only use short rollouts, for higher quality rave upd…
381 bool shortrave; //only update rave values on short rollouts
dca42bd0 » Timo Ewalds
2010-03-29 Make keeping tree optional
382 bool keeptree; //reuse the tree from the previous move
4a5b4c7f » Timo Ewalds
2010-04-17 Add an option to keep the solved tree for use next turn
383 bool minimaxtree;//keep the solved part of the tree
4d2b548a »
2010-05-26 Allow solving to deeper levels at node expansion
384 int minimax; //solve the minimax tree within the uct tree
8d2523bd » Timo Ewalds
2010-03-11 Allow the first play urgency to be configured
385 float fpurgency; //what value to return for a move that hasn't been played yet
309f0ce3 »
2010-05-26 Allow the number of visits per expansion to be increased for low memo…
386 int visitexpand;//number of visits before expanding a node
0ec1b327 » Timo Ewalds
2010-04-17 Prepare for new knowledge initialization code
387 //knowledge
8d2523bd » Timo Ewalds
2010-03-11 Allow the first play urgency to be configured
388 int proofscore; //how many virtual rollouts to assign based on the proof number search values
96ca3732 » Timo Ewalds
2010-04-17 Add move locality
389 bool localreply; //boost for a local reply, ie a move near the previous move
390 bool locality; //boost for playing near previous stones
eaf17770 » Timo Ewalds
2010-04-17 Add a connectivity heuristic
391 bool connect; //boost for having connections to edges and corners
22caa03b » Timo Ewalds
2010-04-17 Add the virtual connection pattern as node initialization
392 bool bridge; //boost replying to a probe at a bridge
0ec1b327 » Timo Ewalds
2010-04-17 Prepare for new knowledge initialization code
393 //rollout
ff9a09be » Timo Ewalds
2010-03-05 Parameterize a few features
394 bool rolloutpattern; //play the response to a virtual connection threat in rollouts
ba795a28 » Timo Ewalds
2010-04-17 Add code to look for instant wins in rollouts, likely a bad idea
395 bool instantwin; //look for instant wins in rollouts
8a654dd8 » Timo Ewalds
2010-02-28 Allow the player to be reused multiple times
396
0ec1b327 » Timo Ewalds
2010-04-17 Prepare for new knowledge initialization code
397
4d2b548a »
2010-05-26 Allow solving to deeper levels at node expansion
398 Solver solver;
ced4d1cf » Timo Ewalds
2010-03-28 Keep the tree between moves. For now that means turning off the solve…
399 Node root;
400 Board rootboard;
401
302209cc » Timo Ewalds
2010-02-22 Commit the beginnings of a UCT MCTS player
402 int runs;
0aa0c763 » Timo Ewalds
2010-02-28 Factor the stats out into a separate file, display some better stats
403 DepthStats treelen, gamelen;
8a654dd8 » Timo Ewalds
2010-02-28 Allow the player to be reused multiple times
404 uint64_t nodes, maxnodes;
302209cc » Timo Ewalds
2010-02-22 Commit the beginnings of a UCT MCTS player
405 bool timeout;
406
bdc8b7da » Timo Ewalds
2010-02-25 Add some version of time control...
407 double time_used;
408
302209cc » Timo Ewalds
2010-02-22 Commit the beginnings of a UCT MCTS player
409 Player() {
ced4d1cf » Timo Ewalds
2010-03-28 Keep the tree between moves. For now that means turning off the solve…
410 nodes = 0;
8a654dd8 » Timo Ewalds
2010-02-28 Allow the player to be reused multiple times
411 time_used = 0;
141e49fc » Timo Ewalds
2010-03-03 The player should first consult the solver for some tactics. Spend 20…
412
b930eada » Timo Ewalds
2010-04-24 Set the parameters based on all the recent testing, changing by board…
413 set_default_params();
414 }
415 void set_default_params(){
416 int s = rootboard.get_size();
417 defaults = true;
418 explore = (s == 4 ? 0.85 : 0);
419 ravefactor = (s == 4 ? 0 : 500);
5e20d954 » Timo Ewalds
2010-04-17 formatting, and disable locality by default
420 ravescale = false;
421 opmoves = false;
422 skiprave = 0;
4b36b92c » Timo Ewalds
2010-05-04 Add an option to only use short rollouts, for higher quality rave upd…
423 shortrave = false;
5e20d954 » Timo Ewalds
2010-04-17 formatting, and disable locality by default
424 keeptree = true;
4a5b4c7f » Timo Ewalds
2010-04-17 Add an option to keep the solved tree for use next turn
425 minimaxtree = false;
d226d919 »
2010-05-31 Enable forced move checking by default
426 minimax = 2;
5e20d954 » Timo Ewalds
2010-04-17 formatting, and disable locality by default
427 fpurgency = 1;
309f0ce3 »
2010-05-26 Allow the number of visits per expansion to be increased for low memo…
428 visitexpand = 1;
5e20d954 » Timo Ewalds
2010-04-17 formatting, and disable locality by default
429 prooftime = 0;
430 proofscore = 0;
5d684562 » Timo Ewalds
2010-04-18 Disable all the features that aren't proven to be good, to form a bas…
431 localreply = false;
5e20d954 » Timo Ewalds
2010-04-17 formatting, and disable locality by default
432 locality = false;
b930eada » Timo Ewalds
2010-04-24 Set the parameters based on all the recent testing, changing by board…
433 connect = (s == 4);
5d684562 » Timo Ewalds
2010-04-18 Disable all the features that aren't proven to be good, to form a bas…
434 bridge = false;
b930eada » Timo Ewalds
2010-04-24 Set the parameters based on all the recent testing, changing by board…
435 rolloutpattern = true;
5e20d954 » Timo Ewalds
2010-04-17 formatting, and disable locality by default
436 instantwin = false;
302209cc » Timo Ewalds
2010-02-22 Commit the beginnings of a UCT MCTS player
437 }
f9e6f77b » Timo Ewalds
2010-04-09 Force the dealloc to be used for deallocation.
438 ~Player(){ root.dealloc(); }
302209cc » Timo Ewalds
2010-02-22 Commit the beginnings of a UCT MCTS player
439 void timedout(){ timeout = true; }
440
ced4d1cf » Timo Ewalds
2010-03-28 Keep the tree between moves. For now that means turning off the solve…
441 void set_board(const Board & board){
442 rootboard = board;
ed6410cf » Timo Ewalds
2010-03-28 Deallocate the root properly, fixes a reverse memory leak
443 nodes -= root.dealloc();
ced4d1cf » Timo Ewalds
2010-03-28 Keep the tree between moves. For now that means turning off the solve…
444 root = Node();
b930eada » Timo Ewalds
2010-04-24 Set the parameters based on all the recent testing, changing by board…
445
446 if(defaults)
447 set_default_params();
ced4d1cf » Timo Ewalds
2010-03-28 Keep the tree between moves. For now that means turning off the solve…
448 }
449 void move(const Move & m){
ce05c67c » Timo Ewalds
2010-04-17 Actually update the locality scores...
450 rootboard.move(m, true);
9d34d4ec » Timo Ewalds
2010-04-09 Clean up keeping the subtree...
451
61a6b449 » Timo Ewalds
2010-04-10 Output the amount of the tree that is saved by keeping the tree
452 uint64_t nodesbefore = nodes;
453
dca42bd0 » Timo Ewalds
2010-03-29 Make keeping tree optional
454 if(keeptree){
9d34d4ec » Timo Ewalds
2010-04-09 Clean up keeping the subtree...
455 Node child;
456
74af2df0 »
2010-05-26 Move children pointer to be managed in a class, hopefully remove the …
457 for(Node * i = root.children.begin(); i != root.children.end(); i++){
458 if(i->move == m){
459 child = *i; //copy the child experience to temp
460 child.swap_tree(*i); //move the child tree to temp
9d34d4ec » Timo Ewalds
2010-04-09 Clean up keeping the subtree...
461 break;
462 }
463 }
464
dca42bd0 » Timo Ewalds
2010-03-29 Make keeping tree optional
465 nodes -= root.dealloc();
9d34d4ec » Timo Ewalds
2010-04-09 Clean up keeping the subtree...
466 root = child;
467 root.swap_tree(child);
61a6b449 » Timo Ewalds
2010-04-10 Output the amount of the tree that is saved by keeping the tree
468
469 if(nodesbefore > 0)
470 fprintf(stderr, "Nodes before: %llu, after: %llu, saved %.1f%% of the tree\n", nodesbefore, nodes, 100.0*nodes/nodesbefore);
dca42bd0 » Timo Ewalds
2010-03-29 Make keeping tree optional
471 }else{
472 nodes -= root.dealloc();
473 root = Node();
6a970024 » Timo Ewalds
2010-04-17 Don't forget to set the previous move...
474 root.move = m;
dca42bd0 » Timo Ewalds
2010-03-29 Make keeping tree optional
475 }
61a6b449 » Timo Ewalds
2010-04-10 Output the amount of the tree that is saved by keeping the tree
476 assert(nodes == root.size());
ced4d1cf » Timo Ewalds
2010-03-28 Keep the tree between moves. For now that means turning off the solve…
477 }
478
48c2aba5 »
2010-05-26 Fix memory limit for above 2gb
479 Move mcts(double time, int maxruns, uint64_t memlimit);
d41e75f8 »
2010-05-28 Add a player based solver. It works, though it is questionable whethe…
480 int solve(double time, uint64_t memlimit);
ced4d1cf » Timo Ewalds
2010-03-28 Keep the tree between moves. For now that means turning off the solve…
481 vector<Move> get_pv();
302209cc » Timo Ewalds
2010-02-22 Commit the beginnings of a UCT MCTS player
482
483 protected:
53f89b93 » Timo Ewalds
2010-05-04 Choose moves in a better order
484 Node * return_move(const Node * node, int toplay) const;
485 Node * return_move_outcome(const Node * node, int outcome) const;
7149ea6e » Timo Ewalds
2010-03-05 Add an option to make the rave scores scale from 2 down to 0
486 int walk_tree(Board & board, Node * node, RaveMoveList & movelist, int depth);
ca1f3533 » Timo Ewalds
2010-04-21 Move node knowledge into its own function
487 void add_knowledge(Board & board, Node * node, Node * child);
8e8be5f0 » Timo Ewalds
2010-04-10 Backup wins in the tree, possibly proving the root
488 Node * choose_move(const Node * node, int toplay) const;
22038b14 » Timo Ewalds
2010-03-27 Major refactoring of UCT/RAVE. Pulled rave updates out of walk_tree. …
489 void update_rave(const Node * node, const RaveMoveList & movelist, int won, int toplay);
bd176465 » Timo Ewalds
2010-04-21 Switch the way the bridge pattern is checked. This is potentially fas…
490 bool test_bridge_probe(const Board & board, const Move & move, const Move & test);
7149ea6e » Timo Ewalds
2010-03-05 Add an option to make the rave scores scale from 2 down to 0
491 int rand_game(Board & board, RaveMoveList & movelist, Move move, int depth);
ec26f286 » Timo Ewalds
2010-03-01 Switch the default explore/rave params to be consistent with the valu…
492 bool check_pattern(const Board & board, Move & move);
d41e75f8 »
2010-05-28 Add a player based solver. It works, though it is questionable whethe…
493
494 void solve_recurse(Board & board, Node * node, double rate, double solvetime, uint64_t memlimit, int depth);
302209cc » Timo Ewalds
2010-02-22 Commit the beginnings of a UCT MCTS player
495 };
496
497 #endif
498
Something went wrong with that request. Please try again.