Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚡ Stop checking for two/threefold repetition and 50 moves draws in QSearch #673

Merged
merged 2 commits into from
Feb 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 3 additions & 25 deletions src/Lynx/Search/NegaMax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -546,32 +546,10 @@ public int QuiescenceSearch(int ply, int alpha, int beta)

PrintPreMove(position, ply, move, isQuiescence: true);

// Before making a move
var oldValue = Game.HalfMovesWithoutCaptureOrPawnMove;
Game.HalfMovesWithoutCaptureOrPawnMove = Utils.Update50movesRule(move, Game.HalfMovesWithoutCaptureOrPawnMove);
var isThreeFoldRepetition = !Game.PositionHashHistory.Add(position.UniqueIdentifier);

int evaluation;
if (isThreeFoldRepetition || Game.Is50MovesRepetition())
{
evaluation = 0;

// We don't need to evaluate further down to know it's a draw.
// Since we won't be evaluating further down, we need to clear the PV table because those moves there
// don't belong to this line and if this move were to beat alpha, they'd incorrectly copied to pv line.
Array.Clear(_pVTable, nextPvIndex, _pVTable.Length - nextPvIndex);
}
else
{
evaluation = -QuiescenceSearch(ply + 1, -beta, -alpha);
}
// No need to check for threefold or 50 moves repetitions, since we're only searching captures, promotions, and castles
// Theoretically there could be a castling move that caused the 50 moves repetitions, but it's highly unlikely

// After making a move
Game.HalfMovesWithoutCaptureOrPawnMove = oldValue;
if (!isThreeFoldRepetition)
{
Game.PositionHashHistory.Remove(position.UniqueIdentifier);
}
int evaluation = -QuiescenceSearch(ply + 1, -beta, -alpha);
position.UnmakeMove(move, gameState);

PrintMove(ply, move, evaluation);
Expand Down
Loading