Skip to content

Commit

Permalink
Added score stability TM component (liamt19#66)
Browse files Browse the repository at this point in the history
bench: 4743305
  • Loading branch information
liamt19 authored Aug 22, 2024
1 parent 3416a7b commit 2b433b5
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions Logic/Threads/SearchThread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,9 @@ public void Search()
// MultiPV searches will only consider the lesser between the number of legal moves and the requested MultiPV number.
int multiPV = Math.Min(SearchOptions.MultiPV, RootMoves.Count);

Span<int> searchScores = stackalloc int[MaxPly];
int scoreIdx = 0;

RootMove lastBestRootMove = new RootMove(Move.Null);
int stability = 0;

Expand Down Expand Up @@ -479,7 +482,9 @@ public void Search()
}
}

if (SoftTimeUp(tm, stability))
searchScores[scoreIdx++] = RootMoves[0].Score;

if (SoftTimeUp(tm, stability, searchScores[..scoreIdx]))
{
break;
}
Expand Down Expand Up @@ -513,7 +518,7 @@ public void Search()
private static ReadOnlySpan<double> StabilityCoefficients => [2.2, 1.6, 1.4, 1.1, 1, 0.95, 0.9];
private static int StabilityMax = StabilityCoefficients.Length - 1;

private bool SoftTimeUp(TimeManager tm, int stability)
private bool SoftTimeUp(TimeManager tm, int stability, Span<int> searchScores)
{
if (!tm.HasSoftTime)
return false;
Expand All @@ -522,8 +527,15 @@ private bool SoftTimeUp(TimeManager tm, int stability)
double multFactor = 1.0;
if (RootDepth > 7)
{
double proportion = NodeTable[RootMoves[0].Move.From][RootMoves[0].Move.To] / (double)Nodes;
multFactor = ((1.5 - proportion) * 1.75) * StabilityCoefficients[Math.Min(stability, StabilityMax)];
double nodeTM = ((1.5 - NodeTable[RootMoves[0].Move.From][RootMoves[0].Move.To] / (double)Nodes) * 1.75);
double bmStability = StabilityCoefficients[Math.Min(stability, StabilityMax)];

double scoreStability = searchScores[searchScores.Length - 1 - 3]
- searchScores[searchScores.Length - 1 - 0];

scoreStability = Math.Max(0.85, Math.Min(1.15, 0.034 * scoreStability));

multFactor = nodeTM * bmStability * scoreStability;
}

if (tm.GetSearchTime() >= tm.SoftTimeLimit * multFactor)
Expand Down

0 comments on commit 2b433b5

Please sign in to comment.