Skip to content

Commit

Permalink
⚡ Stop checking for two/threefold repetition and 50 moves draws in QS…
Browse files Browse the repository at this point in the history
…earch (#673)

As of now, QSearch only searches captures, pawn promotions and castling moves.
Only the latter could produce a 50 moves repetition, and none of them could produce a two/threefold one.

So it's pointless to check for repetition inside of QSearch.
  • Loading branch information
eduherminio authored Feb 20, 2024
1 parent 0a97d99 commit 80f1afb
Showing 1 changed file with 3 additions and 25 deletions.
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

0 comments on commit 80f1afb

Please sign in to comment.