Skip to content

Commit

Permalink
Added NMP verification search (#105)
Browse files Browse the repository at this point in the history
bench: 4562425
  • Loading branch information
liamt19 authored Dec 2, 2024
1 parent 675a0a2 commit 5cfcc4f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
20 changes: 15 additions & 5 deletions Logic/Search/Searches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,11 @@ public static int Negamax<NodeType>(Position pos, SearchStackEntry* ss, int alph

if (UseNMP
&& !isPV
&& !doSkip
&& depth >= NMPMinDepth
&& ss->Ply >= thisThread.NMPPly
&& eval >= beta
&& eval >= ss->StaticEval
&& !doSkip
&& (ss - 1)->CurrentMove != Move.Null
&& pos.HasNonPawnMaterial(pos.ToMove))
{
Expand All @@ -230,15 +231,24 @@ public static int Negamax<NodeType>(Position pos, SearchStackEntry* ss, int alph
// Skip our turn, and see if the our opponent is still behind even with a free move.
pos.MakeNullMove();
prefetch(TT.GetCluster(pos.State->Hash));

score = -Negamax<NonPVNode>(pos, ss + 1, -beta, -beta + 1, depth - reduction, !cutNode);

pos.UnmakeNullMove();

if (score >= beta)
{
// Null moves are not allowed to return mate or TT win scores, so ensure the score is below that.
return score < ScoreTTWin ? score : beta;
if (thisThread.NMPPly > 0 || depth <= 15)
{
return score > ScoreWin ? beta : score;
}

thisThread.NMPPly = (3 * (depth - reduction) / 4) + ss->Ply;
int verification = Negamax<NonPVNode>(pos, ss, beta - 1, beta, depth - reduction, false);
thisThread.NMPPly = 0;

if (verification >= beta)
{
return score;
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions Logic/Threads/SearchThread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public unsafe class SearchThread : IDisposable
/// </summary>
public int CompletedDepth;

public int NMPPly;

/// <summary>
/// When this number reaches <see cref="CheckupMax"/>, the main thread will check to see if the search
/// needs to stop because of max time or max node constraints.
Expand Down
1 change: 1 addition & 0 deletions Logic/Threads/SearchThreadPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public void StartSearch(Position rootPosition, ref SearchInformation rootInfo, T
td.CompletedDepth = 0;
td.RootDepth = 0;
td.SelDepth = 0;
td.NMPPly = 0;

// Each thread gets its own copy of each of the root position's "RootMoves" since the thread will be sorting these
// and doing that simultaneously would cause data races
Expand Down
2 changes: 1 addition & 1 deletion Logic/Util/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Lizard.Logic.Util
public static class Utilities
{

public const string EngineBuildVersion = "11.1.3";
public const string EngineBuildVersion = "11.1.4";

public const int NormalListCapacity = 128;
public const int MoveListSize = 256;
Expand Down

0 comments on commit 5cfcc4f

Please sign in to comment.