Skip to content

Commit

Permalink
🐛 Clamp static evaluation within +- checkmate limits (#510)
Browse files Browse the repository at this point in the history
* Clamp static eval
This avoids engine misbehavior for positions such as:
`QQQQQQQQ/QQQQQQQQ/QQQQQQQQ/QQQQQQQQ/QQQQQQQQ/QQQQQQQQ/QPPPPPPP/K6k b - - 0 1` from https://lichess.org/49dBqSDK
  • Loading branch information
eduherminio authored Nov 20, 2023
1 parent f4afe2c commit bcacef3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Lynx/EvaluationConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,10 @@ static EvaluationConstants()
/// </summary>
public const int NegativeCheckmateDetectionLimit = -27_000; // -CheckMateBaseEvaluation + (Constants.AbsoluteMaxDepth + 45) * DepthCheckmateFactor;

public const int MinEval = NegativeCheckmateDetectionLimit + 1;

public const int MaxEval = PositiveCheckmateDetectionLimit - 1;

public const int PVMoveScoreValue = 4_194_304;

public const int TTMoveScoreValue = 2_097_152;
Expand Down
2 changes: 2 additions & 0 deletions src/Lynx/Model/Position.cs
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,8 @@ public string FEN(int halfMovesWithoutCaptureOrPawnMove = 0, int fullMoveClock =

var eval = ((middleGameScore * gamePhase) + (endGameScore * endGamePhase)) / maxPhase;

eval = Math.Clamp(eval, EvaluationConstants.MinEval, EvaluationConstants.MaxEval);

var sideEval = Side == Side.White
? eval
: -eval;
Expand Down

0 comments on commit bcacef3

Please sign in to comment.