-using std::cout;
-using std::endl;
-
-////
-//// Local definitions
-////
-
-namespace {
-
- enum OptionType { SPIN, COMBO, CHECK, STRING, BUTTON };
-
- typedef std::vector<string> StrVector;
-
- struct Option {
-
- string name, defaultValue, currentValue;
- OptionType type;
- size_t idx;
- int minValue, maxValue;
- StrVector comboValues;
-
- Option();
- Option(const char* defaultValue, OptionType = STRING);
- Option(bool defaultValue, OptionType = CHECK);
- Option(int defaultValue, int minValue, int maxValue);
-
- bool operator<(const Option& o) const { return idx < o.idx; }
- };
-
- typedef std::vector<Option> OptionsVector;
- typedef std::map<string, Option> Options;
-
- Options options;
-
- // stringify() converts a value of type T to a std::string
- template<typename T>
- string stringify(const T& v) {
-
- std::ostringstream ss;
- ss << v;
- return ss.str();
- }
-
- Option::Option() {} // To allow insertion in a std::map
-
- Option::Option(const char* def, OptionType t)
- : defaultValue(def), currentValue(def), type(t), idx(options.size()), minValue(0), maxValue(0) {}
-
- Option::Option(bool def, OptionType t)
- : defaultValue(stringify(def)), currentValue(stringify(def)), type(t), idx(options.size()), minValue(0), maxValue(0) {}
-
- Option::Option(int def, int minv, int maxv)
- : defaultValue(stringify(def)), currentValue(stringify(def)), type(SPIN), idx(options.size()), minValue(minv), maxValue(maxv) {}
-
- // load_defaults() populates the options map with the hard
- // coded names and default values.
-
- void load_defaults(Options& o) {
-
- o["Use Search Log"] = Option(false);
- o["Search Log Filename"] = Option("SearchLog.txt");
- o["Book File"] = Option("book.bin");
- o["Best Book Move"] = Option(false);
- o["Mobility (Middle Game)"] = Option(100, 0, 200);
- o["Mobility (Endgame)"] = Option(100, 0, 200);
- o["Pawn Structure (Middle Game)"] = Option(100, 0, 200);
- o["Pawn Structure (Endgame)"] = Option(100, 0, 200);
- o["Passed Pawns (Middle Game)"] = Option(100, 0, 200);
- o["Passed Pawns (Endgame)"] = Option(100, 0, 200);
- o["Space"] = Option(100, 0, 200);
- o["Aggressiveness"] = Option(100, 0, 200);
- o["Cowardice"] = Option(100, 0, 200);
- o["Check Extension (PV nodes)"] = Option(2, 0, 2);
- o["Check Extension (non-PV nodes)"] = Option(1, 0, 2);
- o["Single Evasion Extension (PV nodes)"] = Option(2, 0, 2);
- o["Single Evasion Extension (non-PV nodes)"] = Option(2, 0, 2);
- o["Mate Threat Extension (PV nodes)"] = Option(2, 0, 2);
- o["Mate Threat Extension (non-PV nodes)"] = Option(2, 0, 2);
- o["Pawn Push to 7th Extension (PV nodes)"] = Option(1, 0, 2);
- o["Pawn Push to 7th Extension (non-PV nodes)"] = Option(1, 0, 2);
- o["Passed Pawn Extension (PV nodes)"] = Option(1, 0, 2);
- o["Passed Pawn Extension (non-PV nodes)"] = Option(0, 0, 2);
- o["Pawn Endgame Extension (PV nodes)"] = Option(2, 0, 2);
- o["Pawn Endgame Extension (non-PV nodes)"] = Option(2, 0, 2);
- o["Minimum Split Depth"] = Option(4, 4, 7);
- o["Maximum Number of Threads per Split Point"] = Option(5, 4, 8);
- o["Threads"] = Option(1, 1, MAX_THREADS);
- o["Hash"] = Option(32, 4, 8192);
- o["Clear Hash"] = Option(false, BUTTON);
- o["New Game"] = Option(false, BUTTON);
- o["Ponder"] = Option(true);
- o["OwnBook"] = Option(true);
- o["MultiPV"] = Option(1, 1, 500);
- o["Emergency Move Horizon"] = Option(40, 0, 50);
- o["Emergency Base Time"] = Option(200, 0, 60000);
- o["Emergency Move Time"] = Option(70, 0, 5000);
- o["Minimum Thinking Time"] = Option(20, 0, 5000);
- o["UCI_Chess960"] = Option(false); // Just a dummy but needed by GUIs
- o["UCI_AnalyseMode"] = Option(false);
-
- // Any option should know its name so to be easily printed
- for (Options::iterator it = o.begin(); it != o.end(); ++it)
- it->second.name = it->first;
- }
-
- // get_option_value() implements the various get_option_value_<type>
- // functions defined later.
-
- template<typename T>
- T get_option_value(const string& optionName) {
-
- T ret = T();
- if (options.find(optionName) == options.end())
- return ret;
-
- std::istringstream ss(options[optionName].currentValue);
- ss >> ret;
- return ret;
- }
-
- // Specialization for std::string where instruction 'ss >> ret'
- // would erroneusly tokenize a string with spaces.
- template<>
- string get_option_value<string>(const string& optionName) {
-
- if (options.find(optionName) == options.end())
- return string();
-
- return options[optionName].currentValue;
- }
-
-}
-
-
-/// init_uci_options() initializes the UCI options. Currently, the only thing
-/// this function does is to initialize the default value of "Threads" and
-/// "Minimum Split Depth" parameters according to the number of CPU cores.