Skip to content

Commit

Permalink
Remove 'fake' ponder hit that keeps killer moves (#644)
Browse files Browse the repository at this point in the history
I had some kind of fake ponder hit that relied on saving the last move.
If the new one matched with the one predicted by the engine, i'd avoid clearing the killers and send the results of the last search before starting the new one.
This adds complexity & potential bugs while apparently not gaining elo now
  • Loading branch information
eduherminio authored Feb 8, 2024
1 parent 9d4cc9f commit e8e9527
Showing 1 changed file with 7 additions and 41 deletions.
48 changes: 7 additions & 41 deletions src/Lynx/Search/IDDFS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,13 @@ public sealed partial class Engine
return onlyOneLegalMoveSearchResult;
}

depth = CheckPonderHit(ref lastSearchResult, depth);
Debug.Assert(_killerMoves.Length == 3);
Array.Clear(_killerMoves[0]);
Array.Clear(_killerMoves[1]);
Array.Clear(_killerMoves[2]);
// Not clearing _quietHistory on purpose
// Not clearing _captureHistory on purpose

if (lastSearchResult is not null)
{
await _engineWriter.WriteAsync(InfoCommand.SearchResultInfo(lastSearchResult));
Expand Down Expand Up @@ -271,46 +277,6 @@ private bool OnlyOneLegalMove([NotNullWhen(true)] out SearchResult? result)
return false;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private int CheckPonderHit(ref SearchResult? lastSearchResult, int depth)
{
if (Game.MoveHistory.Count >= 2
&& _previousSearchResult?.Moves.Count > 2
&& _previousSearchResult.BestMove != default
&& Game.MoveHistory[^2] == _previousSearchResult.Moves[0]
&& Game.MoveHistory[^1] == _previousSearchResult.Moves[1])
{
_logger.Debug("Ponder hit");

lastSearchResult = new SearchResult(_previousSearchResult);

Array.Copy(_previousSearchResult.Moves.ToArray(), 2, _pVTable, 0, _previousSearchResult.Moves.Count - 2);

for (int d = 0; d < Configuration.EngineSettings.MaxDepth - 2; ++d)
{
_killerMoves[0][d] = _previousKillerMoves[0][d + 2];
_killerMoves[1][d] = _previousKillerMoves[1][d + 2];
_killerMoves[2][d] = _previousKillerMoves[2][d + 2];
}

// Re-search from depth 1
depth = 1;
}
else
{
Array.Clear(_killerMoves[0]);
Array.Clear(_killerMoves[1]);
Array.Clear(_killerMoves[2]);
Debug.Assert(_killerMoves.Length == 3);

// Not clearing _quietHistory on purpose

// Not clearing _captureHistory on purpose
}

return depth;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private SearchResult UpdateLastSearchResult(SearchResult? lastSearchResult,
int bestEvaluation, int alpha, int beta, int depth, bool isMateDetected, int bestEvaluationAbs)
Expand Down

0 comments on commit e8e9527

Please sign in to comment.