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

⚡ Use FrozenDictionarys where possible #403

Merged
merged 1 commit into from
Sep 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/Lynx/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Lynx.Model;
using System.Collections.Frozen;

namespace Lynx;

Expand Down Expand Up @@ -100,7 +101,7 @@ public static class Constants
/// <summary>
/// Covert ASCII character pieces to encoded constants
/// </summary>
public static readonly IReadOnlyDictionary<char, Piece> PiecesByChar = new Dictionary<char, Piece>(12)
public static readonly FrozenDictionary<char, Piece> PiecesByChar = new Dictionary<char, Piece>(12)
{
['P'] = Piece.P,
['N'] = Piece.N,
Expand All @@ -115,7 +116,7 @@ public static class Constants
['r'] = Piece.r,
['q'] = Piece.q,
['k'] = Piece.k,
};
}.ToFrozenDictionary();

/// <summary>
/// Relevant bishop occupancy bit count per square
Expand Down Expand Up @@ -322,7 +323,7 @@ public static class Constants
public const string WhiteLongCastle = "e1c1";
public const string BlackLongCastle = "e8c8";

public static readonly IReadOnlyDictionary<int, int> EnPassantCaptureSquares = new Dictionary<int, int>(16)
public static readonly FrozenDictionary<int, int> EnPassantCaptureSquares = new Dictionary<int, int>(16)
{
[(int)BoardSquare.a6] = (int)BoardSquare.a6 + 8,
[(int)BoardSquare.b6] = (int)BoardSquare.b6 + 8,
Expand All @@ -341,7 +342,7 @@ public static class Constants
[(int)BoardSquare.f3] = (int)BoardSquare.f3 - 8,
[(int)BoardSquare.g3] = (int)BoardSquare.g3 - 8,
[(int)BoardSquare.h3] = (int)BoardSquare.h3 - 8,
};
}.ToFrozenDictionary();

/// <summary>
/// https://github.com/maksimKorzh/chess_programming/blob/master/src/bbc/make_move_castling_rights/bbc.c#L1474
Expand Down