Skip to content

Commit

Permalink
Make Piece an integer (#603)
Browse files Browse the repository at this point in the history
  • Loading branch information
eduherminio committed Jan 12, 2024
1 parent 82c6b91 commit 87a65d3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions src/Lynx/Model/GameState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
{
public readonly long ZobristKey;

public readonly byte Castle;

public readonly sbyte CapturedPiece;
public readonly int CapturedPiece;

public readonly BoardSquare EnPassant;

public GameState(long zobristKey, sbyte capturedPiece, byte castle, BoardSquare enpassant)
public readonly byte Castle;

public GameState(long zobristKey, int capturedPiece, BoardSquare enpassant, byte castle)
{
ZobristKey = zobristKey;
CapturedPiece = capturedPiece;
Castle = castle;
EnPassant = enpassant;
ZobristKey = zobristKey;
Castle = castle;
}
}
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 : sbyte
public enum Piece
{
Unknown = -1,
P, N, B, R, Q, K, // White
Expand Down
10 changes: 5 additions & 5 deletions src/Lynx/Model/Position.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public Position(Position position, Move move) : this(position)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public GameState MakeMove(Move move)
{
sbyte capturedPiece = -1;
int capturedPiece = -1;
byte castleCopy = Castle;
BoardSquare enpassantCopy = EnPassant;
long uniqueIdentifierCopy = UniqueIdentifier;
Expand Down Expand Up @@ -268,7 +268,7 @@ public GameState MakeMove(Move move)
PieceBitBoards[oppositePawnIndex].PopBit(capturedPawnSquare);
OccupancyBitBoards[oppositeSide].PopBit(capturedPawnSquare);
UniqueIdentifier ^= ZobristTable.PieceHash(capturedPawnSquare, oppositePawnIndex);
capturedPiece = (sbyte)oppositePawnIndex;
capturedPiece = oppositePawnIndex;
}
else
{
Expand All @@ -279,7 +279,7 @@ public GameState MakeMove(Move move)
{
PieceBitBoards[pieceIndex].PopBit(targetSquare);
UniqueIdentifier ^= ZobristTable.PieceHash(targetSquare, pieceIndex);
capturedPiece = (sbyte)pieceIndex;
capturedPiece = pieceIndex;
break;
}
}
Expand Down Expand Up @@ -338,7 +338,7 @@ public GameState MakeMove(Move move)

UniqueIdentifier ^= ZobristTable.CastleHash(Castle);

return new GameState(uniqueIdentifierCopy, capturedPiece, castleCopy, enpassantCopy);
return new GameState(uniqueIdentifierCopy, capturedPiece, enpassantCopy, castleCopy);
//var clone = new Position(this);
//clone.UnmakeMove(move, gameState);
//if (uniqueIdentifierCopy != clone.UniqueIdentifier)
Expand Down Expand Up @@ -436,7 +436,7 @@ public GameState MakeNullMove()
ZobristTable.SideHash()
^ ZobristTable.EnPassantHash((int)oldEnPassant);

return new GameState(oldUniqueIdentifier, -1, byte.MaxValue, oldEnPassant);
return new GameState(oldUniqueIdentifier, -1, oldEnPassant, byte.MaxValue);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down

0 comments on commit 87a65d3

Please sign in to comment.