2008-08-31 23:59:13 -06:00
|
|
|
/*
|
2008-10-19 10:56:28 -06:00
|
|
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
|
|
|
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
2010-03-20 04:27:07 -06:00
|
|
|
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2008-10-19 10:56:28 -06:00
|
|
|
Stockfish is free software: you can redistribute it and/or modify
|
2008-08-31 23:59:13 -06:00
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
2008-09-01 06:05:02 -06:00
|
|
|
|
2008-10-19 10:56:28 -06:00
|
|
|
Stockfish is distributed in the hope that it will be useful,
|
2008-08-31 23:59:13 -06:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2008-09-01 06:05:02 -06:00
|
|
|
|
2008-08-31 23:59:13 -06:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2011-08-03 07:24:55 -06:00
|
|
|
#include <algorithm>
|
2008-09-01 06:05:02 -06:00
|
|
|
#include <sstream>
|
2008-08-31 23:59:13 -06:00
|
|
|
|
|
|
|
#include "misc.h"
|
|
|
|
#include "thread.h"
|
|
|
|
#include "ucioption.h"
|
|
|
|
|
2009-05-10 10:58:53 -06:00
|
|
|
using std::string;
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2010-11-21 15:28:17 -07:00
|
|
|
OptionsMap Options; // Global object
|
|
|
|
|
|
|
|
|
|
|
|
// Our case insensitive less() function as required by UCI protocol
|
2011-08-03 07:24:55 -06:00
|
|
|
static bool ci_less(char c1, char c2) { return tolower(c1) < tolower(c2); }
|
2010-11-21 15:28:17 -07:00
|
|
|
|
2011-08-03 07:24:55 -06:00
|
|
|
bool CaseInsensitiveLess::operator() (const string& s1, const string& s2) const {
|
2011-12-18 12:48:59 -07:00
|
|
|
return lexicographical_compare(s1.begin(), s1.end(), s2.begin(), s2.end(), ci_less);
|
2010-11-21 15:28:17 -07:00
|
|
|
}
|
2009-11-28 09:31:56 -07:00
|
|
|
|
2010-11-20 06:23:28 -07:00
|
|
|
|
2011-07-24 01:26:35 -06:00
|
|
|
// An helper to convert an integer value to a std::string
|
|
|
|
static string int_to_string(int v) {
|
2009-11-28 09:31:56 -07:00
|
|
|
|
2010-11-04 01:03:27 -06:00
|
|
|
std::ostringstream ss;
|
|
|
|
ss << v;
|
|
|
|
return ss.str();
|
2008-09-01 06:05:02 -06:00
|
|
|
}
|
2008-08-31 23:59:13 -06:00
|
|
|
|
|
|
|
|
2011-04-14 07:59:49 -06:00
|
|
|
/// OptionsMap c'tor initializes the UCI options to their hard coded default
|
2010-11-04 01:03:27 -06:00
|
|
|
/// values and initializes the default value of "Threads" and "Minimum Split Depth"
|
|
|
|
/// parameters according to the number of CPU cores.
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2011-04-14 07:59:49 -06:00
|
|
|
OptionsMap::OptionsMap() {
|
|
|
|
|
|
|
|
OptionsMap& o = *this;
|
|
|
|
|
2011-04-29 01:18:54 -06:00
|
|
|
o["Use Search Log"] = UCIOption(false);
|
|
|
|
o["Search Log Filename"] = UCIOption("SearchLog.txt");
|
|
|
|
o["Book File"] = UCIOption("book.bin");
|
|
|
|
o["Best Book Move"] = UCIOption(false);
|
2011-06-24 03:22:26 -06:00
|
|
|
o["Mobility (Middle Game)"] = UCIOption(100, 0, 200);
|
|
|
|
o["Mobility (Endgame)"] = UCIOption(100, 0, 200);
|
2011-04-29 01:18:54 -06:00
|
|
|
o["Passed Pawns (Middle Game)"] = UCIOption(100, 0, 200);
|
|
|
|
o["Passed Pawns (Endgame)"] = UCIOption(100, 0, 200);
|
|
|
|
o["Space"] = UCIOption(100, 0, 200);
|
2011-06-24 03:22:26 -06:00
|
|
|
o["Aggressiveness"] = UCIOption(100, 0, 200);
|
|
|
|
o["Cowardice"] = UCIOption(100, 0, 200);
|
2011-04-29 01:18:54 -06:00
|
|
|
o["Minimum Split Depth"] = UCIOption(4, 4, 7);
|
|
|
|
o["Maximum Number of Threads per Split Point"] = UCIOption(5, 4, 8);
|
|
|
|
o["Threads"] = UCIOption(1, 1, MAX_THREADS);
|
2011-05-08 02:01:41 -06:00
|
|
|
o["Use Sleeping Threads"] = UCIOption(true);
|
2011-04-29 01:18:54 -06:00
|
|
|
o["Hash"] = UCIOption(32, 4, 8192);
|
|
|
|
o["Clear Hash"] = UCIOption(false, "button");
|
|
|
|
o["Ponder"] = UCIOption(true);
|
|
|
|
o["OwnBook"] = UCIOption(true);
|
|
|
|
o["MultiPV"] = UCIOption(1, 1, 500);
|
2011-05-01 00:49:40 -06:00
|
|
|
o["Skill Level"] = UCIOption(20, 0, 20);
|
2011-04-29 01:18:54 -06:00
|
|
|
o["Emergency Move Horizon"] = UCIOption(40, 0, 50);
|
|
|
|
o["Emergency Base Time"] = UCIOption(200, 0, 30000);
|
|
|
|
o["Emergency Move Time"] = UCIOption(70, 0, 5000);
|
|
|
|
o["Minimum Thinking Time"] = UCIOption(20, 0, 5000);
|
|
|
|
o["UCI_Chess960"] = UCIOption(false);
|
|
|
|
o["UCI_AnalyseMode"] = UCIOption(false);
|
2010-11-04 01:03:27 -06:00
|
|
|
|
|
|
|
// Set some SMP parameters accordingly to the detected CPU count
|
2011-04-29 01:18:54 -06:00
|
|
|
UCIOption& thr = o["Threads"];
|
|
|
|
UCIOption& msd = o["Minimum Split Depth"];
|
2010-01-08 04:51:11 -07:00
|
|
|
|
2011-07-24 01:26:35 -06:00
|
|
|
thr.defaultValue = thr.currentValue = int_to_string(cpu_count());
|
2010-01-09 08:45:31 -07:00
|
|
|
|
2010-01-08 04:51:11 -07:00
|
|
|
if (cpu_count() >= 8)
|
2011-07-24 01:26:35 -06:00
|
|
|
msd.defaultValue = msd.currentValue = int_to_string(7);
|
2008-08-31 23:59:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-14 07:59:49 -06:00
|
|
|
/// OptionsMap::print_all() returns a string with all the UCI options in chronological
|
2011-01-09 07:57:18 -07:00
|
|
|
/// insertion order (the idx field) and in the format defined by the UCI protocol.
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2011-04-14 07:59:49 -06:00
|
|
|
string OptionsMap::print_all() const {
|
2011-01-09 07:57:18 -07:00
|
|
|
|
|
|
|
std::stringstream s;
|
2008-09-01 06:05:02 -06:00
|
|
|
|
2011-04-14 07:59:49 -06:00
|
|
|
for (size_t i = 0; i <= size(); i++)
|
|
|
|
for (OptionsMap::const_iterator it = begin(); it != end(); ++it)
|
2010-11-04 01:03:27 -06:00
|
|
|
if (it->second.idx == i)
|
|
|
|
{
|
2011-04-29 01:18:54 -06:00
|
|
|
const UCIOption& o = it->second;
|
2011-01-09 07:57:18 -07:00
|
|
|
s << "\noption name " << it->first << " type " << o.type;
|
2010-11-04 01:03:27 -06:00
|
|
|
|
2010-11-20 06:23:28 -07:00
|
|
|
if (o.type != "button")
|
2011-01-09 07:57:18 -07:00
|
|
|
s << " default " << o.defaultValue;
|
2010-11-20 06:23:28 -07:00
|
|
|
|
|
|
|
if (o.type == "spin")
|
2011-01-09 07:57:18 -07:00
|
|
|
s << " min " << o.minValue << " max " << o.maxValue;
|
2010-11-04 01:03:27 -06:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2011-01-09 07:57:18 -07:00
|
|
|
return s.str();
|
2008-08-31 23:59:13 -06:00
|
|
|
}
|
|
|
|
|
2009-04-11 04:46:47 -06:00
|
|
|
|
2010-11-20 06:23:28 -07:00
|
|
|
/// Option class c'tors
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2011-04-29 01:18:54 -06:00
|
|
|
UCIOption::UCIOption(const char* def) : type("string"), minValue(0), maxValue(0), idx(Options.size())
|
2010-11-04 01:03:27 -06:00
|
|
|
{ defaultValue = currentValue = def; }
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2011-04-29 01:18:54 -06:00
|
|
|
UCIOption::UCIOption(bool def, string t) : type(t), minValue(0), maxValue(0), idx(Options.size())
|
2010-11-20 06:23:28 -07:00
|
|
|
{ defaultValue = currentValue = (def ? "true" : "false"); }
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2011-04-29 01:18:54 -06:00
|
|
|
UCIOption::UCIOption(int def, int minv, int maxv) : type("spin"), minValue(minv), maxValue(maxv), idx(Options.size())
|
2011-07-24 01:26:35 -06:00
|
|
|
{ defaultValue = currentValue = int_to_string(def); }
|
2008-09-01 06:05:02 -06:00
|
|
|
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2010-11-20 06:23:28 -07:00
|
|
|
/// set_value() updates currentValue of the Option object. Normally it's up to
|
|
|
|
/// the GUI to check for option's limits, but we could receive the new value
|
|
|
|
/// directly from the user by teminal window. So let's check the bounds anyway.
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2011-04-29 01:18:54 -06:00
|
|
|
void UCIOption::set_value(const string& v) {
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2010-11-20 06:23:28 -07:00
|
|
|
assert(!type.empty());
|
2010-07-14 07:12:09 -06:00
|
|
|
|
2011-04-04 01:53:44 -06:00
|
|
|
if (v.empty())
|
2011-01-09 06:45:49 -07:00
|
|
|
return;
|
|
|
|
|
2011-04-14 07:59:49 -06:00
|
|
|
if ((type == "check" || type == "button") != (v == "true" || v == "false"))
|
2010-02-01 06:06:59 -07:00
|
|
|
return;
|
|
|
|
|
2010-11-04 01:03:27 -06:00
|
|
|
if (type == "spin")
|
2010-02-01 06:06:59 -07:00
|
|
|
{
|
2011-04-04 01:53:44 -06:00
|
|
|
int val = atoi(v.c_str());
|
|
|
|
if (val < minValue || val > maxValue)
|
2010-02-01 06:06:59 -07:00
|
|
|
return;
|
|
|
|
}
|
2010-11-20 06:23:28 -07:00
|
|
|
|
2011-04-04 01:53:44 -06:00
|
|
|
currentValue = v;
|
2008-08-31 23:59:13 -06:00
|
|
|
}
|