Do not change TB cursed wins to draws if requested

If Syzygy50MoveRule is false, do not calls to is_draw() need to be guarded.
Also fixes a TB rootmove ranking issue in this case.

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

No functional change
This commit is contained in:
Robert Nurnberg @ elitebook
2025-01-21 17:23:51 +01:00
committed by Joost VandeVondele
parent 75b75bc16a
commit 6c7c5c7e47
4 changed files with 10 additions and 7 deletions

View File

@@ -1187,11 +1187,12 @@ bool Position::is_draw(int ply) const {
if (st->rule50 > 99 && (!checkers() || MoveList<LEGAL>(*this).size()))
return true;
// Return a draw score if a position repeats once earlier but strictly
// after the root, or repeats twice before or at the root.
return st->repetition && st->repetition < ply;
return is_repetition(ply);
}
// Return a draw score if a position repeats once earlier but strictly
// after the root, or repeats twice before or at the root.
bool Position::is_repetition(int ply) const { return st->repetition && st->repetition < ply; }
// Tests whether there has been at least one repetition
// of positions since the last capture or pawn move.

View File

@@ -163,6 +163,7 @@ class Position {
int game_ply() const;
bool is_chess960() const;
bool is_draw(int ply) const;
bool is_repetition(int ply) const;
bool upcoming_repetition(int ply) const;
bool has_repeated() const;
int rule50_count() const;

View File

@@ -1949,6 +1949,7 @@ void syzygy_extend_pv(const OptionsMap& options,
auto t_start = std::chrono::steady_clock::now();
int moveOverhead = int(options["Move Overhead"]);
bool rule50 = bool(options["Syzygy50MoveRule"]);
// Do not use more than moveOverhead / 2 time, if time management is active
auto time_abort = [&t_start, &moveOverhead, &limits]() -> bool {
@@ -1986,7 +1987,7 @@ void syzygy_extend_pv(const OptionsMap& options,
pos.do_move(pvMove, st);
// Do not allow for repetitions or drawing moves along the PV in TB regime
if (config.rootInTB && pos.is_draw(ply))
if (config.rootInTB && ((rule50 && pos.is_draw(ply)) || pos.is_repetition(ply)))
{
pos.undo_move(pvMove);
ply--;
@@ -2005,7 +2006,7 @@ void syzygy_extend_pv(const OptionsMap& options,
// Step 2, now extend the PV to mate, as if the user explored syzygy-tables.info
// using top ranked moves (minimal DTZ), which gives optimal mates only for simple
// endgames e.g. KRvK.
while (!pos.is_draw(0))
while (!(rule50 && pos.is_draw(0)))
{
if (time_abort())
break;
@@ -2048,7 +2049,7 @@ void syzygy_extend_pv(const OptionsMap& options,
pos.do_move(pvMove, st);
}
// Finding a draw in this function is an exceptional case, that cannot happen
// Finding a draw in this function is an exceptional case, that cannot happen when rule50 is false or
// during engine game play, since we have a winning score, and play correctly
// with TB support. However, it can be that a position is draw due to the 50 move
// rule if it has been been reached on the board with a non-optimal 50 move counter

View File

@@ -1620,7 +1620,7 @@ bool Tablebases::root_probe(Position& pos,
WDLScore wdl = -probe_wdl(pos, &result);
dtz = dtz_before_zeroing(wdl);
}
else if (pos.is_draw(1))
else if ((rule50 && pos.is_draw(1)) || pos.is_repetition(1))
{
// In case a root move leads to a draw by repetition or 50-move rule,
// we set dtz to zero. Note: since we are only 1 ply from the root,