Skip to content

Commit

Permalink
Add bad capture history pruning
Browse files Browse the repository at this point in the history
  • Loading branch information
eduherminio committed Nov 23, 2024
1 parent eaec907 commit 04c3cb1
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 11 deletions.
10 changes: 8 additions & 2 deletions src/Lynx/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,16 @@ public int TranspositionTableSize
public int FP_Margin { get; set; } = 218;

[SPSA<int>(0, 10, 0.5)]
public int HistoryPrunning_MaxDepth { get; set; } = 5;
public int QuietHistoryPrunning_MaxDepth { get; set; } = 5;

[SPSA<int>(-8192, 0, 512)]
public int HistoryPrunning_Margin { get; set; } = -1940;
public int QuietHistoryPrunning_Margin { get; set; } = -1940;

[SPSA<int>(0, 10, 0.5)]
public int CaptureHistoryPrunning_MaxDepth { get; set; } = 5;

[SPSA<int>(-8192, 0, 512)]
public int CaptureHistoryPrunning_Margin { get; set; } = -1940;
}

[JsonSourceGenerationOptions(
Expand Down
19 changes: 14 additions & 5 deletions src/Lynx/Search/NegaMax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,20 @@ void RevertMove()
}

// 🔍 History pruning - all quiet moves can be pruned
// once we find one with a history score too low
if (!isCapture
&& moveScores[moveIndex] < EvaluationConstants.CounterMoveValue
&& depth < Configuration.EngineSettings.HistoryPrunning_MaxDepth // TODO use LMR depth
&& _quietHistory[move.Piece()][move.TargetSquare()] < Configuration.EngineSettings.HistoryPrunning_Margin * (depth - 1))
// once we find one with a history score too low if (isCapture)
if (!isCapture)
{
if (moveScores[moveIndex] < EvaluationConstants.CounterMoveValue
&& depth < Configuration.EngineSettings.CaptureHistoryPrunning_MaxDepth // TODO use LMR depth
&& _captureHistory[CaptureHistoryIndex(move.Piece(), move.TargetSquare(), move.CapturedPiece())] < Configuration.EngineSettings.CaptureHistoryPrunning_Margin * (depth - 1))
{
RevertMove();
break;
}
}
else if (moveScores[moveIndex] < EvaluationConstants.CounterMoveValue
&& depth < Configuration.EngineSettings.QuietHistoryPrunning_MaxDepth // TODO use LMR depth
&& _quietHistory[move.Piece()][move.TargetSquare()] < Configuration.EngineSettings.QuietHistoryPrunning_Margin * (depth - 1))
{
RevertMove();
break;
Expand Down
24 changes: 20 additions & 4 deletions src/Lynx/UCIHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -509,19 +509,35 @@ private void HandleSetOption(ReadOnlySpan<char> command)
}
break;
}
case "historyprunning_maxdepth":
case "quiethistoryprunning_maxdepth":
{
if (length > 4 && int.TryParse(command[commandItems[4]], out var value))
{
Configuration.EngineSettings.HistoryPrunning_MaxDepth = value;
Configuration.EngineSettings.QuietHistoryPrunning_MaxDepth = value;
}
break;
}
case "historyprunning_margin":
case "quiethistoryprunning_margin":
{
if (length > 4 && int.TryParse(command[commandItems[4]], out var value))
{
Configuration.EngineSettings.HistoryPrunning_Margin = value;
Configuration.EngineSettings.QuietHistoryPrunning_Margin = value;
}
break;
}
case "capturehistoryprunning_maxdepth":
{
if (length > 4 && int.TryParse(command[commandItems[4]], out var value))
{
Configuration.EngineSettings.CaptureHistoryPrunning_MaxDepth = value;
}
break;
}
case "capturehistoryprunning_margin":
{
if (length > 4 && int.TryParse(command[commandItems[4]], out var value))
{
Configuration.EngineSettings.CaptureHistoryPrunning_Margin = value;
}
break;
}
Expand Down

0 comments on commit 04c3cb1

Please sign in to comment.