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

🔍 Prune bad captures in QSearch using SEE #558

Merged
merged 1 commit into from
Dec 31, 2023
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
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
Loading