Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔍 NMP, tweak reduction using eval - beta #1139

Merged
merged 2 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -170,14 +171,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
Loading