Skip to content

Commit

Permalink
Remove aspiration windows
Browse files Browse the repository at this point in the history
  • Loading branch information
eduherminio committed Nov 19, 2024
1 parent 1cc2477 commit 1ea9842
Showing 1 changed file with 1 addition and 50 deletions.
51 changes: 1 addition & 50 deletions src/Lynx/Search/IDDFS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,56 +104,7 @@ public SearchResult IDDFS(int maxDepth, int softLimitTimeBound)
_absoluteSearchCancellationTokenSource.Token.ThrowIfCancellationRequested();
_searchCancellationTokenSource.Token.ThrowIfCancellationRequested();

if (depth < Configuration.EngineSettings.AspirationWindow_MinDepth
|| lastSearchResult?.Score is null)
{
bestScore = NegaMax(depth: depth, ply: 0, alpha, beta);
}
else
{
// 🔍 Aspiration windows - search using a window around an expected score (the previous search one)
// If the resulting score doesn't fall inside of the window, it is widened it until it does
var window = Configuration.EngineSettings.AspirationWindow_Base;

// A temporary reduction is used for fail highs, because the verification for those 'too good' lines
// are expected to happen at lower depths
int failHighReduction = 0;

alpha = Math.Max(EvaluationConstants.MinEval, lastSearchResult.Score - window);
beta = Math.Min(EvaluationConstants.MaxEval, lastSearchResult.Score + window);

_logger.Debug("Aspiration windows depth {Depth}: [{Alpha}, {Beta}] for previous search score {Score}, nodes {Nodes}",
depth, alpha, beta, lastSearchResult.Score, _nodes);
Debug.Assert(lastSearchResult.Mate == 0 && lastSearchResult.Score > EvaluationConstants.NegativeCheckmateDetectionLimit && lastSearchResult.Score < EvaluationConstants.PositiveCheckmateDetectionLimit);

while (true)
{
_logger.Debug("Aspiration windows depth {Depth}: [{Alpha}, {Beta}] for score {Score}, nodes {Nodes}",
depth, alpha, beta, bestScore, _nodes);

bestScore = NegaMax(depth: depth - failHighReduction, ply: 0, alpha, beta);

// 13, 19, 28, 42, 63, 94, 141, 211, 316, 474, 711, 1066, 1599, 2398, 3597, 5395, 8092, 12138, 18207, 27310, |EvaluationConstants.MaxEval|, 40965
window += window >> 1; // window / 2

// Depth change: https://github.com/lynx-chess/Lynx/pull/440
if (alpha >= bestScore) // Fail low
{
alpha = Math.Max(bestScore - window, EvaluationConstants.MinEval);
beta = (alpha + beta) >> 1; // (alpha + beta) / 2
failHighReduction = 0;
}
else if (beta <= bestScore) // Fail high
{
beta = Math.Min(bestScore + window, EvaluationConstants.MaxEval);
++failHighReduction;
}
else
{
break;
}
}
}
bestScore = NegaMax(depth: depth, ply: 0, alpha, beta);

//PrintPvTable(depth: depth);
ValidatePVTable();
Expand Down

0 comments on commit 1ea9842

Please sign in to comment.