]> git.sesse.net Git - stockfish/blob - src/ucioption.cpp
Retire "New Game" UCI option
[stockfish] / src / ucioption.cpp
1 /*
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
5
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.
10
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.
15
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/>.
18 */
19
20 #include <iostream>
21 #include <sstream>
22
23 #include "misc.h"
24 #include "thread.h"
25 #include "ucioption.h"
26
27 using std::string;
28 using std::cout;
29 using std::endl;
30
31 OptionsMap Options;
32
33
34 // stringify() converts a numeric value of type T to a std::string
35 template<typename T>
36 static string stringify(const T& v) {
37
38   std::ostringstream ss;
39   ss << v;
40   return ss.str();
41 }
42
43
44 /// init_uci_options() initializes the UCI options to their hard coded default
45 /// values and initializes the default value of "Threads" and "Minimum Split Depth"
46 /// parameters according to the number of CPU cores.
47
48 void init_uci_options() {
49
50   Options["Use Search Log"] = Option(false);
51   Options["Search Log Filename"] = Option("SearchLog.txt");
52   Options["Book File"] = Option("book.bin");
53   Options["Best Book Move"] = Option(false);
54   Options["Mobility (Middle Game)"] = Option(100, 0, 200);
55   Options["Mobility (Endgame)"] = Option(100, 0, 200);
56   Options["Pawn Structure (Middle Game)"] = Option(100, 0, 200);
57   Options["Pawn Structure (Endgame)"] = Option(100, 0, 200);
58   Options["Passed Pawns (Middle Game)"] = Option(100, 0, 200);
59   Options["Passed Pawns (Endgame)"] = Option(100, 0, 200);
60   Options["Space"] = Option(100, 0, 200);
61   Options["Aggressiveness"] = Option(100, 0, 200);
62   Options["Cowardice"] = Option(100, 0, 200);
63   Options["Check Extension (PV nodes)"] = Option(2, 0, 2);
64   Options["Check Extension (non-PV nodes)"] = Option(1, 0, 2);
65   Options["Single Evasion Extension (PV nodes)"] = Option(2, 0, 2);
66   Options["Single Evasion Extension (non-PV nodes)"] = Option(2, 0, 2);
67   Options["Mate Threat Extension (PV nodes)"] = Option(2, 0, 2);
68   Options["Mate Threat Extension (non-PV nodes)"] = Option(2, 0, 2);
69   Options["Pawn Push to 7th Extension (PV nodes)"] = Option(1, 0, 2);
70   Options["Pawn Push to 7th Extension (non-PV nodes)"] = Option(1, 0, 2);
71   Options["Passed Pawn Extension (PV nodes)"] = Option(1, 0, 2);
72   Options["Passed Pawn Extension (non-PV nodes)"] = Option(0, 0, 2);
73   Options["Pawn Endgame Extension (PV nodes)"] = Option(2, 0, 2);
74   Options["Pawn Endgame Extension (non-PV nodes)"] = Option(2, 0, 2);
75   Options["Minimum Split Depth"] = Option(4, 4, 7);
76   Options["Maximum Number of Threads per Split Point"] = Option(5, 4, 8);
77   Options["Threads"] = Option(1, 1, MAX_THREADS);
78   Options["Use Sleeping Master"] = Option(false);
79   Options["Hash"] = Option(32, 4, 8192);
80   Options["Clear Hash"] = Option(false, "button");
81   Options["Ponder"] = Option(true);
82   Options["OwnBook"] = Option(true);
83   Options["MultiPV"] = Option(1, 1, 500);
84   Options["Emergency Move Horizon"] = Option(40, 0, 50);
85   Options["Emergency Base Time"] = Option(200, 0, 60000);
86   Options["Emergency Move Time"] = Option(70, 0, 5000);
87   Options["Minimum Thinking Time"] = Option(20, 0, 5000);
88   Options["UCI_Chess960"] = Option(false); // Just a dummy but needed by GUIs
89   Options["UCI_AnalyseMode"] = Option(false);
90
91   // Set some SMP parameters accordingly to the detected CPU count
92   Option& thr = Options["Threads"];
93   Option& msd = Options["Minimum Split Depth"];
94
95   thr.defaultValue = thr.currentValue = stringify(cpu_count());
96
97   if (cpu_count() >= 8)
98       msd.defaultValue = msd.currentValue = stringify(7);
99 }
100
101
102 /// print_uci_options() prints all the UCI options to the standard output,
103 /// in chronological insertion order (the idx field) and in the format
104 /// defined by the UCI protocol.
105
106 void print_uci_options() {
107
108   for (size_t i = 0; i <= Options.size(); i++)
109       for (OptionsMap::const_iterator it = Options.begin(); it != Options.end(); ++it)
110           if (it->second.idx == i)
111           {
112               const Option& o = it->second;
113               cout << "\noption name " << it->first << " type " << o.type;
114
115               if (o.type != "button")
116                   cout << " default " << o.defaultValue;
117
118               if (o.type == "spin")
119                   cout << " min " << o.minValue << " max " << o.maxValue;
120
121               break;
122           }
123   cout << endl;
124 }
125
126
127 /// Option class c'tors
128
129 Option::Option(const char* def) : type("string"), idx(Options.size()), minValue(0), maxValue(0)
130 { defaultValue = currentValue = def; }
131
132 Option::Option(bool def, string t) : type(t), idx(Options.size()), minValue(0), maxValue(0)
133 { defaultValue = currentValue = (def ? "true" : "false"); }
134
135 Option::Option(int def, int minv, int maxv) : type("spin"), idx(Options.size()), minValue(minv), maxValue(maxv)
136 { defaultValue = currentValue = stringify(def); }
137
138
139 /// set_value() updates currentValue of the Option object. Normally it's up to
140 /// the GUI to check for option's limits, but we could receive the new value
141 /// directly from the user by teminal window. So let's check the bounds anyway.
142
143 void Option::set_value(const string& value) {
144
145   assert(!type.empty());
146
147   if (    (type == "check" || type == "button")
148       && !(value == "true" || value == "false"))
149       return;
150
151   if (type == "spin")
152   {
153       int v = atoi(value.c_str());
154       if (v < minValue || v > maxValue)
155           return;
156   }
157
158   currentValue = value;
159 }