Skip to content

Commit d1aa0f4

Browse files
committed
Added input buckets, released v 1.1.2
1 parent b67533d commit d1aa0f4

File tree

9 files changed

+137
-85
lines changed

9 files changed

+137
-85
lines changed

.github/workflows/release-pipeline.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
working-directory: Sapling
2626
id: get_version
2727
run: |
28-
VERSION=1.1.1
28+
VERSION=1.1.2
2929
echo "Application version: $VERSION"
3030
echo "::set-output name=version::$VERSION"
3131

Sapling.Engine/BoardState.cs

+12-11
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace Sapling.Engine;
44

55
using System.Runtime.InteropServices;
66

7-
[StructLayout(LayoutKind.Explicit, Size = 142)] // Explicit layout with size control
7+
[StructLayout(LayoutKind.Explicit, Size = 144)] // Explicit layout with size control
88
public unsafe struct BoardStateData
99
{
1010
// 8-byte fields (grouped together for optimal alignment)
@@ -18,22 +18,23 @@ public unsafe struct BoardStateData
1818
// Grouped bools (using 1 byte each)
1919
[FieldOffset(131)] public bool WhiteToMove; // 1 byte
2020
[FieldOffset(132)] public bool InCheck; // 1 byte
21-
[FieldOffset(133)] public bool ShouldWhiteMirrored; // 1 byte
22-
[FieldOffset(134)] public bool ShouldBlackMirrored; // 1 byte
23-
[FieldOffset(135)] public bool WhiteMirrored; // 1 byte
24-
[FieldOffset(136)] public bool BlackMirrored; // 1 byte
21+
[FieldOffset(133)] public bool WhiteMirrored; // 1 byte
22+
[FieldOffset(134)] public bool BlackMirrored; // 1 byte
2523

2624
// 4-byte field (for proper alignment)
2725

2826
// CastleRights (assuming this is a byte-sized enum)
29-
[FieldOffset(137)] public CastleRights CastleRights; // 1 byte
27+
[FieldOffset(135)] public CastleRights CastleRights; // 1 byte
3028

3129
// Smaller fields (grouped together for minimal padding)
32-
[FieldOffset(138)] public byte WhiteKingSquare; // 1 byte
33-
[FieldOffset(139)] public byte BlackKingSquare; // 1 byte
34-
[FieldOffset(140)] public byte EnPassantFile; // 1 byte
35-
[FieldOffset(141)] public byte PieceCount; // 1 byte
36-
30+
[FieldOffset(136)] public byte WhiteKingSquare; // 1 byte
31+
[FieldOffset(137)] public byte BlackKingSquare; // 1 byte
32+
[FieldOffset(138)] public byte EnPassantFile; // 1 byte
33+
[FieldOffset(139)] public byte PieceCount; // 1 byte
34+
[FieldOffset(140)] public byte WhiteInputBucket; // 1 byte
35+
[FieldOffset(141)] public byte BlackInputBucket; // 1 byte
36+
[FieldOffset(142)] public bool WhiteNeedsRefresh; // 1 byte
37+
[FieldOffset(143)] public bool BlackNeedsRefresh; // 1 byte
3738
public void CloneTo(ref BoardStateData copy)
3839
{
3940
fixed (BoardStateData* sourcePtr = &this)

Sapling.Engine/BoardStateExtensions.cs

+11-21
Original file line numberDiff line numberDiff line change
@@ -376,24 +376,6 @@ public static void UpdateCastleStatus(this ref BoardStateData board, CastleRight
376376
board.Hash ^= Zobrist.BlackQueenSideCastlingRights;
377377
}
378378
}
379-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
380-
public static void UpdateMirrorStatus(this ref BoardStateData board,byte piece, bool fromMirroredSide, bool toMirroredSide)
381-
{
382-
if (fromMirroredSide == toMirroredSide)
383-
{
384-
return;
385-
}
386-
387-
if (piece == Constants.WhiteKing)
388-
{
389-
board.ShouldWhiteMirrored = toMirroredSide;
390-
}
391-
392-
if (piece == Constants.BlackKing)
393-
{
394-
board.ShouldBlackMirrored = toMirroredSide;
395-
}
396-
}
397379

398380
[MethodImpl(MethodImplOptions.AggressiveInlining)]
399381
public static unsafe void FinishApply(this ref BoardStateData board, VectorShort* whiteAcc, VectorShort* blackAcc, ulong* hashHistory, uint m,
@@ -404,6 +386,15 @@ public static unsafe void FinishApply(this ref BoardStateData board, VectorShort
404386

405387
var (movedPiece, fromSquare, toSquare, capturedPiece, moveType) = m.Deconstruct();
406388

389+
if (movedPiece == Constants.WhiteKing)
390+
{
391+
board.WhiteNeedsRefresh |= board.WhiteMirrored != toSquare.IsMirroredSide() || board.WhiteInputBucket != NnueEvaluator.GetKingBucket(toSquare);
392+
}
393+
else if (movedPiece == Constants.BlackKing)
394+
{
395+
board.BlackNeedsRefresh |= board.BlackMirrored != toSquare.IsMirroredSide() || board.BlackInputBucket != NnueEvaluator.GetKingBucket((byte)(toSquare ^ 0x38));
396+
}
397+
407398
if (moveType == 0)
408399
{
409400
board.Replace(whiteAcc, blackAcc, movedPiece, fromSquare, toSquare);
@@ -427,8 +418,8 @@ public static unsafe void FinishApply(this ref BoardStateData board, VectorShort
427418
// Castle move
428419
if (toSquare == 62)
429420
{
430-
board.Replace(whiteAcc, blackAcc, Constants.BlackRook, 63, 61);
431-
board.Replace(whiteAcc, blackAcc, Constants.BlackKing, fromSquare, toSquare);
421+
board.Replace( whiteAcc, blackAcc, Constants.BlackRook, 63, 61);
422+
board.Replace( whiteAcc, blackAcc, Constants.BlackKing, fromSquare, toSquare);
432423
board.Hash ^= Zobrist.PiecesArray[Constants.BlackKing * 64 + fromSquare] ^
433424
Zobrist.PiecesArray[Constants.BlackKing * 64 + toSquare] ^
434425
Zobrist.PiecesArray[Constants.BlackRook * 64 + 63] ^
@@ -514,7 +505,6 @@ public static unsafe void FinishApply(this ref BoardStateData board, VectorShort
514505
}
515506

516507
board.UpdateCastleStatus(prevCastle);
517-
board.UpdateMirrorStatus(movedPiece, fromSquare.IsMirroredSide(), toSquare.IsMirroredSide());
518508

519509
hashHistory[board.TurnCount - 1] = board.Hash;
520510
}

0 commit comments

Comments
 (0)