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
|
2021-01-08 09:04:23 -07:00
|
|
|
Copyright (C) 2004-2021 The Stockfish developers (see AUTHORS file)
|
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/>.
|
|
|
|
*/
|
|
|
|
|
2017-05-03 20:46:40 -06:00
|
|
|
#include <cassert>
|
Provide WDL statistics
A number of engines, GUIs and tournaments start to report WDL estimates
along or instead of scores. This patch enables reporting of those stats
in a more or less standard way (http://www.talkchess.com/forum3/viewtopic.php?t=72140)
The model this reporting uses is based on data derived from a few million fishtest LTC games,
given a score and a game ply, a win rate is provided that matches rather closely,
especially in the intermediate range [0.05, 0.95] that data. Some data is shown at
https://github.com/glinscott/fishtest/wiki/UsefulData#win-loss-draw-statistics-of-ltc-games-on-fishtest
Making the conversion game ply dependent is important for a good fit, and is in line
with experience that a +1 score in the early midgame is more likely a win than in the late endgame.
Even when enabled, the printing of the info causes no significant overhead.
Passed STC:
LLR: 2.94 (-2.94,2.94) {-1.50,0.50}
Total: 197112 W: 37226 L: 37347 D: 122539
Ptnml(0-2): 2591, 21025, 51464, 20866, 2610
https://tests.stockfishchess.org/tests/view/5ef79ef4f993893290cc146b
closes https://github.com/official-stockfish/Stockfish/pull/2778
No functional change
2020-06-27 13:29:29 -06:00
|
|
|
#include <cmath>
|
2008-08-31 23:59:13 -06:00
|
|
|
#include <iostream>
|
2008-09-01 00:06:34 -06:00
|
|
|
#include <sstream>
|
2008-08-31 23:59:13 -06:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "evaluate.h"
|
2014-10-26 00:50:09 -06:00
|
|
|
#include "movegen.h"
|
2008-08-31 23:59:13 -06:00
|
|
|
#include "position.h"
|
|
|
|
#include "search.h"
|
2011-11-05 00:53:19 -06:00
|
|
|
#include "thread.h"
|
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
|
|
|
#include "timeman.h"
|
2018-03-20 18:26:12 -06:00
|
|
|
#include "tt.h"
|
2014-10-26 00:09:19 -06:00
|
|
|
#include "uci.h"
|
2016-07-16 00:10:45 -06:00
|
|
|
#include "syzygy/tbprobe.h"
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2009-05-20 04:40:07 -06:00
|
|
|
using namespace std;
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2021-02-26 02:02:13 -07:00
|
|
|
namespace Stockfish {
|
|
|
|
|
2017-08-15 03:51:14 -06:00
|
|
|
extern vector<string> setup_bench(const Position&, istream&);
|
2012-04-01 02:25:07 -06:00
|
|
|
|
2008-08-31 23:59:13 -06:00
|
|
|
namespace {
|
|
|
|
|
2011-12-03 02:41:50 -07:00
|
|
|
// FEN string of the initial position, normal chess
|
|
|
|
const char* StartFEN = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
|
2010-08-19 10:55:32 -06:00
|
|
|
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2013-06-22 04:45:14 -06:00
|
|
|
// position() is called when engine receives the "position" UCI command.
|
2013-12-04 23:18:12 -07:00
|
|
|
// The function sets up the position described in the given FEN string ("fen")
|
2012-08-26 10:07:54 -06:00
|
|
|
// or the starting position ("startpos") and then makes the moves given in the
|
|
|
|
// following move list ("moves").
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2017-08-13 00:38:39 -06:00
|
|
|
void position(Position& pos, istringstream& is, StateListPtr& states) {
|
2008-09-01 00:06:34 -06:00
|
|
|
|
2011-07-17 03:22:08 -06:00
|
|
|
Move m;
|
2011-04-26 03:19:57 -06:00
|
|
|
string token, fen;
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2011-07-24 00:22:37 -06:00
|
|
|
is >> token;
|
2008-09-01 00:16:17 -06:00
|
|
|
|
|
|
|
if (token == "startpos")
|
2010-12-13 03:17:06 -07:00
|
|
|
{
|
2011-12-03 02:41:50 -07:00
|
|
|
fen = StartFEN;
|
2011-07-24 00:22:37 -06:00
|
|
|
is >> token; // Consume "moves" token if any
|
2010-12-13 03:17:06 -07:00
|
|
|
}
|
2011-01-09 06:45:49 -07:00
|
|
|
else if (token == "fen")
|
2011-07-24 00:22:37 -06:00
|
|
|
while (is >> token && token != "moves")
|
2011-01-09 06:45:49 -07:00
|
|
|
fen += token + " ";
|
2011-07-24 00:22:37 -06:00
|
|
|
else
|
|
|
|
return;
|
2011-01-09 03:22:59 -07:00
|
|
|
|
2017-08-13 00:38:39 -06:00
|
|
|
states = StateListPtr(new std::deque<StateInfo>(1)); // Drop old and create a new one
|
|
|
|
pos.set(fen, Options["UCI_Chess960"], &states->back(), Threads.main());
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2011-07-20 02:01:12 -06:00
|
|
|
// Parse move list (if any)
|
2014-10-26 00:41:25 -06:00
|
|
|
while (is >> token && (m = UCI::to_move(pos, token)) != MOVE_NONE)
|
2011-07-18 02:20:37 -06:00
|
|
|
{
|
2017-08-13 00:38:39 -06:00
|
|
|
states->emplace_back();
|
|
|
|
pos.do_move(m, states->back());
|
2011-07-18 02:20:37 -06:00
|
|
|
}
|
2008-08-31 23:59:13 -06:00
|
|
|
}
|
|
|
|
|
Add NNUE evaluation
This patch ports the efficiently updatable neural network (NNUE) evaluation to Stockfish.
Both the NNUE and the classical evaluations are available, and can be used to
assign a value to a position that is later used in alpha-beta (PVS) search to find the
best move. The classical evaluation computes this value as a function of various chess
concepts, handcrafted by experts, tested and tuned using fishtest. The NNUE evaluation
computes this value with a neural network based on basic inputs. The network is optimized
and trained on the evalutions of millions of positions at moderate search depth.
The NNUE evaluation was first introduced in shogi, and ported to Stockfish afterward.
It can be evaluated efficiently on CPUs, and exploits the fact that only parts
of the neural network need to be updated after a typical chess move.
[The nodchip repository](https://github.com/nodchip/Stockfish) provides additional
tools to train and develop the NNUE networks.
This patch is the result of contributions of various authors, from various communities,
including: nodchip, ynasu87, yaneurao (initial port and NNUE authors), domschl, FireFather,
rqs, xXH4CKST3RXx, tttak, zz4032, joergoster, mstembera, nguyenpham, erbsenzaehler,
dorzechowski, and vondele.
This new evaluation needed various changes to fishtest and the corresponding infrastructure,
for which tomtor, ppigazzini, noobpwnftw, daylen, and vondele are gratefully acknowledged.
The first networks have been provided by gekkehenker and sergiovieri, with the latter
net (nn-97f742aaefcd.nnue) being the current default.
The evaluation function can be selected at run time with the `Use NNUE` (true/false) UCI option,
provided the `EvalFile` option points the the network file (depending on the GUI, with full path).
The performance of the NNUE evaluation relative to the classical evaluation depends somewhat on
the hardware, and is expected to improve quickly, but is currently on > 80 Elo on fishtest:
60000 @ 10+0.1 th 1
https://tests.stockfishchess.org/tests/view/5f28fe6ea5abc164f05e4c4c
ELO: 92.77 +-2.1 (95%) LOS: 100.0%
Total: 60000 W: 24193 L: 8543 D: 27264
Ptnml(0-2): 609, 3850, 9708, 10948, 4885
40000 @ 20+0.2 th 8
https://tests.stockfishchess.org/tests/view/5f290229a5abc164f05e4c58
ELO: 89.47 +-2.0 (95%) LOS: 100.0%
Total: 40000 W: 12756 L: 2677 D: 24567
Ptnml(0-2): 74, 1583, 8550, 7776, 2017
At the same time, the impact on the classical evaluation remains minimal, causing no significant
regression:
sprt @ 10+0.1 th 1
https://tests.stockfishchess.org/tests/view/5f2906a2a5abc164f05e4c5b
LLR: 2.94 (-2.94,2.94) {-6.00,-4.00}
Total: 34936 W: 6502 L: 6825 D: 21609
Ptnml(0-2): 571, 4082, 8434, 3861, 520
sprt @ 60+0.6 th 1
https://tests.stockfishchess.org/tests/view/5f2906cfa5abc164f05e4c5d
LLR: 2.93 (-2.94,2.94) {-6.00,-4.00}
Total: 10088 W: 1232 L: 1265 D: 7591
Ptnml(0-2): 49, 914, 3170, 843, 68
The needed networks can be found at https://tests.stockfishchess.org/nns
It is recommended to use the default one as indicated by the `EvalFile` UCI option.
Guidelines for testing new nets can be found at
https://github.com/glinscott/fishtest/wiki/Creating-my-first-test#nnue-net-tests
Integration has been discussed in various issues:
https://github.com/official-stockfish/Stockfish/issues/2823
https://github.com/official-stockfish/Stockfish/issues/2728
The integration branch will be closed after the merge:
https://github.com/official-stockfish/Stockfish/pull/2825
https://github.com/official-stockfish/Stockfish/tree/nnue-player-wip
closes https://github.com/official-stockfish/Stockfish/pull/2912
This will be an exciting time for computer chess, looking forward to seeing the evolution of
this approach.
Bench: 4746616
2020-08-05 09:11:15 -06:00
|
|
|
// trace_eval() prints the evaluation for the current position, consistent with the UCI
|
|
|
|
// options set so far.
|
|
|
|
|
|
|
|
void trace_eval(Position& pos) {
|
|
|
|
|
|
|
|
StateListPtr states(new std::deque<StateInfo>(1));
|
|
|
|
Position p;
|
|
|
|
p.set(pos.fen(), Options["UCI_Chess960"], &states->back(), Threads.main());
|
|
|
|
|
2020-09-09 02:49:31 -06:00
|
|
|
Eval::NNUE::verify();
|
Add NNUE evaluation
This patch ports the efficiently updatable neural network (NNUE) evaluation to Stockfish.
Both the NNUE and the classical evaluations are available, and can be used to
assign a value to a position that is later used in alpha-beta (PVS) search to find the
best move. The classical evaluation computes this value as a function of various chess
concepts, handcrafted by experts, tested and tuned using fishtest. The NNUE evaluation
computes this value with a neural network based on basic inputs. The network is optimized
and trained on the evalutions of millions of positions at moderate search depth.
The NNUE evaluation was first introduced in shogi, and ported to Stockfish afterward.
It can be evaluated efficiently on CPUs, and exploits the fact that only parts
of the neural network need to be updated after a typical chess move.
[The nodchip repository](https://github.com/nodchip/Stockfish) provides additional
tools to train and develop the NNUE networks.
This patch is the result of contributions of various authors, from various communities,
including: nodchip, ynasu87, yaneurao (initial port and NNUE authors), domschl, FireFather,
rqs, xXH4CKST3RXx, tttak, zz4032, joergoster, mstembera, nguyenpham, erbsenzaehler,
dorzechowski, and vondele.
This new evaluation needed various changes to fishtest and the corresponding infrastructure,
for which tomtor, ppigazzini, noobpwnftw, daylen, and vondele are gratefully acknowledged.
The first networks have been provided by gekkehenker and sergiovieri, with the latter
net (nn-97f742aaefcd.nnue) being the current default.
The evaluation function can be selected at run time with the `Use NNUE` (true/false) UCI option,
provided the `EvalFile` option points the the network file (depending on the GUI, with full path).
The performance of the NNUE evaluation relative to the classical evaluation depends somewhat on
the hardware, and is expected to improve quickly, but is currently on > 80 Elo on fishtest:
60000 @ 10+0.1 th 1
https://tests.stockfishchess.org/tests/view/5f28fe6ea5abc164f05e4c4c
ELO: 92.77 +-2.1 (95%) LOS: 100.0%
Total: 60000 W: 24193 L: 8543 D: 27264
Ptnml(0-2): 609, 3850, 9708, 10948, 4885
40000 @ 20+0.2 th 8
https://tests.stockfishchess.org/tests/view/5f290229a5abc164f05e4c58
ELO: 89.47 +-2.0 (95%) LOS: 100.0%
Total: 40000 W: 12756 L: 2677 D: 24567
Ptnml(0-2): 74, 1583, 8550, 7776, 2017
At the same time, the impact on the classical evaluation remains minimal, causing no significant
regression:
sprt @ 10+0.1 th 1
https://tests.stockfishchess.org/tests/view/5f2906a2a5abc164f05e4c5b
LLR: 2.94 (-2.94,2.94) {-6.00,-4.00}
Total: 34936 W: 6502 L: 6825 D: 21609
Ptnml(0-2): 571, 4082, 8434, 3861, 520
sprt @ 60+0.6 th 1
https://tests.stockfishchess.org/tests/view/5f2906cfa5abc164f05e4c5d
LLR: 2.93 (-2.94,2.94) {-6.00,-4.00}
Total: 10088 W: 1232 L: 1265 D: 7591
Ptnml(0-2): 49, 914, 3170, 843, 68
The needed networks can be found at https://tests.stockfishchess.org/nns
It is recommended to use the default one as indicated by the `EvalFile` UCI option.
Guidelines for testing new nets can be found at
https://github.com/glinscott/fishtest/wiki/Creating-my-first-test#nnue-net-tests
Integration has been discussed in various issues:
https://github.com/official-stockfish/Stockfish/issues/2823
https://github.com/official-stockfish/Stockfish/issues/2728
The integration branch will be closed after the merge:
https://github.com/official-stockfish/Stockfish/pull/2825
https://github.com/official-stockfish/Stockfish/tree/nnue-player-wip
closes https://github.com/official-stockfish/Stockfish/pull/2912
This will be an exciting time for computer chess, looking forward to seeing the evolution of
this approach.
Bench: 4746616
2020-08-05 09:11:15 -06:00
|
|
|
|
|
|
|
sync_cout << "\n" << Eval::trace(p) << sync_endl;
|
|
|
|
}
|
|
|
|
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2013-06-22 04:45:14 -06:00
|
|
|
// setoption() is called when engine receives the "setoption" UCI command. The
|
2011-12-03 02:41:50 -07:00
|
|
|
// function updates the UCI option ("name") to the given value ("value").
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2013-06-22 04:45:14 -06:00
|
|
|
void setoption(istringstream& is) {
|
2008-09-01 00:06:34 -06:00
|
|
|
|
2011-07-17 05:26:50 -06:00
|
|
|
string token, name, value;
|
2008-09-01 00:16:17 -06:00
|
|
|
|
2011-07-24 00:22:37 -06:00
|
|
|
is >> token; // Consume "name" token
|
2010-01-07 03:59:32 -07:00
|
|
|
|
2011-07-17 05:26:50 -06:00
|
|
|
// Read option name (can contain spaces)
|
2011-07-24 00:22:37 -06:00
|
|
|
while (is >> token && token != "value")
|
2018-02-09 17:44:05 -07:00
|
|
|
name += (name.empty() ? "" : " ") + token;
|
2009-07-10 10:34:56 -06:00
|
|
|
|
2011-07-17 05:26:50 -06:00
|
|
|
// Read option value (can contain spaces)
|
2011-07-24 00:22:37 -06:00
|
|
|
while (is >> token)
|
2018-02-09 17:44:05 -07:00
|
|
|
value += (value.empty() ? "" : " ") + token;
|
2010-11-03 02:32:14 -06:00
|
|
|
|
2012-03-17 14:18:02 -06:00
|
|
|
if (Options.count(name))
|
2011-12-28 10:27:18 -07:00
|
|
|
Options[name] = value;
|
2012-03-17 14:18:02 -06:00
|
|
|
else
|
2012-08-29 05:28:59 -06:00
|
|
|
sync_cout << "No such option: " << name << sync_endl;
|
2008-08-31 23:59:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-03 02:41:50 -07:00
|
|
|
// go() is called when engine receives the "go" UCI command. The function sets
|
2015-01-03 02:51:38 -07:00
|
|
|
// the thinking time and other parameters from the input string, then starts
|
2012-03-27 04:27:57 -06:00
|
|
|
// the search.
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2017-08-13 00:38:39 -06:00
|
|
|
void go(Position& pos, istringstream& is, StateListPtr& states) {
|
2008-09-01 00:06:34 -06:00
|
|
|
|
2011-11-27 09:07:17 -07:00
|
|
|
Search::LimitsType limits;
|
2012-03-27 04:27:57 -06:00
|
|
|
string token;
|
2017-08-10 13:32:50 -06:00
|
|
|
bool ponderMode = false;
|
2008-08-31 23:59:13 -06:00
|
|
|
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
limits.startTime = now(); // As early as possible!
|
|
|
|
|
2011-07-24 00:22:37 -06:00
|
|
|
while (is >> token)
|
2020-03-30 14:45:35 -06:00
|
|
|
if (token == "searchmoves") // Needs to be the last command on the line
|
2011-07-24 00:22:37 -06:00
|
|
|
while (is >> token)
|
2014-10-26 00:41:25 -06:00
|
|
|
limits.searchmoves.push_back(UCI::to_move(pos, token));
|
2012-10-28 04:09:47 -06:00
|
|
|
|
|
|
|
else if (token == "wtime") is >> limits.time[WHITE];
|
|
|
|
else if (token == "btime") is >> limits.time[BLACK];
|
|
|
|
else if (token == "winc") is >> limits.inc[WHITE];
|
|
|
|
else if (token == "binc") is >> limits.inc[BLACK];
|
|
|
|
else if (token == "movestogo") is >> limits.movestogo;
|
|
|
|
else if (token == "depth") is >> limits.depth;
|
|
|
|
else if (token == "nodes") is >> limits.nodes;
|
|
|
|
else if (token == "movetime") is >> limits.movetime;
|
2012-12-30 03:40:20 -07:00
|
|
|
else if (token == "mate") is >> limits.mate;
|
2017-08-15 02:05:22 -06:00
|
|
|
else if (token == "perft") is >> limits.perft;
|
2015-09-27 02:53:39 -06:00
|
|
|
else if (token == "infinite") limits.infinite = 1;
|
2017-08-10 13:32:50 -06:00
|
|
|
else if (token == "ponder") ponderMode = true;
|
2011-12-03 02:41:50 -07:00
|
|
|
|
2017-08-13 00:38:39 -06:00
|
|
|
Threads.start_thinking(pos, states, limits, ponderMode);
|
2008-08-31 23:59:13 -06:00
|
|
|
}
|
2014-04-12 04:05:25 -06:00
|
|
|
|
2017-08-14 11:41:04 -06:00
|
|
|
|
|
|
|
// bench() is called when engine receives the "bench" command. Firstly
|
|
|
|
// a list of UCI commands is setup according to bench parameters, then
|
2017-08-15 02:05:22 -06:00
|
|
|
// it is run one by one printing a summary at the end.
|
2017-08-14 11:41:04 -06:00
|
|
|
|
|
|
|
void bench(Position& pos, istream& args, StateListPtr& states) {
|
|
|
|
|
|
|
|
string token;
|
|
|
|
uint64_t num, nodes = 0, cnt = 1;
|
|
|
|
|
|
|
|
vector<string> list = setup_bench(pos, args);
|
2019-11-27 11:03:23 -07:00
|
|
|
num = count_if(list.begin(), list.end(), [](string s) { return s.find("go ") == 0 || s.find("eval") == 0; });
|
2017-08-14 11:41:04 -06:00
|
|
|
|
|
|
|
TimePoint elapsed = now();
|
|
|
|
|
|
|
|
for (const auto& cmd : list)
|
|
|
|
{
|
|
|
|
istringstream is(cmd);
|
|
|
|
is >> skipws >> token;
|
|
|
|
|
2019-11-27 11:03:23 -07:00
|
|
|
if (token == "go" || token == "eval")
|
2017-08-14 11:41:04 -06:00
|
|
|
{
|
2020-09-09 22:24:40 -06:00
|
|
|
cerr << "\nPosition: " << cnt++ << '/' << num << " (" << pos.fen() << ")" << endl;
|
2019-11-27 11:03:23 -07:00
|
|
|
if (token == "go")
|
|
|
|
{
|
|
|
|
go(pos, is, states);
|
|
|
|
Threads.main()->wait_for_search_finished();
|
|
|
|
nodes += Threads.nodes_searched();
|
|
|
|
}
|
|
|
|
else
|
Add NNUE evaluation
This patch ports the efficiently updatable neural network (NNUE) evaluation to Stockfish.
Both the NNUE and the classical evaluations are available, and can be used to
assign a value to a position that is later used in alpha-beta (PVS) search to find the
best move. The classical evaluation computes this value as a function of various chess
concepts, handcrafted by experts, tested and tuned using fishtest. The NNUE evaluation
computes this value with a neural network based on basic inputs. The network is optimized
and trained on the evalutions of millions of positions at moderate search depth.
The NNUE evaluation was first introduced in shogi, and ported to Stockfish afterward.
It can be evaluated efficiently on CPUs, and exploits the fact that only parts
of the neural network need to be updated after a typical chess move.
[The nodchip repository](https://github.com/nodchip/Stockfish) provides additional
tools to train and develop the NNUE networks.
This patch is the result of contributions of various authors, from various communities,
including: nodchip, ynasu87, yaneurao (initial port and NNUE authors), domschl, FireFather,
rqs, xXH4CKST3RXx, tttak, zz4032, joergoster, mstembera, nguyenpham, erbsenzaehler,
dorzechowski, and vondele.
This new evaluation needed various changes to fishtest and the corresponding infrastructure,
for which tomtor, ppigazzini, noobpwnftw, daylen, and vondele are gratefully acknowledged.
The first networks have been provided by gekkehenker and sergiovieri, with the latter
net (nn-97f742aaefcd.nnue) being the current default.
The evaluation function can be selected at run time with the `Use NNUE` (true/false) UCI option,
provided the `EvalFile` option points the the network file (depending on the GUI, with full path).
The performance of the NNUE evaluation relative to the classical evaluation depends somewhat on
the hardware, and is expected to improve quickly, but is currently on > 80 Elo on fishtest:
60000 @ 10+0.1 th 1
https://tests.stockfishchess.org/tests/view/5f28fe6ea5abc164f05e4c4c
ELO: 92.77 +-2.1 (95%) LOS: 100.0%
Total: 60000 W: 24193 L: 8543 D: 27264
Ptnml(0-2): 609, 3850, 9708, 10948, 4885
40000 @ 20+0.2 th 8
https://tests.stockfishchess.org/tests/view/5f290229a5abc164f05e4c58
ELO: 89.47 +-2.0 (95%) LOS: 100.0%
Total: 40000 W: 12756 L: 2677 D: 24567
Ptnml(0-2): 74, 1583, 8550, 7776, 2017
At the same time, the impact on the classical evaluation remains minimal, causing no significant
regression:
sprt @ 10+0.1 th 1
https://tests.stockfishchess.org/tests/view/5f2906a2a5abc164f05e4c5b
LLR: 2.94 (-2.94,2.94) {-6.00,-4.00}
Total: 34936 W: 6502 L: 6825 D: 21609
Ptnml(0-2): 571, 4082, 8434, 3861, 520
sprt @ 60+0.6 th 1
https://tests.stockfishchess.org/tests/view/5f2906cfa5abc164f05e4c5d
LLR: 2.93 (-2.94,2.94) {-6.00,-4.00}
Total: 10088 W: 1232 L: 1265 D: 7591
Ptnml(0-2): 49, 914, 3170, 843, 68
The needed networks can be found at https://tests.stockfishchess.org/nns
It is recommended to use the default one as indicated by the `EvalFile` UCI option.
Guidelines for testing new nets can be found at
https://github.com/glinscott/fishtest/wiki/Creating-my-first-test#nnue-net-tests
Integration has been discussed in various issues:
https://github.com/official-stockfish/Stockfish/issues/2823
https://github.com/official-stockfish/Stockfish/issues/2728
The integration branch will be closed after the merge:
https://github.com/official-stockfish/Stockfish/pull/2825
https://github.com/official-stockfish/Stockfish/tree/nnue-player-wip
closes https://github.com/official-stockfish/Stockfish/pull/2912
This will be an exciting time for computer chess, looking forward to seeing the evolution of
this approach.
Bench: 4746616
2020-08-05 09:11:15 -06:00
|
|
|
trace_eval(pos);
|
2017-08-14 11:41:04 -06:00
|
|
|
}
|
|
|
|
else if (token == "setoption") setoption(is);
|
|
|
|
else if (token == "position") position(pos, is, states);
|
2019-06-30 07:16:20 -06:00
|
|
|
else if (token == "ucinewgame") { Search::clear(); elapsed = now(); } // Search::clear() may take some while
|
2017-08-14 11:41:04 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
elapsed = now() - elapsed + 1; // Ensure positivity to avoid a 'divide by zero'
|
|
|
|
|
|
|
|
dbg_print(); // Just before exiting
|
|
|
|
|
|
|
|
cerr << "\n==========================="
|
|
|
|
<< "\nTotal time (ms) : " << elapsed
|
|
|
|
<< "\nNodes searched : " << nodes
|
|
|
|
<< "\nNodes/second : " << 1000 * nodes / elapsed << endl;
|
|
|
|
}
|
|
|
|
|
Provide WDL statistics
A number of engines, GUIs and tournaments start to report WDL estimates
along or instead of scores. This patch enables reporting of those stats
in a more or less standard way (http://www.talkchess.com/forum3/viewtopic.php?t=72140)
The model this reporting uses is based on data derived from a few million fishtest LTC games,
given a score and a game ply, a win rate is provided that matches rather closely,
especially in the intermediate range [0.05, 0.95] that data. Some data is shown at
https://github.com/glinscott/fishtest/wiki/UsefulData#win-loss-draw-statistics-of-ltc-games-on-fishtest
Making the conversion game ply dependent is important for a good fit, and is in line
with experience that a +1 score in the early midgame is more likely a win than in the late endgame.
Even when enabled, the printing of the info causes no significant overhead.
Passed STC:
LLR: 2.94 (-2.94,2.94) {-1.50,0.50}
Total: 197112 W: 37226 L: 37347 D: 122539
Ptnml(0-2): 2591, 21025, 51464, 20866, 2610
https://tests.stockfishchess.org/tests/view/5ef79ef4f993893290cc146b
closes https://github.com/official-stockfish/Stockfish/pull/2778
No functional change
2020-06-27 13:29:29 -06:00
|
|
|
// The win rate model returns the probability (per mille) of winning given an eval
|
|
|
|
// and a game-ply. The model fits rather accurately the LTC fishtest statistics.
|
|
|
|
int win_rate_model(Value v, int ply) {
|
|
|
|
|
|
|
|
// The model captures only up to 240 plies, so limit input (and rescale)
|
|
|
|
double m = std::min(240, ply) / 64.0;
|
|
|
|
|
|
|
|
// Coefficients of a 3rd order polynomial fit based on fishtest data
|
|
|
|
// for two parameters needed to transform eval to the argument of a
|
|
|
|
// logistic function.
|
|
|
|
double as[] = {-8.24404295, 64.23892342, -95.73056462, 153.86478679};
|
|
|
|
double bs[] = {-3.37154371, 28.44489198, -56.67657741, 72.05858751};
|
|
|
|
double a = (((as[0] * m + as[1]) * m + as[2]) * m) + as[3];
|
|
|
|
double b = (((bs[0] * m + bs[1]) * m + bs[2]) * m) + bs[3];
|
|
|
|
|
|
|
|
// Transform eval to centipawns with limited range
|
2020-07-11 08:59:33 -06:00
|
|
|
double x = std::clamp(double(100 * v) / PawnValueEg, -1000.0, 1000.0);
|
Provide WDL statistics
A number of engines, GUIs and tournaments start to report WDL estimates
along or instead of scores. This patch enables reporting of those stats
in a more or less standard way (http://www.talkchess.com/forum3/viewtopic.php?t=72140)
The model this reporting uses is based on data derived from a few million fishtest LTC games,
given a score and a game ply, a win rate is provided that matches rather closely,
especially in the intermediate range [0.05, 0.95] that data. Some data is shown at
https://github.com/glinscott/fishtest/wiki/UsefulData#win-loss-draw-statistics-of-ltc-games-on-fishtest
Making the conversion game ply dependent is important for a good fit, and is in line
with experience that a +1 score in the early midgame is more likely a win than in the late endgame.
Even when enabled, the printing of the info causes no significant overhead.
Passed STC:
LLR: 2.94 (-2.94,2.94) {-1.50,0.50}
Total: 197112 W: 37226 L: 37347 D: 122539
Ptnml(0-2): 2591, 21025, 51464, 20866, 2610
https://tests.stockfishchess.org/tests/view/5ef79ef4f993893290cc146b
closes https://github.com/official-stockfish/Stockfish/pull/2778
No functional change
2020-06-27 13:29:29 -06:00
|
|
|
|
|
|
|
// Return win rate in per mille (rounded to nearest)
|
|
|
|
return int(0.5 + 1000 / (1 + std::exp((a - x) / b)));
|
|
|
|
}
|
|
|
|
|
2014-04-12 04:05:25 -06:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
2015-01-03 02:51:38 -07:00
|
|
|
/// UCI::loop() waits for a command from stdin, parses it and calls the appropriate
|
|
|
|
/// function. Also intercepts EOF from stdin to ensure gracefully exiting if the
|
|
|
|
/// GUI dies unexpectedly. When called with some command line arguments, e.g. to
|
|
|
|
/// run 'bench', once the command is executed the function returns immediately.
|
|
|
|
/// In addition to the UCI ones, also some additional debug commands are supported.
|
2014-04-12 04:05:25 -06:00
|
|
|
|
2014-04-12 04:52:10 -06:00
|
|
|
void UCI::loop(int argc, char* argv[]) {
|
2014-04-12 04:05:25 -06:00
|
|
|
|
2016-04-11 08:45:36 -06:00
|
|
|
Position pos;
|
2014-04-12 04:52:10 -06:00
|
|
|
string token, cmd;
|
2017-08-13 00:38:39 -06:00
|
|
|
StateListPtr states(new std::deque<StateInfo>(1));
|
2014-04-12 04:52:10 -06:00
|
|
|
|
2019-09-19 10:10:46 -06:00
|
|
|
pos.set(StartFEN, false, &states->back(), Threads.main());
|
2016-04-11 08:45:36 -06:00
|
|
|
|
2014-04-12 04:52:10 -06:00
|
|
|
for (int i = 1; i < argc; ++i)
|
|
|
|
cmd += std::string(argv[i]) + " ";
|
2014-04-12 04:05:25 -06:00
|
|
|
|
|
|
|
do {
|
2015-01-03 02:51:38 -07:00
|
|
|
if (argc == 1 && !getline(cin, cmd)) // Block here waiting for input or EOF
|
2014-04-12 04:05:25 -06:00
|
|
|
cmd = "quit";
|
|
|
|
|
|
|
|
istringstream is(cmd);
|
|
|
|
|
2017-08-13 00:38:39 -06:00
|
|
|
token.clear(); // Avoid a stale if getline() returns empty or blank line
|
2014-04-12 04:05:25 -06:00
|
|
|
is >> skipws >> token;
|
|
|
|
|
2015-01-03 02:51:38 -07:00
|
|
|
if ( token == "quit"
|
Simplify pondering time management (#1899)
stopOnPonderhit is used to stop search quickly on a ponderhit. It is set by mainThread as part of its time management. However, master employs it as a signal between mainThread and the UCI thread. This is not necessary, it is sufficient for the UCI thread to signal that pondering finished, and mainThread should do its usual time-keeping job, and in this case stop immediately.
This patch implements this, removing stopOnPonderHit as an atomic variable from the ThreadPool,
and moving it as a normal variable to mainThread, reducing its scope. In MainThread::check_time() the search is stopped immediately if ponder switches to false, and the variable stopOnPonderHit is set.
Furthermore, ponder has been moved to mainThread, as the variable is only used to exchange signals between the UCI thread and mainThread.
The version has been tested locally (as fishtest doesn't support ponder):
Score of ponderSimp vs master: 2616 - 2528 - 8630 [0.503] 13774
Elo difference: 2.22 +/- 3.54
which indicates no regression.
No functional change.
2019-01-20 11:14:24 -07:00
|
|
|
|| token == "stop")
|
2017-07-13 17:07:19 -06:00
|
|
|
Threads.stop = true;
|
2017-08-04 11:48:07 -06:00
|
|
|
|
Simplify pondering time management (#1899)
stopOnPonderhit is used to stop search quickly on a ponderhit. It is set by mainThread as part of its time management. However, master employs it as a signal between mainThread and the UCI thread. This is not necessary, it is sufficient for the UCI thread to signal that pondering finished, and mainThread should do its usual time-keeping job, and in this case stop immediately.
This patch implements this, removing stopOnPonderHit as an atomic variable from the ThreadPool,
and moving it as a normal variable to mainThread, reducing its scope. In MainThread::check_time() the search is stopped immediately if ponder switches to false, and the variable stopOnPonderHit is set.
Furthermore, ponder has been moved to mainThread, as the variable is only used to exchange signals between the UCI thread and mainThread.
The version has been tested locally (as fishtest doesn't support ponder):
Score of ponderSimp vs master: 2616 - 2528 - 8630 [0.503] 13774
Elo difference: 2.22 +/- 3.54
which indicates no regression.
No functional change.
2019-01-20 11:14:24 -07:00
|
|
|
// The GUI sends 'ponderhit' to tell us the user has played the expected move.
|
|
|
|
// So 'ponderhit' will be sent if we were told to ponder on the same move the
|
|
|
|
// user has played. We should continue searching but switch from pondering to
|
|
|
|
// normal search.
|
2015-01-03 02:51:38 -07:00
|
|
|
else if (token == "ponderhit")
|
Simplify pondering time management (#1899)
stopOnPonderhit is used to stop search quickly on a ponderhit. It is set by mainThread as part of its time management. However, master employs it as a signal between mainThread and the UCI thread. This is not necessary, it is sufficient for the UCI thread to signal that pondering finished, and mainThread should do its usual time-keeping job, and in this case stop immediately.
This patch implements this, removing stopOnPonderHit as an atomic variable from the ThreadPool,
and moving it as a normal variable to mainThread, reducing its scope. In MainThread::check_time() the search is stopped immediately if ponder switches to false, and the variable stopOnPonderHit is set.
Furthermore, ponder has been moved to mainThread, as the variable is only used to exchange signals between the UCI thread and mainThread.
The version has been tested locally (as fishtest doesn't support ponder):
Score of ponderSimp vs master: 2616 - 2528 - 8630 [0.503] 13774
Elo difference: 2.22 +/- 3.54
which indicates no regression.
No functional change.
2019-01-20 11:14:24 -07:00
|
|
|
Threads.main()->ponder = false; // Switch to normal search
|
2014-04-12 04:05:25 -06:00
|
|
|
|
|
|
|
else if (token == "uci")
|
|
|
|
sync_cout << "id name " << engine_info(true)
|
|
|
|
<< "\n" << Options
|
|
|
|
<< "\nuciok" << sync_endl;
|
|
|
|
|
2017-08-13 00:38:39 -06:00
|
|
|
else if (token == "setoption") setoption(is);
|
|
|
|
else if (token == "go") go(pos, is, states);
|
|
|
|
else if (token == "position") position(pos, is, states);
|
2017-08-06 05:43:02 -06:00
|
|
|
else if (token == "ucinewgame") Search::clear();
|
2015-01-03 02:51:38 -07:00
|
|
|
else if (token == "isready") sync_cout << "readyok" << sync_endl;
|
|
|
|
|
2019-09-19 10:10:46 -06:00
|
|
|
// Additional custom non-UCI commands, mainly for debugging.
|
|
|
|
// Do not use these commands during a search!
|
2019-09-24 11:00:27 -06:00
|
|
|
else if (token == "flip") pos.flip();
|
|
|
|
else if (token == "bench") bench(pos, is, states);
|
|
|
|
else if (token == "d") sync_cout << pos << sync_endl;
|
Add NNUE evaluation
This patch ports the efficiently updatable neural network (NNUE) evaluation to Stockfish.
Both the NNUE and the classical evaluations are available, and can be used to
assign a value to a position that is later used in alpha-beta (PVS) search to find the
best move. The classical evaluation computes this value as a function of various chess
concepts, handcrafted by experts, tested and tuned using fishtest. The NNUE evaluation
computes this value with a neural network based on basic inputs. The network is optimized
and trained on the evalutions of millions of positions at moderate search depth.
The NNUE evaluation was first introduced in shogi, and ported to Stockfish afterward.
It can be evaluated efficiently on CPUs, and exploits the fact that only parts
of the neural network need to be updated after a typical chess move.
[The nodchip repository](https://github.com/nodchip/Stockfish) provides additional
tools to train and develop the NNUE networks.
This patch is the result of contributions of various authors, from various communities,
including: nodchip, ynasu87, yaneurao (initial port and NNUE authors), domschl, FireFather,
rqs, xXH4CKST3RXx, tttak, zz4032, joergoster, mstembera, nguyenpham, erbsenzaehler,
dorzechowski, and vondele.
This new evaluation needed various changes to fishtest and the corresponding infrastructure,
for which tomtor, ppigazzini, noobpwnftw, daylen, and vondele are gratefully acknowledged.
The first networks have been provided by gekkehenker and sergiovieri, with the latter
net (nn-97f742aaefcd.nnue) being the current default.
The evaluation function can be selected at run time with the `Use NNUE` (true/false) UCI option,
provided the `EvalFile` option points the the network file (depending on the GUI, with full path).
The performance of the NNUE evaluation relative to the classical evaluation depends somewhat on
the hardware, and is expected to improve quickly, but is currently on > 80 Elo on fishtest:
60000 @ 10+0.1 th 1
https://tests.stockfishchess.org/tests/view/5f28fe6ea5abc164f05e4c4c
ELO: 92.77 +-2.1 (95%) LOS: 100.0%
Total: 60000 W: 24193 L: 8543 D: 27264
Ptnml(0-2): 609, 3850, 9708, 10948, 4885
40000 @ 20+0.2 th 8
https://tests.stockfishchess.org/tests/view/5f290229a5abc164f05e4c58
ELO: 89.47 +-2.0 (95%) LOS: 100.0%
Total: 40000 W: 12756 L: 2677 D: 24567
Ptnml(0-2): 74, 1583, 8550, 7776, 2017
At the same time, the impact on the classical evaluation remains minimal, causing no significant
regression:
sprt @ 10+0.1 th 1
https://tests.stockfishchess.org/tests/view/5f2906a2a5abc164f05e4c5b
LLR: 2.94 (-2.94,2.94) {-6.00,-4.00}
Total: 34936 W: 6502 L: 6825 D: 21609
Ptnml(0-2): 571, 4082, 8434, 3861, 520
sprt @ 60+0.6 th 1
https://tests.stockfishchess.org/tests/view/5f2906cfa5abc164f05e4c5d
LLR: 2.93 (-2.94,2.94) {-6.00,-4.00}
Total: 10088 W: 1232 L: 1265 D: 7591
Ptnml(0-2): 49, 914, 3170, 843, 68
The needed networks can be found at https://tests.stockfishchess.org/nns
It is recommended to use the default one as indicated by the `EvalFile` UCI option.
Guidelines for testing new nets can be found at
https://github.com/glinscott/fishtest/wiki/Creating-my-first-test#nnue-net-tests
Integration has been discussed in various issues:
https://github.com/official-stockfish/Stockfish/issues/2823
https://github.com/official-stockfish/Stockfish/issues/2728
The integration branch will be closed after the merge:
https://github.com/official-stockfish/Stockfish/pull/2825
https://github.com/official-stockfish/Stockfish/tree/nnue-player-wip
closes https://github.com/official-stockfish/Stockfish/pull/2912
This will be an exciting time for computer chess, looking forward to seeing the evolution of
this approach.
Bench: 4746616
2020-08-05 09:11:15 -06:00
|
|
|
else if (token == "eval") trace_eval(pos);
|
2019-09-24 11:00:27 -06:00
|
|
|
else if (token == "compiler") sync_cout << compiler_info() << sync_endl;
|
2014-04-12 04:05:25 -06:00
|
|
|
else
|
|
|
|
sync_cout << "Unknown command: " << cmd << sync_endl;
|
|
|
|
|
2017-08-13 00:38:39 -06:00
|
|
|
} while (token != "quit" && argc == 1); // Command line args are one-shot
|
2008-08-31 23:59:13 -06:00
|
|
|
}
|
2014-10-26 00:50:09 -06:00
|
|
|
|
|
|
|
|
2015-01-03 02:51:38 -07:00
|
|
|
/// UCI::value() converts a Value to a string suitable for use with the UCI
|
|
|
|
/// protocol specification:
|
2014-10-26 00:50:09 -06:00
|
|
|
///
|
2015-01-03 02:51:38 -07:00
|
|
|
/// cp <x> The score from the engine's point of view in centipawns.
|
|
|
|
/// mate <y> Mate in y moves, not plies. If the engine is getting mated
|
|
|
|
/// use negative values for y.
|
2014-10-26 00:50:09 -06:00
|
|
|
|
2015-01-03 02:51:38 -07:00
|
|
|
string UCI::value(Value v) {
|
2014-10-26 00:50:09 -06:00
|
|
|
|
2017-05-03 20:46:40 -06:00
|
|
|
assert(-VALUE_INFINITE < v && v < VALUE_INFINITE);
|
|
|
|
|
2014-10-26 00:50:09 -06:00
|
|
|
stringstream ss;
|
|
|
|
|
2020-03-14 10:04:50 -06:00
|
|
|
if (abs(v) < VALUE_MATE_IN_MAX_PLY)
|
2014-10-26 00:50:09 -06:00
|
|
|
ss << "cp " << v * 100 / PawnValueEg;
|
|
|
|
else
|
|
|
|
ss << "mate " << (v > 0 ? VALUE_MATE - v + 1 : -VALUE_MATE - v) / 2;
|
|
|
|
|
|
|
|
return ss.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Provide WDL statistics
A number of engines, GUIs and tournaments start to report WDL estimates
along or instead of scores. This patch enables reporting of those stats
in a more or less standard way (http://www.talkchess.com/forum3/viewtopic.php?t=72140)
The model this reporting uses is based on data derived from a few million fishtest LTC games,
given a score and a game ply, a win rate is provided that matches rather closely,
especially in the intermediate range [0.05, 0.95] that data. Some data is shown at
https://github.com/glinscott/fishtest/wiki/UsefulData#win-loss-draw-statistics-of-ltc-games-on-fishtest
Making the conversion game ply dependent is important for a good fit, and is in line
with experience that a +1 score in the early midgame is more likely a win than in the late endgame.
Even when enabled, the printing of the info causes no significant overhead.
Passed STC:
LLR: 2.94 (-2.94,2.94) {-1.50,0.50}
Total: 197112 W: 37226 L: 37347 D: 122539
Ptnml(0-2): 2591, 21025, 51464, 20866, 2610
https://tests.stockfishchess.org/tests/view/5ef79ef4f993893290cc146b
closes https://github.com/official-stockfish/Stockfish/pull/2778
No functional change
2020-06-27 13:29:29 -06:00
|
|
|
/// UCI::wdl() report WDL statistics given an evaluation and a game ply, based on
|
|
|
|
/// data gathered for fishtest LTC games.
|
|
|
|
|
|
|
|
string UCI::wdl(Value v, int ply) {
|
|
|
|
|
|
|
|
stringstream ss;
|
|
|
|
|
|
|
|
int wdl_w = win_rate_model( v, ply);
|
|
|
|
int wdl_l = win_rate_model(-v, ply);
|
|
|
|
int wdl_d = 1000 - wdl_w - wdl_l;
|
|
|
|
ss << " wdl " << wdl_w << " " << wdl_d << " " << wdl_l;
|
|
|
|
|
|
|
|
return ss.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-03 02:51:38 -07:00
|
|
|
/// UCI::square() converts a Square to a string in algebraic notation (g1, a7, etc.)
|
2014-10-26 00:50:09 -06:00
|
|
|
|
2014-12-14 01:31:13 -07:00
|
|
|
std::string UCI::square(Square s) {
|
2015-01-18 03:04:51 -07:00
|
|
|
return std::string{ char('a' + file_of(s)), char('1' + rank_of(s)) };
|
2014-10-26 00:50:09 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-03 02:51:38 -07:00
|
|
|
/// UCI::move() converts a Move to a string in coordinate notation (g1f3, a7a8q).
|
|
|
|
/// The only special case is castling, where we print in the e1g1 notation in
|
|
|
|
/// normal chess mode, and in e1h1 notation in chess960 mode. Internally all
|
|
|
|
/// castling moves are always encoded as 'king captures rook'.
|
2014-10-26 00:50:09 -06:00
|
|
|
|
2014-12-14 01:31:13 -07:00
|
|
|
string UCI::move(Move m, bool chess960) {
|
2014-10-26 00:50:09 -06:00
|
|
|
|
|
|
|
Square from = from_sq(m);
|
|
|
|
Square to = to_sq(m);
|
|
|
|
|
|
|
|
if (m == MOVE_NONE)
|
|
|
|
return "(none)";
|
|
|
|
|
|
|
|
if (m == MOVE_NULL)
|
|
|
|
return "0000";
|
|
|
|
|
|
|
|
if (type_of(m) == CASTLING && !chess960)
|
|
|
|
to = make_square(to > from ? FILE_G : FILE_C, rank_of(from));
|
|
|
|
|
2014-12-14 01:31:13 -07:00
|
|
|
string move = UCI::square(from) + UCI::square(to);
|
2014-10-26 00:50:09 -06:00
|
|
|
|
|
|
|
if (type_of(m) == PROMOTION)
|
|
|
|
move += " pnbrqk"[promotion_type(m)];
|
|
|
|
|
|
|
|
return move;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-03 02:51:38 -07:00
|
|
|
/// UCI::to_move() converts a string representing a move in coordinate notation
|
|
|
|
/// (g1f3, a7a8q) to the corresponding legal Move, if any.
|
2014-10-26 00:50:09 -06:00
|
|
|
|
|
|
|
Move UCI::to_move(const Position& pos, string& str) {
|
|
|
|
|
|
|
|
if (str.length() == 5) // Junior could send promotion piece in uppercase
|
|
|
|
str[4] = char(tolower(str[4]));
|
|
|
|
|
2015-01-31 10:39:51 -07:00
|
|
|
for (const auto& m : MoveList<LEGAL>(pos))
|
|
|
|
if (str == UCI::move(m, pos.is_chess960()))
|
|
|
|
return m;
|
2014-10-26 00:50:09 -06:00
|
|
|
|
|
|
|
return MOVE_NONE;
|
|
|
|
}
|
2021-02-26 02:02:13 -07:00
|
|
|
|
|
|
|
} // namespace Stockfish
|