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

🐛 Prevent negative checkmate scores from being lower than EvaluationConstants.MinEval #1063

Merged
merged 3 commits into from
Sep 27, 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
30 changes: 15 additions & 15 deletions src/Lynx/EvaluationConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,17 @@ static EvaluationConstants()
/// <summary>
/// Base absolute checkmate evaluation value. Actual absolute evaluations are lower than this one by a number of <see cref="Position.DepthCheckmateFactor"/>
/// </summary>
public const int CheckMateBaseEvaluation = 30_000;
public const int CheckMateBaseEvaluation = 29_000;

/// <summary>
/// Max eval, including checkmate values
/// </summary>
public const int MaxEval = CheckMateBaseEvaluation + 1;
public const int MaxEval = 32_000; // CheckMateBaseEvaluation + (Constants.AbsoluteMaxDepth + 45) * DepthCheckmateFactor;

/// <summary>
/// Min eval, including checkmate values
/// </summary>
public const int MinEval = -CheckMateBaseEvaluation - 1;
public const int MinEval = -32_000; // -CheckMateBaseEvaluation - (Constants.AbsoluteMaxDepth + 45) * DepthCheckmateFactor;

/// <summary>
/// This value combined with <see cref="PositiveCheckmateDetectionLimit"/> and <see cref="NegativeCheckmateDetectionLimit"/> should allows mates up to in <see cref="Constants.AbsoluteMaxDepth"/> moves.
Expand All @@ -109,12 +109,12 @@ static EvaluationConstants()
/// <summary>
/// Minimum evaluation for a position to be White checkmate
/// </summary>
public const int PositiveCheckmateDetectionLimit = 27_000; // CheckMateBaseEvaluation - (Constants.AbsoluteMaxDepth + 45) * DepthCheckmateFactor;
public const int PositiveCheckmateDetectionLimit = 26_000; // CheckMateBaseEvaluation - (Constants.AbsoluteMaxDepth + 45) * DepthCheckmateFactor;

/// <summary>
/// Minimum evaluation for a position to be Black checkmate
/// </summary>
public const int NegativeCheckmateDetectionLimit = -27_000; // -CheckMateBaseEvaluation + (Constants.AbsoluteMaxDepth + 45) * DepthCheckmateFactor;
public const int NegativeCheckmateDetectionLimit = -26_000; // -CheckMateBaseEvaluation + (Constants.AbsoluteMaxDepth + 45) * DepthCheckmateFactor;

/// <summary>
/// Max static eval. It doesn't include checkmate values and it's below <see cref="PositiveCheckmateDetectionLimit"/>
Expand All @@ -126,6 +126,16 @@ static EvaluationConstants()
/// </summary>
public const int MinStaticEval = NegativeCheckmateDetectionLimit + 1;

/// <summary>
/// Outside of the evaluation ranges (higher than any sensible evaluation, lower than <see cref="PositiveCheckmateDetectionLimit"/>)
/// </summary>
public const int NoHashEntry = 25_000;

/// <summary>
/// Evaluation to be returned when there's one single legal move
/// </summary>
public const int SingleMoveScore = 200;

#region Move ordering

public const int TTMoveScoreValue = 2_097_152;
Expand Down Expand Up @@ -156,16 +166,6 @@ static EvaluationConstants()

#endregion

/// <summary>
/// Outside of the evaluation ranges (higher than any sensible evaluation, lower than <see cref="PositiveCheckmateDetectionLimit"/>)
/// </summary>
public const int NoHashEntry = 25_000;

/// <summary>
/// Evaluation to be returned when there's one single legal move
/// </summary>
public const int SingleMoveScore = 200;

public const int ContinuationHistoryPlyCount = 1;
}

Expand Down
2 changes: 2 additions & 0 deletions tests/Lynx.Test/EvaluationConstantsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ public void NegativeCheckmateDetectionLimitTest()
public void MaxEvalTest()
{
Assert.Greater(MaxEval, PositiveCheckmateDetectionLimit + ((Constants.AbsoluteMaxDepth + 10) * CheckmateDepthFactor));
Assert.Less(MaxEval, short.MaxValue);
}

[Test]
public void MinEvalTest()
{
Assert.Less(MinEval, NegativeCheckmateDetectionLimit - ((Constants.AbsoluteMaxDepth + 10) * CheckmateDepthFactor));
Assert.Greater(MinEval, short.MinValue);
}

[Test]
Expand Down
Loading