Skip to content

Commit

Permalink
Prune bad captures in QSearch
Browse files Browse the repository at this point in the history
  • Loading branch information
eduherminio committed Dec 31, 2023
1 parent 514d63d commit 4e85650
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Lynx/EvaluationConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ static EvaluationConstants()

public const int ThirdKillerMoveValue = 131_072;

// Revisit bad capture pruning in NegaMax.cs if order changes and promos aren't the lowest before bad captures
public const int PromotionMoveScoreValue = 65_536;

public const int BadCaptureMoveBaseScoreValue = 32_768;
Expand Down
7 changes: 7 additions & 0 deletions src/Lynx/Search/NegaMax.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Lynx.Model;
using System.Transactions;

namespace Lynx;

Expand Down Expand Up @@ -452,6 +453,12 @@ public int QuiescenceSearch(int ply, int alpha, int beta)

var move = pseudoLegalMoves[i];

// Prune bad captures
if (scores[i] < EvaluationConstants.PromotionMoveScoreValue && scores[i] >= EvaluationConstants.BadCaptureMoveBaseScoreValue)
{
continue;
}

var gameState = position.MakeMove(move);
if (!position.WasProduceByAValidMove())
{
Expand Down
19 changes: 19 additions & 0 deletions tests/Lynx.Test/EvaluationConstantsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,25 @@ public void ThirdKillerMoveValueConstant()
Assert.Greater(ThirdKillerMoveValue, default);
}

[Test]
public void PromotionMoveValueConstant()
{
var maxMVVLVAMoveValue = int.MinValue;

for (int s = (int)Piece.P; s <= (int)Piece.r; ++s)
{
for (int t = (int)Piece.P; t <= (int)Piece.r; ++t)
{
if (MostValueableVictimLeastValuableAttacker[s, t] > maxMVVLVAMoveValue)
{
maxMVVLVAMoveValue = MostValueableVictimLeastValuableAttacker[s, t];
}
}
}

Assert.Less(BadCaptureMoveBaseScoreValue + maxMVVLVAMoveValue, PromotionMoveScoreValue);
}

/// <summary>
/// Avoids drawish evals that can lead the GUI to declare a draw
/// or negative ones that can lead it to resign
Expand Down

0 comments on commit 4e85650

Please sign in to comment.