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

Make Piece an integer #603

Merged
merged 4 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 struct GameState
{
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
Loading