00001
00008 #pragma once
00009
00010 #include "utils.h"
00011 #include <list>
00012
00013 using std::list;
00014
00015 #define CFG_SEP '='
00016 #define CFG_COMMENT "#"
00017 #define DEFAULT_CFG "default.cfg"
00018 #define SINGLE_VALUE -1
00019
00020 class Cfg;
00021
00022 enum itemType_e { IT_STR, IT_BOOL, IT_INT, IT_FLOAT, IT_INT_AR, IT_FLOAT_AR };
00023
00024 bool fillItemFromString(void* item, itemType_e type, string s, int index=SINGLE_VALUE);
00025 string getItemAsString(void* item, itemType_e type, int index=SINGLE_VALUE);
00026
00030 class CfgItem
00031 {
00032 public:
00033 CfgItem(const char* name, itemType_e type, void* item, const char * defaultValue_);
00034 private:
00035 string name_;
00036 itemType_e type_;
00037 void * item_;
00038 bool set_;
00039 string defaultValue_;
00040
00041 friend class Cfg;
00042 };
00043
00044 typedef list<CfgItem > CfgItemList;
00045 typedef CfgItemList::iterator CfgItemListIter;
00046
00047 class Values;
00048 class EvaluationValues;
00049 class StepKnowledgeValues;
00050
00056 class Cfg
00057 {
00058 public:
00062 Cfg();
00063
00067 void loadFromFile(string fn);
00068
00072 void loadFromSection(string content);
00073
00077 bool checkConfiguration();
00078
00079 inline bool localPlayout() { return localPlayout_; }
00080 inline bool useBestEval() { return useBestEval_; }
00081 inline bool extensionsInEval() { return extensionsInEval_; }
00082 inline bool uct_tt() { return uct_tt_; }
00083 inline int vv() { return vv_; }
00084 inline bool ucbTuned() { return ucbTuned_; }
00085 inline bool dynamicExploration() { return dynamicExploration_; }
00086 inline bool childrenCache() { return childrenCache_; }
00087 inline bool knowledgeInTree() { return knowledgeInTree_;}
00088 inline bool uctRelativeUpdate() { return uctRelativeUpdate_;}
00089 inline bool historyHeuristic() { return historyHeuristic_;}
00090 inline float exploreRate() { return exploreRate_; }
00091 inline int playoutLen() { return playoutLen_; }
00092 inline int matureLevel() { return matureLevel_; }
00093 inline float tcMoveDefault() { return tcMoveDefault_; }
00094 inline bool exactPlayoutValue() { return exactPlayoutValue_; }
00095 inline bool knowledgeInPlayout() { return knowledgeInPlayout_;}
00096 inline float moveAdvisor() { return moveAdvisor_; }
00097 inline float activeTrapping() { return activeTrapping_; }
00098 inline bool playoutByMoves() { return playoutByMoves_; }
00099 inline uint knowledgeTournamentSize() { return knowledgeTournamentSize_; }
00100 inline int searchThreadsNum() { return searchThreadsNum_; }
00101 inline string evalCfg() { return evalCfg_; }
00102
00103 inline EvaluationValues* evaluationValues() {return evaluationValues_;}
00104 inline StepKnowledgeValues* stepKnowledgeValues() {return stepKnowledgeValues_;}
00105
00106 private:
00107 CfgItemList items_;
00108
00110 bool localPlayout_;
00112 bool useBestEval_;
00114 bool extensionsInEval_;
00116 bool uct_tt_;
00118 int vv_;
00120 bool ucbTuned_;
00122 bool dynamicExploration_;
00124 bool childrenCache_;
00126 bool knowledgeInTree_;
00128 bool playoutByMoves_;
00130 bool uctRelativeUpdate_;
00132 bool historyHeuristic_;
00134 float exploreRate_;
00136 int playoutLen_;
00138 int matureLevel_;
00140 float tcMoveDefault_;
00142 bool exactPlayoutValue_;
00144 bool knowledgeInPlayout_;
00146 float moveAdvisor_;
00148 float activeTrapping_;
00150 uint knowledgeTournamentSize_;
00152 int searchThreadsNum_;
00154 string evalCfg_;
00155
00156 EvaluationValues * evaluationValues_;
00157 StepKnowledgeValues * stepKnowledgeValues_;
00158 };
00159
00160 enum optionType_e { OT_STRING, OT_BOOL_POS, OT_BOOL_NEG, OT_INT };
00161
00162 class Options;
00163
00164 class OptionFather
00165 {
00166 protected:
00167 string shortName_;
00168 string longName_;
00169 string description_;
00170 optionType_e type_;
00171 bool parsed_;
00172
00173 friend class Options;
00174
00175 public:
00176 OptionFather(){};
00177 virtual ~OptionFather(){};
00178 OptionFather(string shortName, string longName, string description, optionType_e type):
00179 shortName_(shortName), longName_(longName), description_(description), type_(type) { parsed_ = false;};
00180 virtual void setValue(bool){};
00181 virtual void setValue(string){};
00182 virtual void setValue(int){};
00183 virtual void setValueParsed(bool){};
00184 virtual void setValueParsed(string){};
00185 virtual void setValueParsed(int){};
00186 bool parsed() { return parsed_;}
00187 virtual string toString(){ return "";};
00188 virtual string help(){ return "";};
00189 };
00190
00191 template <typename T> class Option: public OptionFather
00192 {
00193 T value_;
00194
00195 public:
00196 Option(){;};
00197 Option(string shortName, string longName, string description, optionType_e type, T defaultValue):
00198 OptionFather(shortName, longName, description, type), value_(defaultValue) {;};
00199 ~Option(){;};
00200
00201 T getValue() { return value_;}
00202 void setValueParsed(T value) { if ( ! parsed_) { value_ = value; parsed_ = true;};}
00203 void setValue(T value) { value_ = value;}
00204
00205 string toString() {
00206 stringstream ss;
00207 ss << "[" << shortName_ << ", " << longName_ << ", " << description_ << ", " << value_ << "]" << endl;
00208 return ss.str();
00209 }
00210
00211 string help() {
00212 stringstream ss;
00213 ss << "-" << shortName_ << ", --" << longName_ << ", " << description_ << endl;
00214 return ss.str();
00215 }
00216
00217
00218 };
00219
00220 typedef Option<int> OptionInt;
00221 typedef Option<bool> OptionBool;
00222 typedef Option<string> OptionString;
00223
00224 typedef list<OptionFather*> OptionList;
00225
00229 class Options
00230 {
00231 private:
00232 OptionList options_;
00233 OptionList values_;
00234
00236 OptionString fnAeiInit_;
00238 OptionString fnPosition_;
00240 OptionString fnRecord_;
00242 OptionString fnGameState_;
00244 OptionString fnCfg_;
00246 OptionBool benchmarkMode_;
00248 OptionBool getMoveMode_;
00250 OptionBool localMode_;
00252 OptionBool help_;
00253
00254 public:
00255 Options();
00256
00257 bool parse(const int, const char **);
00258 bool parseToken(string, string);
00259 bool parseValue(string);
00260
00261 bool benchmarkMode() { return benchmarkMode_.getValue(); }
00262 bool localMode() { return localMode_.getValue(); }
00263 bool getMoveMode() { return getMoveMode_.getValue(); }
00264 bool help() { return help_.getValue(); }
00265 string fnAeiInit() { return fnAeiInit_.getValue(); }
00266 string fnPosition() { return fnPosition_.getValue(); }
00267 string fnRecord() { return fnRecord_.getValue(); }
00268 string fnGameState() { return fnGameState_.getValue(); }
00269 string fnCfg() { return fnCfg_.getValue(); }
00270
00271 void printAll();
00272 string helpToString();
00273
00274 };
00275
00276 extern Cfg cfg;
00277 extern Options options;