-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.h
277 lines (235 loc) · 7.84 KB
/
config.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/**
* @file config.h
*
* Configuration
* @full Handles command line configuration and configuration files parsing.
*/
#pragma once
#include "utils.h"
#include <list>
using std::list;
#define CFG_SEP '='
#define CFG_COMMENT "#"
#define DEFAULT_CFG "default.cfg"
#define SINGLE_VALUE -1
class Cfg;
enum itemType_e { IT_STR, IT_BOOL, IT_INT, IT_FLOAT, IT_INT_AR, IT_FLOAT_AR };
bool fillItemFromString(void* item, itemType_e type, string s, int index=SINGLE_VALUE);
string getItemAsString(void* item, itemType_e type, int index=SINGLE_VALUE);
/**
* Configuration item.
*/
class CfgItem
{
public:
CfgItem(const char* name, itemType_e type, void* item, const char * defaultValue_);
private:
string name_;
itemType_e type_;
void * item_;
bool set_;
string defaultValue_;
friend class Cfg;
};
typedef list<CfgItem > CfgItemList;
typedef CfgItemList::iterator CfgItemListIter;
class Values;
class EvaluationValues;
class StepKnowledgeValues;
/**
* Program configuration.
*
* Mostly influences the search/board/time management.
*/
class Cfg
{
public:
/**
* Binds items to variables.
*/
Cfg();
/**
* Parses the sections and sends them to appropriate loaders.
*/
void loadFromFile(string fn);
/**
* Section loader for cfg class.
*/
void loadFromSection(string content);
/**
* Checks whether every item has been set.
*/
bool checkConfiguration();
inline bool localPlayout() { return localPlayout_; }
inline bool useBestEval() { return useBestEval_; }
inline bool extensionsInEval() { return extensionsInEval_; }
inline bool uct_tt() { return uct_tt_; }
inline int vv() { return vv_; }
inline bool ucbTuned() { return ucbTuned_; }
inline bool dynamicExploration() { return dynamicExploration_; }
inline bool childrenCache() { return childrenCache_; }
inline bool knowledgeInTree() { return knowledgeInTree_;}
inline bool uctRelativeUpdate() { return uctRelativeUpdate_;}
inline bool historyHeuristic() { return historyHeuristic_;}
inline float exploreRate() { return exploreRate_; }
inline int playoutLen() { return playoutLen_; }
inline int matureLevel() { return matureLevel_; }
inline float tcMoveDefault() { return tcMoveDefault_; }
inline bool exactPlayoutValue() { return exactPlayoutValue_; }
inline bool knowledgeInPlayout() { return knowledgeInPlayout_;}
inline float moveAdvisor() { return moveAdvisor_; }
inline float activeTrapping() { return activeTrapping_; }
inline bool playoutByMoves() { return playoutByMoves_; }
inline uint knowledgeTournamentSize() { return knowledgeTournamentSize_; }
inline int searchThreadsNum() { return searchThreadsNum_; }
inline string evalCfg() { return evalCfg_; }
inline EvaluationValues* evaluationValues() {return evaluationValues_;}
inline StepKnowledgeValues* stepKnowledgeValues() {return stepKnowledgeValues_;}
private:
CfgItemList items_;
/**Locality in playout switch.*/
bool localPlayout_;
/**Is top evaluation function used*/
bool useBestEval_;
/** Search extensions in evaluation.*/
bool extensionsInEval_;
/** Uct transpotion tables. */
bool uct_tt_;
/**Virtual visits value*/
int vv_;
/**Use ucb tuned formula.*/
bool ucbTuned_;
/**Dynamic exploration rate..*/
bool dynamicExploration_;
/**Children caching for perfomance boost.*/
bool childrenCache_;
/**Use knowledge in uct tree.*/
bool knowledgeInTree_;
/**In playout go by moves or steps.*/
bool playoutByMoves_;
/**Relative update in playout.*/
bool uctRelativeUpdate_;
/**Use tw steps as history heuristic.*/
bool historyHeuristic_;
/**Uct explore rate.*/
float exploreRate_;
/**Lenght of playout before evaluation.*/
int playoutLen_;
/**Number of traverses through node before expansion.*/
int matureLevel_;
/**Default time per move.*/
float tcMoveDefault_;
/**Use exact evaluation value [-1, 1] or approximation {1, -1}.*/
bool exactPlayoutValue_;
/**Use knowledge in playout.*/
bool knowledgeInPlayout_;
/**Use move advisour in uct/playouts.*/
float moveAdvisor_;
/**Actively look for trappings in playouts.*/
float activeTrapping_;
/**How many steps go to step tournament in playout (must be > 0).*/
uint knowledgeTournamentSize_;
/**Number of threads for search.*/
int searchThreadsNum_;
/**Filename to take the evaluation configuration from.*/
string evalCfg_;
EvaluationValues * evaluationValues_;
StepKnowledgeValues * stepKnowledgeValues_;
};
enum optionType_e { OT_STRING, OT_BOOL_POS, OT_BOOL_NEG, OT_INT };
class Options;
class OptionFather
{
protected:
string shortName_;
string longName_;
string description_;
optionType_e type_;
bool parsed_;
friend class Options;
public:
OptionFather(){};
virtual ~OptionFather(){};
OptionFather(string shortName, string longName, string description, optionType_e type):
shortName_(shortName), longName_(longName), description_(description), type_(type) { parsed_ = false;};
virtual void setValue(bool){};
virtual void setValue(string){};
virtual void setValue(int){};
virtual void setValueParsed(bool){};
virtual void setValueParsed(string){};
virtual void setValueParsed(int){};
bool parsed() { return parsed_;}
virtual string toString(){ return "";};
virtual string help(){ return "";};
};
template <typename T> class Option: public OptionFather
{
T value_;
public:
Option(){;};
Option(string shortName, string longName, string description, optionType_e type, T defaultValue):
OptionFather(shortName, longName, description, type), value_(defaultValue) {;};
~Option(){;};
T getValue() { return value_;}
void setValueParsed(T value) { if ( ! parsed_) { value_ = value; parsed_ = true;};}
void setValue(T value) { value_ = value;}
string toString() {
stringstream ss;
ss << "[" << shortName_ << ", " << longName_ << ", " << description_ << ", " << value_ << "]" << endl;
return ss.str();
}
string help() {
stringstream ss;
ss << "-" << shortName_ << ", --" << longName_ << ", " << description_ << endl;
return ss.str();
}
};
typedef Option<int> OptionInt;
typedef Option<bool> OptionBool;
typedef Option<string> OptionString;
typedef list<OptionFather*> OptionList;
/**
* Management of command line configuration.
*/
class Options
{
private:
OptionList options_;
OptionList values_;
/**AEI init file - for debugging.*/
OptionString fnAeiInit_;
/**Position input file - for getMoveMode_.*/
OptionString fnPosition_;
/**Record input file.*/
OptionString fnRecord_;
/**Game state input file.*/
OptionString fnGameState_;
/**Configuration file.*/
OptionString fnCfg_;
/**Perform various benchmarks.*/
OptionBool benchmarkMode_;
/**Switch to getMove mode - used by match script for instance.*/
OptionBool getMoveMode_;
/**Use extended AEI set.*/
OptionBool localMode_;
/**Print help.*/
OptionBool help_;
public:
Options();
bool parse(const int, const char **);
bool parseToken(string, string);
bool parseValue(string);
bool benchmarkMode() { return benchmarkMode_.getValue(); }
bool localMode() { return localMode_.getValue(); }
bool getMoveMode() { return getMoveMode_.getValue(); }
bool help() { return help_.getValue(); }
string fnAeiInit() { return fnAeiInit_.getValue(); }
string fnPosition() { return fnPosition_.getValue(); }
string fnRecord() { return fnRecord_.getValue(); }
string fnGameState() { return fnGameState_.getValue(); }
string fnCfg() { return fnCfg_.getValue(); }
void printAll();
string helpToString();
};
extern Cfg cfg;
extern Options options;