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-2015 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/>.
29 #include "syzygy/tbprobe.h"
33 UCI::OptionsMap Options; // Global object
37 /// 'On change' actions, triggered by an option's value change
38 void on_clear_hash(const Option&) { Search::clear(); }
39 void on_hash_size(const Option& o) { TT.resize(o); }
40 void on_logger(const Option& o) { start_logger(o); }
41 void on_threads(const Option&) { Threads.read_uci_options(); }
42 void on_tb_path(const Option& o) { Tablebases::init(o); }
45 /// Our case insensitive less() function as required by UCI protocol
46 bool CaseInsensitiveLess::operator() (const string& s1, const string& s2) const {
48 return std::lexicographical_compare(s1.begin(), s1.end(), s2.begin(), s2.end(),
49 [](char c1, char c2) { return tolower(c1) < tolower(c2); });
53 /// init() initializes the UCI options to their hard-coded default values
55 void init(OptionsMap& o) {
57 const int MaxHashMB = Is64Bit ? 1024 * 1024 : 2048;
59 o["Write Debug Log"] << Option(false, on_logger);
60 o["Contempt"] << Option(0, -100, 100);
61 o["Threads"] << Option(1, 1, 128, on_threads);
62 o["Hash"] << Option(16, 1, MaxHashMB, on_hash_size);
63 o["Clear Hash"] << Option(on_clear_hash);
64 o["Ponder"] << Option(false);
65 o["MultiPV"] << Option(1, 1, 500);
66 o["Skill Level"] << Option(20, 0, 20);
67 o["Move Overhead"] << Option(30, 0, 5000);
68 o["Minimum Thinking Time"] << Option(20, 0, 5000);
69 o["Slow Mover"] << Option(84, 10, 1000);
70 o["nodestime"] << Option(0, 0, 10000);
71 o["UCI_Chess960"] << Option(false);
72 o["SyzygyPath"] << Option("<empty>", on_tb_path);
73 o["SyzygyProbeDepth"] << Option(1, 1, 100);
74 o["Syzygy50MoveRule"] << Option(true);
75 o["SyzygyProbeLimit"] << Option(6, 0, 6);
79 /// operator<<() is used to print all the options default values in chronological
80 /// insertion order (the idx field) and in the format defined by the UCI protocol.
82 std::ostream& operator<<(std::ostream& os, const OptionsMap& om) {
84 for (size_t idx = 0; idx < om.size(); ++idx)
85 for (const auto& it : om)
86 if (it.second.idx == idx)
88 const Option& o = it.second;
89 os << "\noption name " << it.first << " type " << o.type;
91 if (o.type != "button")
92 os << " default " << o.defaultValue;
95 os << " min " << o.min << " max " << o.max;
104 /// Option class constructors and conversion operators
106 Option::Option(const char* v, OnChange f) : type("string"), min(0), max(0), on_change(f)
107 { defaultValue = currentValue = v; }
109 Option::Option(bool v, OnChange f) : type("check"), min(0), max(0), on_change(f)
110 { defaultValue = currentValue = (v ? "true" : "false"); }
112 Option::Option(OnChange f) : type("button"), min(0), max(0), on_change(f)
115 Option::Option(int v, int minv, int maxv, OnChange f) : type("spin"), min(minv), max(maxv), on_change(f)
116 { defaultValue = currentValue = std::to_string(v); }
118 Option::operator int() const {
119 assert(type == "check" || type == "spin");
120 return (type == "spin" ? stoi(currentValue) : currentValue == "true");
123 Option::operator std::string() const {
124 assert(type == "string");
129 /// operator<<() inits options and assigns idx in the correct printing order
131 void Option::operator<<(const Option& o) {
133 static size_t insert_order = 0;
136 idx = insert_order++;
140 /// operator=() updates currentValue and triggers on_change() action. It's up to
141 /// the GUI to check for option's limits, but we could receive the new value from
142 /// the user by console window, so let's check the bounds anyway.
144 Option& Option::operator=(const string& v) {
146 assert(!type.empty());
148 if ( (type != "button" && v.empty())
149 || (type == "check" && v != "true" && v != "false")
150 || (type == "spin" && (stoi(v) < min || stoi(v) > max)))
153 if (type != "button")