Skip to content

Commit

Permalink
⚡ Replace Chebyshev distance calculation with lookup table (double ar…
Browse files Browse the repository at this point in the history
…ray) (#957)
  • Loading branch information
eduherminio authored Sep 7, 2024
1 parent cfd214f commit 309700e
Show file tree
Hide file tree
Showing 6 changed files with 416 additions and 20 deletions.
340 changes: 340 additions & 0 deletions src/Lynx.Benchmark/ChebyshevDistance_Benchmark.cs

Large diffs are not rendered by default.

71 changes: 71 additions & 0 deletions src/Lynx/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,77 @@ public static class Constants
/// 500 moves, https://www.chess.com/game/live/378106991
/// </summary>
public const string SuperLongPositionCommand = "position fen rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1 moves e2e4 e7e5 g1f3 g8f6 b1c3 b8c6 f1e2 f8b4 a2a3 b4c3 b2c3 f6e4 e2b5 d7d6 d1e2 e4f6 d2d4 e8g8 d4e5 d6e5 b5c6 b7c6 c1g5 h7h6 g5h4 f8e8 a1d1 d8e7 e1g1 c8g4 h2h3 g4f3 e2f3 e7e6 h4f6 e6f6 f3f6 g7f6 d1d7 a8c8 f1b1 e8d8 d7d3 e5e4 d3d4 d8d4 c3d4 c8d8 c2c3 d8d7 f2f3 e4e3 g1f1 f6f5 f3f4 d7e7 f1e2 h6h5 h3h4 g8g7 b1f1 e7e4 g2g3 g7f6 f1f3 f6e6 f3e3 e4e3 e2e3 e6d5 e3d3 c6c5 c3c4 d5c6 d4d5 c6d6 d3c3 c7c6 d5c6 d6c6 c3b3 c6b6 a3a4 a7a5 b3a3 f7f6 a3b3 b6c6 b3c3 c6d6 c3d3 d6c6 d3e3 c6d6 e3f3 d6e6 f3e3 e6d6 e3f3 d6e6 f3e3 e6d6 e3f2 d6e6 f2e2 e6d6 e2d3 d6e6 d3c3 e6d6 c3b3 d6e6 b3a3 e6d6 a3b3 d6e6 b3c2 e6d6 c2c3 d6e6 c3b2 e6d6 b2c2 d6e6 c2c3 e6e7 c3d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, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 6, 5, 4, 4, 4, 4, 4, 4, 6, 5, 4, 3, 3, 3, 3, 3, 6, 5, 4, 3, 2, 2, 2, 2, 6, 5, 4, 3, 2, 1, 1, 1, 6, 5, 4, 3, 2, 1, 0, 1],
[7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 7, 6, 5, 5, 5, 5, 5, 5, 7, 6, 5, 4, 4, 4, 4, 4, 7, 6, 5, 4, 3, 3, 3, 3, 7, 6, 5, 4, 3, 2, 2, 2, 7, 6, 5, 4, 3, 2, 1, 1, 7, 6, 5, 4, 3, 2, 1, 0]
];
}

#pragma warning restore IDE0055
4 changes: 2 additions & 2 deletions src/Lynx/Model/Position.cs
Original file line number Diff line number Diff line change
Expand Up @@ -911,9 +911,9 @@ private int PawnAdditionalEvaluation(int bucket, int squareIndex, int pieceIndex
rank = 7 - rank;
}

var friendlyKingDistance = Utils.ChebyshevDistance(sameSideKingSquare, squareIndex);
var friendlyKingDistance = Constants.ChebyshevDistance[squareIndex][sameSideKingSquare];

var enemyKingDistance = Utils.ChebyshevDistance(oppositeSideKingSquare, squareIndex);
var enemyKingDistance = Constants.ChebyshevDistance[squareIndex][oppositeSideKingSquare];

packedBonus += PassedPawnBonus[bucket][rank]
+ FriendlyKingDistanceToPassedPawnBonus[friendlyKingDistance]
Expand Down
15 changes: 0 additions & 15 deletions src/Lynx/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,21 +214,6 @@ public static short UnpackEG(int packed)
return (short)((packed + 0x8000) >> 16);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int ChebyshevDistance(BoardSquare square1, BoardSquare square2) =>
ChebyshevDistance((int)square1, (int)square2);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int ChebyshevDistance(int square1, int square2)
{
var xDelta = Math.Abs(Constants.File[square1] - Constants.File[square2]);
var yDelta = Math.Abs(Constants.Rank[square1] - Constants.Rank[square2]);

return xDelta >= yDelta
? xDelta
: yDelta;
}

[Conditional("DEBUG")]
private static void GuardAgainstSideBoth(int side)
{
Expand Down
Loading

0 comments on commit 309700e

Please sign in to comment.