Allow time checking after each DTZ probe

This PR allows for time checking within Tablebases::rank_root_moves(). The
principal application for now is syzygy_extend_pv().

In the past, Stockfish suffered some time losses at e.g. TCEC when the HDD with
the DTZ tables was too slow for the chosen move overhead setting, see #5894.

```
> ./fastchess -engine name="patch" cmd=./stockfish.patch -engine name="master" cmd=./stockfish.master -each tc=10+0.1 option.SyzygyPath=/disk1/syzygy/3-4-5-6/WDL:/disk2/syzygy/3-4-5-6/DTZ -draw movenumber=34 movecount=8 score=20 -openings file=UHO_Lichess_4852_v1.epd format=epd -rounds 50 -repeat -concurrency 16
...
Results of patch vs master (10+0.1, 1t, 16MB, UHO_Lichess_4852_v1.epd):
Elo: 59.64 +/- 35.35, nElo: 117.61 +/- 68.10
LOS: 99.96 %, DrawRatio: 56.00 %, PairsRatio: 4.50
Games: 100, Wins: 34, Losses: 17, Draws: 49, Points: 58.5 (58.50 %)
Ptnml(0-2): [0, 4, 28, 15, 3], WL/DD Ratio: 0.87
--------------------------------------------------

Player: master
  Timeouts: 19
  Crashed: 0

Finished match
```

closes https://github.com/official-stockfish/Stockfish/pull/6422

No functional change
This commit is contained in:
Robert Nurnberg
2025-11-14 17:38:55 +01:00
committed by Joost VandeVondele
parent db824e26be
commit 4b71d8e202
3 changed files with 34 additions and 22 deletions
+15 -12
View File
@@ -1594,10 +1594,11 @@ int Tablebases::probe_dtz(Position& pos, ProbeState* result) {
// Use the DTZ tables to rank root moves.
//
// A return value false indicates that not all probes were successful.
bool Tablebases::root_probe(Position& pos,
Search::RootMoves& rootMoves,
bool rule50,
bool rankDTZ) {
bool Tablebases::root_probe(Position& pos,
Search::RootMoves& rootMoves,
bool rule50,
bool rankDTZ,
const std::function<bool()>& time_abort) {
ProbeState result = OK;
StateInfo st;
@@ -1642,7 +1643,7 @@ bool Tablebases::root_probe(Position& pos,
pos.undo_move(m.pv[0]);
if (result == FAIL)
if (time_abort() || result == FAIL)
return false;
// Better moves are ranked higher. Certain wins are ranked equally.
@@ -1707,10 +1708,11 @@ bool Tablebases::root_probe_wdl(Position& pos, Search::RootMoves& rootMoves, boo
return true;
}
Config Tablebases::rank_root_moves(const OptionsMap& options,
Position& pos,
Search::RootMoves& rootMoves,
bool rankDTZ) {
Config Tablebases::rank_root_moves(const OptionsMap& options,
Position& pos,
Search::RootMoves& rootMoves,
bool rankDTZ,
const std::function<bool()>& time_abort) {
Config config;
if (rootMoves.empty())
@@ -1733,10 +1735,11 @@ Config Tablebases::rank_root_moves(const OptionsMap& options,
if (config.cardinality >= popcount(pos.pieces()) && !pos.can_castle(ANY_CASTLING))
{
// Rank moves using DTZ tables
config.rootInTB = root_probe(pos, rootMoves, options["Syzygy50MoveRule"], rankDTZ);
// Rank moves using DTZ tables, bail out if time_abort flags zeitnot
config.rootInTB =
root_probe(pos, rootMoves, options["Syzygy50MoveRule"], rankDTZ, time_abort);
if (!config.rootInTB)
if (!config.rootInTB && !time_abort())
{
// DTZ tables are missing; try to rank moves using WDL tables
dtz_available = false;