Skip to content

Commit

Permalink
do not change cursed wins to draws (take 2)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertnurnberg committed Jan 21, 2025
1 parent 8e3e22b commit 3bcf21d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/position.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/position.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions src/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1952,6 +1952,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 {
Expand Down Expand Up @@ -1989,7 +1990,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--;
Expand All @@ -2008,7 +2009,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;
Expand Down Expand Up @@ -2051,7 +2052,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
Expand Down
2 changes: 1 addition & 1 deletion src/syzygy/tbprobe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 3bcf21d

Please sign in to comment.