Skip to content

Commit

Permalink
Merge branch 'main' into search/improving-rfp-5
Browse files Browse the repository at this point in the history
  • Loading branch information
eduherminio authored Nov 9, 2024
2 parents 1ca8f08 + b4f658e commit a68c159
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/Lynx/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ public int TranspositionTableSize
[SPSA<int>(1, 10, 0.5)]
public int NMP_DepthDivisor { get; set; } = 3;

[SPSA<int>(150, 350, 10)]
public int NMP_StaticEvalBetaDivisor { get; set; } = 100;

[SPSA<int>(1, 10, 0.5)]
public int NMP_StaticEvalBetaMaxReduction { get; set; } = 3;

[SPSA<int>(5, 30, 1)]
public int AspirationWindow_Base { get; set; } = 13;

Expand Down
11 changes: 9 additions & 2 deletions src/Lynx/Search/NegaMax.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Lynx.Model;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Security.Authentication;

namespace Lynx;

Expand Down Expand Up @@ -181,14 +182,20 @@ private int NegaMax(int depth, int ply, int alpha, int beta, bool parentWasNullM
}
}

var staticEvalBetaDiff = staticEval - beta;

// 🔍 Null Move Pruning (NMP) - our position is so good that we can potentially afford giving our opponent a double move and still remain ahead of beta
if (depth >= Configuration.EngineSettings.NMP_MinDepth
&& staticEval >= beta
&& staticEvalBetaDiff >= 0
&& !parentWasNullMove
&& phase > 2 // Zugzwang risk reduction: pieces other than pawn presents
&& (ttElementType != NodeType.Alpha || ttScore >= beta)) // TT suggests NMP will fail: entry must not be a fail-low entry with a score below beta - Stormphrax and Ethereal
{
var nmpReduction = Configuration.EngineSettings.NMP_BaseDepthReduction + ((depth + Configuration.EngineSettings.NMP_DepthIncrement) / Configuration.EngineSettings.NMP_DepthDivisor); // Clarity
var nmpReduction = Configuration.EngineSettings.NMP_BaseDepthReduction
+ ((depth + Configuration.EngineSettings.NMP_DepthIncrement) / Configuration.EngineSettings.NMP_DepthDivisor) // Clarity
+ Math.Min(
Configuration.EngineSettings.NMP_StaticEvalBetaMaxReduction,
staticEvalBetaDiff / Configuration.EngineSettings.NMP_StaticEvalBetaDivisor);

// TODO more advanced adaptative reduction, similar to what Ethereal and Stormphrax are doing
//var nmpReduction = Math.Min(
Expand Down
16 changes: 16 additions & 0 deletions src/Lynx/UCIHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,22 @@ private void HandleSetOption(ReadOnlySpan<char> command)
}
break;
}
case "nmp_staticevalbetadivisor":
{
if (length > 4 && int.TryParse(command[commandItems[4]], out var value))
{
Configuration.EngineSettings.NMP_StaticEvalBetaDivisor = value;
}
break;
}
case "nmp_staticevalbetamaxreduction":
{
if (length > 4 && int.TryParse(command[commandItems[4]], out var value))
{
Configuration.EngineSettings.NMP_StaticEvalBetaMaxReduction = value;
}
break;
}

//case "aspirationwindow_delta":
// {
Expand Down

0 comments on commit a68c159

Please sign in to comment.