Skip to content

Commit

Permalink
GameState compression: make Piece (and therefore `GameState.Capture…
Browse files Browse the repository at this point in the history
…dPiece`) a sbyte enum
  • Loading branch information
eduherminio committed Aug 9, 2023
1 parent 5fc56e7 commit 5bcbeae
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/Lynx.Benchmark/MakeMove.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,12 @@ namespace Lynx.Benchmark;
public class MakeMove : BaseBenchmark
{
public static IEnumerable<(string, int)> Data => new[] {
//(Constants.InitialPositionFEN, 4),
//(Constants.TrickyTestPositionFEN, 4),
//("r4rk1/1pp1qppp/p1np1n2/2b1p1B1/2B1P1b1/P1NP1N2/1PP1QPPP/R4RK1 w - - 0 10", 4),
(Constants.InitialPositionFEN, 4),
(Constants.TrickyTestPositionFEN, 4),
("r4rk1/1pp1qppp/p1np1n2/2b1p1B1/2B1P1b1/P1NP1N2/1PP1QPPP/R4RK1 w - - 0 10", 4),
("3K4/8/8/8/8/8/4p3/2k2R2 b - - 0 1", 6),
//("2K2r2/4P3/8/8/8/8/8/3k4 w - - 0 1", 6),
//("8/p7/8/1P6/K1k3p1/6P1/7P/8 w - -", 6),
("2K2r2/4P3/8/8/8/8/8/3k4 w - - 0 1", 6),
("8/p7/8/1P6/K1k3p1/6P1/7P/8 w - -", 6)
};

[Benchmark(Baseline = true)]
Expand Down
4 changes: 2 additions & 2 deletions src/Lynx/Model/GameState.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
namespace Lynx.Model;
public readonly struct GameState
{
public readonly int CapturedPiece;
public readonly sbyte CapturedPiece;

public readonly byte Castle;

public readonly BoardSquare EnPassant;

// TODO: save full Zobrist key?

public GameState(int capturedPiece, byte castle, BoardSquare enpassant)
public GameState(sbyte capturedPiece, byte castle, BoardSquare enpassant)
{
CapturedPiece = capturedPiece;
Castle = castle;
Expand Down
2 changes: 1 addition & 1 deletion src/Lynx/Model/Piece.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Lynx.Model;

public enum Piece
public enum Piece : sbyte
{
Unknown = -1,
P, N, B, R, Q, K, // White
Expand Down
6 changes: 3 additions & 3 deletions src/Lynx/Model/Position.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public Position(Position position, Move move) : this(position)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public GameState MakeMove(Move move)
{
int capturedPiece = -1;
sbyte capturedPiece = -1;
byte castleCopy = Castle;
BoardSquare enpassantCopy = EnPassant;

Expand Down Expand Up @@ -255,7 +255,7 @@ public GameState MakeMove(Move move)
PieceBitBoards[oppositePawnIndex].PopBit(capturedPawnSquare);
OccupancyBitBoards[oppositeSide].PopBit(capturedPawnSquare);
UniqueIdentifier ^= ZobristTable.PieceHash(capturedPawnSquare, oppositePawnIndex);
capturedPiece = oppositePawnIndex;
capturedPiece = (sbyte)oppositePawnIndex;
}
else
{
Expand All @@ -266,7 +266,7 @@ public GameState MakeMove(Move move)
{
PieceBitBoards[pieceIndex].PopBit(targetSquare);
UniqueIdentifier ^= ZobristTable.PieceHash(targetSquare, pieceIndex);
capturedPiece = pieceIndex;
capturedPiece = (sbyte)pieceIndex;
break;
}
}
Expand Down

0 comments on commit 5bcbeae

Please sign in to comment.