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-2014 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/>.
32 UCI::OptionsMap Options; // Global object
36 /// 'On change' actions, triggered by an option's value change
37 void on_logger(const Option& o) { start_logger(o); }
38 void on_threads(const Option&) { Threads.read_uci_options(); }
39 void on_hash_size(const Option& o) { TT.resize(o); }
40 void on_clear_hash(const Option&) { TT.clear(); }
43 /// Our case insensitive less() function as required by UCI protocol
44 bool ci_less(char c1, char c2) { return tolower(c1) < tolower(c2); }
46 bool CaseInsensitiveLess::operator() (const string& s1, const string& s2) const {
47 return std::lexicographical_compare(s1.begin(), s1.end(), s2.begin(), s2.end(), ci_less);
51 /// init() initializes the UCI options to their hard-coded default values
53 void init(OptionsMap& o) {
55 o["Write Debug Log"] << Option(false, on_logger);
56 o["Contempt"] << Option(0, -100, 100);
57 o["Min Split Depth"] << Option(0, 0, 12, on_threads);
58 o["Threads"] << Option(1, 1, MAX_THREADS, on_threads);
59 o["Hash"] << Option(16, 1, 1024 * 1024, on_hash_size);
60 o["Clear Hash"] << Option(on_clear_hash);
61 o["Ponder"] << Option(true);
62 o["MultiPV"] << Option(1, 1, 500);
63 o["Skill Level"] << Option(20, 0, 20);
64 o["Move Overhead"] << Option(30, 0, 5000);
65 o["Minimum Thinking Time"] << Option(20, 0, 5000);
66 o["Slow Mover"] << Option(80, 10, 1000);
67 o["UCI_Chess960"] << Option(false);
71 /// operator<<() is used to print all the options default values in chronological
72 /// insertion order (the idx field) and in the format defined by the UCI protocol.
74 std::ostream& operator<<(std::ostream& os, const OptionsMap& om) {
76 for (size_t idx = 0; idx < om.size(); ++idx)
77 for (OptionsMap::const_iterator it = om.begin(); it != om.end(); ++it)
78 if (it->second.idx == idx)
80 const Option& o = it->second;
81 os << "\noption name " << it->first << " type " << o.type;
83 if (o.type != "button")
84 os << " default " << o.defaultValue;
87 os << " min " << o.min << " max " << o.max;
95 /// Option class constructors and conversion operators
97 Option::Option(const char* v, OnChange f) : type("string"), min(0), max(0), on_change(f)
98 { defaultValue = currentValue = v; }
100 Option::Option(bool v, OnChange f) : type("check"), min(0), max(0), on_change(f)
101 { defaultValue = currentValue = (v ? "true" : "false"); }
103 Option::Option(OnChange f) : type("button"), min(0), max(0), on_change(f)
106 Option::Option(int v, int minv, int maxv, OnChange f) : type("spin"), min(minv), max(maxv), on_change(f)
107 { std::ostringstream ss; ss << v; defaultValue = currentValue = ss.str(); }
110 Option::operator int() const {
111 assert(type == "check" || type == "spin");
112 return (type == "spin" ? atoi(currentValue.c_str()) : currentValue == "true");
115 Option::operator std::string() const {
116 assert(type == "string");
121 /// operator<<() inits options and assigns idx in the correct printing order
123 void Option::operator<<(const Option& o) {
125 static size_t insert_order = 0;
128 idx = insert_order++;
132 /// operator=() updates currentValue and triggers on_change() action. It's up to
133 /// the GUI to check for option's limits, but we could receive the new value from
134 /// the user by console window, so let's check the bounds anyway.
136 Option& Option::operator=(const string& v) {
138 assert(!type.empty());
140 if ( (type != "button" && v.empty())
141 || (type == "check" && v != "true" && v != "false")
142 || (type == "spin" && (atoi(v.c_str()) < min || atoi(v.c_str()) > max)))
145 if (type != "button")