2 Stockfish, a UCI chess playing engine derived from Glaurung 2.1
3 Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
4 Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
6 Stockfish is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 Stockfish is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include "ucioption.h"
32 OptionsMap Options; // Global object
35 // Our case insensitive less() function as required by UCI protocol
36 bool CaseInsensitiveLess::operator() (const string& s1, const string& s2) const {
41 while (i < s1.size() && i < s2.size())
44 c2 = tolower(s2[i++]);
49 return s1.size() < s2.size();
53 // stringify() converts a numeric value of type T to a std::string
55 static string stringify(const T& v) {
57 std::ostringstream ss;
63 /// OptionsMap c'tor initializes the UCI options to their hard coded default
64 /// values and initializes the default value of "Threads" and "Minimum Split Depth"
65 /// parameters according to the number of CPU cores.
67 OptionsMap::OptionsMap() {
69 OptionsMap& o = *this;
71 o["Use Search Log"] = Option(false);
72 o["Search Log Filename"] = Option("SearchLog.txt");
73 o["Book File"] = Option("book.bin");
74 o["Best Book Move"] = Option(false);
75 o["Mobility (Middle Game)"] = Option(100, 0, 200);
76 o["Mobility (Endgame)"] = Option(100, 0, 200);
77 o["Pawn Structure (Middle Game)"] = Option(100, 0, 200);
78 o["Pawn Structure (Endgame)"] = Option(100, 0, 200);
79 o["Passed Pawns (Middle Game)"] = Option(100, 0, 200);
80 o["Passed Pawns (Endgame)"] = Option(100, 0, 200);
81 o["Space"] = Option(100, 0, 200);
82 o["Aggressiveness"] = Option(100, 0, 200);
83 o["Cowardice"] = Option(100, 0, 200);
84 o["Minimum Split Depth"] = Option(4, 4, 7);
85 o["Maximum Number of Threads per Split Point"] = Option(5, 4, 8);
86 o["Threads"] = Option(1, 1, MAX_THREADS);
87 o["Use Sleeping Threads"] = Option(true);
88 o["Hash"] = Option(32, 4, 8192);
89 o["Clear Hash"] = Option(false, "button");
90 o["Ponder"] = Option(true);
91 o["OwnBook"] = Option(true);
92 o["MultiPV"] = Option(1, 1, 500);
93 o["Skill level"] = Option(20, 0, 20);
94 o["Emergency Move Horizon"] = Option(40, 0, 50);
95 o["Emergency Base Time"] = Option(200, 0, 30000);
96 o["Emergency Move Time"] = Option(70, 0, 5000);
97 o["Minimum Thinking Time"] = Option(20, 0, 5000);
98 o["UCI_Chess960"] = Option(false);
99 o["UCI_AnalyseMode"] = Option(false);
101 // Set some SMP parameters accordingly to the detected CPU count
102 Option& thr = o["Threads"];
103 Option& msd = o["Minimum Split Depth"];
105 thr.defaultValue = thr.currentValue = stringify(cpu_count());
107 if (cpu_count() >= 8)
108 msd.defaultValue = msd.currentValue = stringify(7);
112 /// OptionsMap::print_all() returns a string with all the UCI options in chronological
113 /// insertion order (the idx field) and in the format defined by the UCI protocol.
115 string OptionsMap::print_all() const {
119 for (size_t i = 0; i <= size(); i++)
120 for (OptionsMap::const_iterator it = begin(); it != end(); ++it)
121 if (it->second.idx == i)
123 const Option& o = it->second;
124 s << "\noption name " << it->first << " type " << o.type;
126 if (o.type != "button")
127 s << " default " << o.defaultValue;
129 if (o.type == "spin")
130 s << " min " << o.minValue << " max " << o.maxValue;
138 /// Option class c'tors
140 Option::Option(const char* def) : type("string"), minValue(0), maxValue(0), idx(Options.size())
141 { defaultValue = currentValue = def; }
143 Option::Option(bool def, string t) : type(t), minValue(0), maxValue(0), idx(Options.size())
144 { defaultValue = currentValue = (def ? "true" : "false"); }
146 Option::Option(int def, int minv, int maxv) : type("spin"), minValue(minv), maxValue(maxv), idx(Options.size())
147 { defaultValue = currentValue = stringify(def); }
150 /// set_value() updates currentValue of the Option object. Normally it's up to
151 /// the GUI to check for option's limits, but we could receive the new value
152 /// directly from the user by teminal window. So let's check the bounds anyway.
154 void Option::set_value(const string& v) {
156 assert(!type.empty());
161 if ((type == "check" || type == "button") != (v == "true" || v == "false"))
166 int val = atoi(v.c_str());
167 if (val < minValue || val > maxValue)