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)
|
2015-01-10 03:43:28 -07:00
|
|
|
Copyright (C) 2008-2015 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>
|
2012-08-18 04:50:43 -06:00
|
|
|
#include <cassert>
|
2015-04-10 00:57:35 -06:00
|
|
|
#include <ostream>
|
2008-08-31 23:59:13 -06:00
|
|
|
|
|
|
|
#include "misc.h"
|
|
|
|
#include "thread.h"
|
2012-03-04 09:57:01 -07:00
|
|
|
#include "tt.h"
|
2014-10-26 00:09:19 -06:00
|
|
|
#include "uci.h"
|
2015-01-18 00:05:05 -07:00
|
|
|
#include "syzygy/tbprobe.h"
|
2014-11-25 16:45:28 -07:00
|
|
|
|
2009-05-10 10:58:53 -06:00
|
|
|
using std::string;
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2012-08-18 04:50:43 -06:00
|
|
|
UCI::OptionsMap Options; // Global object
|
2010-11-21 15:28:17 -07:00
|
|
|
|
2012-08-18 04:50:43 -06:00
|
|
|
namespace UCI {
|
2010-11-21 15:28:17 -07:00
|
|
|
|
2012-03-05 11:24:59 -07:00
|
|
|
/// 'On change' actions, triggered by an option's value change
|
2014-11-29 01:22:25 -07:00
|
|
|
void on_clear_hash(const Option&) { TT.clear(); }
|
|
|
|
void on_hash_size(const Option& o) { TT.resize(o); }
|
2012-08-18 04:50:43 -06:00
|
|
|
void on_logger(const Option& o) { start_logger(o); }
|
|
|
|
void on_threads(const Option&) { Threads.read_uci_options(); }
|
2015-01-18 00:05:05 -07:00
|
|
|
void on_tb_path(const Option& o) { Tablebases::init(o); }
|
2012-08-18 04:50:43 -06:00
|
|
|
|
2012-03-04 09:57:01 -07:00
|
|
|
|
2011-12-26 08:21:13 -07:00
|
|
|
/// Our case insensitive less() function as required by UCI protocol
|
2011-08-03 07:24:55 -06:00
|
|
|
bool CaseInsensitiveLess::operator() (const string& s1, const string& s2) const {
|
2015-01-18 00:00:50 -07:00
|
|
|
|
|
|
|
return std::lexicographical_compare(s1.begin(), s1.end(), s2.begin(), s2.end(),
|
|
|
|
[](char c1, char c2) { return tolower(c1) < tolower(c2); });
|
2010-11-21 15:28:17 -07:00
|
|
|
}
|
2009-11-28 09:31:56 -07:00
|
|
|
|
2010-11-20 06:23:28 -07:00
|
|
|
|
2013-12-02 11:04:09 -07:00
|
|
|
/// init() initializes the UCI options to their hard-coded default values
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2012-08-18 04:50:43 -06:00
|
|
|
void init(OptionsMap& o) {
|
2011-04-14 07:59:49 -06:00
|
|
|
|
2015-01-17 01:04:25 -07:00
|
|
|
const int MaxHashMB = Is64Bit ? 1024 * 1024 : 2048;
|
|
|
|
|
2014-09-08 07:44:25 -06:00
|
|
|
o["Write Debug Log"] << Option(false, on_logger);
|
2014-09-30 01:05:20 -06:00
|
|
|
o["Contempt"] << Option(0, -100, 100);
|
2015-04-11 15:21:52 -06:00
|
|
|
o["Min Split Depth"] << Option(5, 0, 12, on_threads);
|
2014-09-08 07:44:25 -06:00
|
|
|
o["Threads"] << Option(1, 1, MAX_THREADS, on_threads);
|
2015-01-17 01:04:25 -07:00
|
|
|
o["Hash"] << Option(16, 1, MaxHashMB, on_hash_size);
|
2014-09-08 07:44:25 -06:00
|
|
|
o["Clear Hash"] << Option(on_clear_hash);
|
|
|
|
o["Ponder"] << Option(true);
|
|
|
|
o["MultiPV"] << Option(1, 1, 500);
|
|
|
|
o["Skill Level"] << Option(20, 0, 20);
|
|
|
|
o["Move Overhead"] << Option(30, 0, 5000);
|
|
|
|
o["Minimum Thinking Time"] << Option(20, 0, 5000);
|
|
|
|
o["Slow Mover"] << Option(80, 10, 1000);
|
Add support for playing in 'nodes as time' mode
When running more games in parallel, or simply when running a game
with a background process, due to how OS scheduling works, there is no
guarantee that the CPU resources allocated evenly between the two
players. This introduces noise in the result that leads to unreliable
result and in the worst cases can even invalidate the result. For
instance in SF test framework we avoid running from clouds virtual
machines because are a known source of very unstable CPU speed.
To overcome this issue, without requiring changes to the GUI, the idea
is to use searched nodes instead of time, and to convert time to
available nodes upfront, at the beginning of the game.
When nodestime UCI option is set at a given nodes per milliseconds
(npmsec), at the beginning of the game (and only once), the engine
reads the available time to think, sent by the GUI with 'go wtime x'
UCI command. Then it translates time in available nodes (nodes =
npmsec * x), then feeds available nodes instead of time to the time
management logic and starts the search. During the search the engine
checks the searched nodes against the available ones in such a way
that all the time management logic still fully applies, and the game
mimics a real one played on real time. When the search finishes,
before returning best move, the total available nodes are updated,
subtracting the real searched nodes. After the first move, the time
information sent by the GUI is ignored, and the engine fully relies on
the updated total available nodes to feed time management.
To avoid time losses, the speed of the engine (npms) must be set to a
value lower than real speed so that if the real TC is for instance 30
secs, and npms is half of the real speed, the game will last on
average 15 secs, so much less than the TC limit, providing for a
safety 'time buffer'.
There are 2 main limitations with this mode.
1. Engine speed should be the same for both players, and this limits
the approach to mainly parameter tuning patches.
2. Because npms is fixed while, in real engines, the speed increases
toward endgame, this introduces an artifact that is equivalent to an
altered time management. Namely it is like the time management gives
less available time than what should be in standard case.
May be the second limitation could be mitigated in a future with a
smarter 'dynamic npms' approach.
Tests shows that the standard deviation of the results with 'nodestime'
is lower than in standard TC, as is expected because now all the introduced
noise due the random speed variability of the engines during the game is
fully removed.
Original NIT idea by Michael Hoffman that shows how to play in NIT mode
without requiring changes to the GUI. This implementation goes a bit
further, the key difference is that we read TC from GUI only once upfront
instead of re-reading after every move as in Michael's implementation.
No functional change.
2015-03-22 14:15:44 -06:00
|
|
|
o["nodestime"] << Option(0, 0, 10000);
|
2014-09-08 07:44:25 -06:00
|
|
|
o["UCI_Chess960"] << Option(false);
|
2015-01-18 00:05:05 -07:00
|
|
|
o["SyzygyPath"] << Option("<empty>", on_tb_path);
|
|
|
|
o["SyzygyProbeDepth"] << Option(1, 1, 100);
|
|
|
|
o["Syzygy50MoveRule"] << Option(true);
|
|
|
|
o["SyzygyProbeLimit"] << Option(6, 0, 6);
|
2008-08-31 23:59:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-18 04:50:43 -06:00
|
|
|
/// operator<<() is used to print all the options default values in chronological
|
|
|
|
/// insertion order (the idx field) and in the format defined by the UCI protocol.
|
2012-03-05 11:24:59 -07:00
|
|
|
|
2011-12-26 08:21:13 -07:00
|
|
|
std::ostream& operator<<(std::ostream& os, const OptionsMap& om) {
|
2011-01-09 07:57:18 -07:00
|
|
|
|
2014-04-01 01:39:41 -06:00
|
|
|
for (size_t idx = 0; idx < om.size(); ++idx)
|
2015-01-31 10:39:51 -07:00
|
|
|
for (const auto& it : om)
|
2015-01-18 00:00:50 -07:00
|
|
|
if (it.second.idx == idx)
|
2010-11-04 01:03:27 -06:00
|
|
|
{
|
2015-01-18 00:00:50 -07:00
|
|
|
const Option& o = it.second;
|
|
|
|
os << "\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-12-26 08:21:13 -07:00
|
|
|
os << " default " << o.defaultValue;
|
2010-11-20 06:23:28 -07:00
|
|
|
|
|
|
|
if (o.type == "spin")
|
2011-12-26 08:21:13 -07:00
|
|
|
os << " min " << o.min << " max " << o.max;
|
2010-11-04 01:03:27 -06:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2015-01-18 00:00:50 -07:00
|
|
|
|
2011-12-26 08:21:13 -07:00
|
|
|
return os;
|
2008-08-31 23:59:13 -06:00
|
|
|
}
|
|
|
|
|
2009-04-11 04:46:47 -06:00
|
|
|
|
2014-01-06 22:25:35 -07:00
|
|
|
/// Option class constructors and conversion operators
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2014-04-01 01:39:41 -06:00
|
|
|
Option::Option(const char* v, OnChange f) : type("string"), min(0), max(0), on_change(f)
|
2011-12-26 08:21:13 -07:00
|
|
|
{ defaultValue = currentValue = v; }
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2014-04-01 01:39:41 -06:00
|
|
|
Option::Option(bool v, OnChange f) : type("check"), min(0), max(0), on_change(f)
|
2011-12-26 08:21:13 -07:00
|
|
|
{ defaultValue = currentValue = (v ? "true" : "false"); }
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2014-04-01 01:39:41 -06:00
|
|
|
Option::Option(OnChange f) : type("button"), min(0), max(0), on_change(f)
|
2012-03-17 14:18:02 -06:00
|
|
|
{}
|
2012-03-17 03:29:33 -06:00
|
|
|
|
2014-04-01 01:39:41 -06:00
|
|
|
Option::Option(int v, int minv, int maxv, OnChange f) : type("spin"), min(minv), max(maxv), on_change(f)
|
2015-01-18 00:00:50 -07:00
|
|
|
{ defaultValue = currentValue = std::to_string(v); }
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2012-08-18 04:50:43 -06:00
|
|
|
Option::operator int() const {
|
|
|
|
assert(type == "check" || type == "spin");
|
2015-01-18 00:00:50 -07:00
|
|
|
return (type == "spin" ? stoi(currentValue) : currentValue == "true");
|
2012-08-18 04:50:43 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
Option::operator std::string() const {
|
|
|
|
assert(type == "string");
|
|
|
|
return currentValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-01 01:39:41 -06:00
|
|
|
/// operator<<() inits options and assigns idx in the correct printing order
|
|
|
|
|
2014-04-03 02:34:25 -06:00
|
|
|
void Option::operator<<(const Option& o) {
|
2014-04-01 01:39:41 -06:00
|
|
|
|
2014-04-06 02:50:27 -06:00
|
|
|
static size_t insert_order = 0;
|
2014-04-01 01:39:41 -06:00
|
|
|
|
|
|
|
*this = o;
|
2014-04-06 02:50:27 -06:00
|
|
|
idx = insert_order++;
|
2014-04-01 01:39:41 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-18 04:50:43 -06:00
|
|
|
/// operator=() updates currentValue and triggers on_change() action. It's up to
|
|
|
|
/// the GUI to check for option's limits, but we could receive the new value from
|
2012-03-05 11:24:59 -07:00
|
|
|
/// the user by console window, so let's check the bounds anyway.
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2012-08-18 04:50:43 -06:00
|
|
|
Option& Option::operator=(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
|
|
|
|
2012-06-24 17:14:42 -06:00
|
|
|
if ( (type != "button" && v.empty())
|
|
|
|
|| (type == "check" && v != "true" && v != "false")
|
2015-01-18 00:00:50 -07:00
|
|
|
|| (type == "spin" && (stoi(v) < min || stoi(v) > max)))
|
2012-07-05 04:52:11 -06:00
|
|
|
return *this;
|
2012-06-24 17:14:42 -06:00
|
|
|
|
|
|
|
if (type != "button")
|
|
|
|
currentValue = v;
|
|
|
|
|
|
|
|
if (on_change)
|
2014-02-09 09:31:45 -07:00
|
|
|
on_change(*this);
|
2012-07-05 04:52:11 -06:00
|
|
|
|
|
|
|
return *this;
|
2008-08-31 23:59:13 -06:00
|
|
|
}
|
2012-08-18 04:50:43 -06:00
|
|
|
|
|
|
|
} // namespace UCI
|