Skip to content

Commit

Permalink
Add 'modern' razoring implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
eduherminio committed May 16, 2024
1 parent 19b2ee9 commit eb6b44f
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Lynx.Cli/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
"FP_DepthScalingFactor": 60,
"FP_Margin": 250,

"Razoring2_MaxDepth": 4,
"Razoring2_AlphaMargin": 2000,
"Razoring2_DepthScalingFactor": 250,

// Evaluation
"IsolatedPawnPenalty": {
"MG": -21,
Expand Down
14 changes: 13 additions & 1 deletion src/Lynx/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ public sealed class EngineSettings
[SPSAAttribute<int>(1, 20, 1)]
public int AspirationWindow_MinDepth { get; set; } = 7;

[SPSAAttribute<int>(1, 20, 1)]
/// <summary>
/// Min 2 due to existing logic that assumes RFP_MaxDepth >= Razoring_MaxDepth
/// </summary>
[SPSAAttribute<int>(2, 20, 1)]
public int RFP_MaxDepth { get; set; } = 6;

[SPSAAttribute<int>(1, 300, 10)]
Expand Down Expand Up @@ -201,6 +204,15 @@ public sealed class EngineSettings
[SPSAAttribute<int>(0, 500, 25)]
public int FP_Margin { get; set; } = 250;

[SPSAAttribute<int>(1, 10, 1)]
public int Razoring2_MaxDepth { get; set; } = 4;

[SPSAAttribute<int>(1000, 5000, 500)]
public int Razoring2_AlphaMargin { get; set; } = 2000;

[SPSAAttribute<int>(50, 500, 50)]
public int Razoring2_DepthScalingFactor { get; set; } = 250;

#region Evaluation

public TaperedEvaluationTerm IsolatedPawnPenalty { get; set; } = new(-21, -17);
Expand Down
11 changes: 11 additions & 0 deletions src/Lynx/Search/NegaMax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ private int NegaMax(int depth, int ply, int alpha, int beta, bool parentWasNullM
staticEval = ttScore;
}

// Razoring implementation, according to modern standards. Based on Ciekce + JW
if (depth <= Configuration.EngineSettings.Razoring2_MaxDepth
&& Math.Abs(alpha) < 2000
&& staticEval + (Configuration.EngineSettings.Razoring2_DepthScalingFactor * depth) <= alpha)
{
var score = QuiescenceSearch(ply, alpha, alpha + 1);

if (score <= alpha)
return score;
}

if (depth <= Configuration.EngineSettings.RFP_MaxDepth)
{
// 🔍 Reverse Futility Pruning (RFP) - https://www.chessprogramming.org/Reverse_Futility_Pruning
Expand Down
24 changes: 24 additions & 0 deletions src/Lynx/UCIHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,30 @@ private void HandleSetOption(ReadOnlySpan<char> command)
}
break;
}
case "razoring2_maxdepth":
{
if (length > 4 && int.TryParse(command[commandItems[4]], out var value))
{
Configuration.EngineSettings.Razoring2_MaxDepth = value;
}
break;
}
case "razoring2_alphamargin":
{
if (length > 4 && int.TryParse(command[commandItems[4]], out var value))
{
Configuration.EngineSettings.Razoring2_AlphaMargin = value;
}
break;
}
case "razoring2_depthscalingfactor":
{
if (length > 4 && int.TryParse(command[commandItems[4]], out var value))
{
Configuration.EngineSettings.Razoring2_DepthScalingFactor = value;
}
break;
}

#endregion

Expand Down

0 comments on commit eb6b44f

Please sign in to comment.