Datagen #46

Merged
rektdie merged 27 commits from datagen into main 2025-04-03 03:54:14 +02:00
2 changed files with 29 additions and 11 deletions
Showing only changes of commit c80adecb6e - Show all commits

No files matched your search

+2 -6
View File
@@ -5,9 +5,7 @@
struct PackedBoard { struct PackedBoard {
uint64_t occupancy; // 8 bytes: Bitboard representing all occupied squares (includes all pieces) uint64_t occupancy; // 8 bytes: Bitboard representing all occupied squares (includes all pieces)
std::array<uint8_t, 32> pieces; // 32 bytes: 64 squares stored in 4-bit format (2 squares per byte) std::array<uint8_t, 32> pieces; // 32 bytes: 64 squares stored in 4-bit format (2 squares per byte)
uint8_t sideToMove; // 1 byte: 0 = White to move, 1 = Black to move uint8_t stmEPSquare; // 1 byte: STM (side to move) in bit 7, EP square in bits 0-5
uint8_t castlingRights; // 1 byte: 4-bit bitmask indicating available castling rights
uint8_t enPassantTarget; // 1 byte: En passant target square (0-63) or 64 if no en passant is available
uint8_t halfmoveClock; // 1 byte: Halfmove counter for the 50-move rule (incremented after each move) uint8_t halfmoveClock; // 1 byte: Halfmove counter for the 50-move rule (incremented after each move)
uint16_t fullmoveNumber; // 2 bytes: Full move counter, starting at 1 (increments after Black's move) uint16_t fullmoveNumber; // 2 bytes: Full move counter, starting at 1 (increments after Black's move)
int16_t eval; // 2 bytes: Static evaluation score (e.g., centipawns, positive = White advantage) int16_t eval; // 2 bytes: Static evaluation score (e.g., centipawns, positive = White advantage)
@@ -17,9 +15,7 @@ struct PackedBoard {
void packFrom(Board& board, int16_t eval, uint8_t wdl) { void packFrom(Board& board, int16_t eval, uint8_t wdl) {
occupancy = board.occupied; occupancy = board.occupied;
pieces = UTILS::CompressPieces(board); pieces = UTILS::CompressPieces(board);
sideToMove = board.sideToMove; uint8_t stm_ep_square = (board.sideToMove<< 7) | (board.enPassantTarget & 0x3F);
castlingRights = board.castlingRights;
enPassantTarget = (board.enPassantTarget == noEPTarget) ? 64 : board.enPassantTarget;
halfmoveClock = board.halfMoves; halfmoveClock = board.halfMoves;
fullmoveNumber = board.fullMoves; fullmoveNumber = board.fullMoves;
this->eval = eval; this->eval = eval;
+27 -5
View File
@@ -148,24 +148,45 @@ Move parseMove(Board &board, std::string_view str) {
} }
std::array<uint8_t, 32> CompressPieces(Board &board) { std::array<uint8_t, 32> CompressPieces(Board &board) {
const uint8_t UNMOVED_ROOK = 0x10; // Special value for unmoved rooks
std::array<uint8_t, 32> compressed; std::array<uint8_t, 32> compressed;
for (int square = a1; square <= h8; square++) { for (int square = a1; square <= h8; square++) {
int pieceCode = 0; int pieceCode = 0;
for (int pieceType = Pawn; pieceType <= King; pieceType++) { for (int pieceType = Pawn; pieceType <= King; pieceType++) {
if (board.pieces[pieceType].IsSet(square)) { Bitboard pieceBitboard = board.pieces[pieceType];
if (board.pieces[pieceType] & board.colors[White]) {
pieceCode = pieceType + 1; // White pieces: 1-6 if (pieceBitboard.IsSet(square)) {
if (board.colors[White] & board.pieces[pieceType]) {
pieceCode = pieceType + 1; // White pieces: 1-6
} else { } else {
pieceCode = pieceType + 7; // Black pieces: 7-12 pieceCode = pieceType + 7; // Black pieces: 7-12
}
// If it's a rook and hasn't moved (check castling rights)
if (pieceType == Rook) {
if (board.sideToMove == White) {
// If the white rooks are still eligible for castling, they haven't moved
if ((board.castlingRights & (whiteKingRight | whiteQueenRight)) != 0) {
pieceCode |= UNMOVED_ROOK; // Mark as unmoved rook
}
} else if (board.sideToMove == Black) {
// If the black rooks are still eligible for castling, they haven't moved
if ((board.castlingRights & (blackKingRight | blackQueenRight)) != 0) {
pieceCode |= UNMOVED_ROOK; // Mark as unmoved rook
}
}
} }
break; break;
} }
} }
// Determine the byte index for storing the piece code (since we are packing 2 pieces per byte)
int byteIndex = square / 2; int byteIndex = square / 2;
// Pack the piece code into the byte array
if (square % 2 == 0) { if (square % 2 == 0) {
compressed[byteIndex] = (compressed[byteIndex] & 0xF0) | (pieceCode & 0x0F); compressed[byteIndex] = (compressed[byteIndex] & 0xF0) | (pieceCode & 0x0F);
} else { } else {
@@ -175,4 +196,5 @@ std::array<uint8_t, 32> CompressPieces(Board &board) {
return compressed; return compressed;
} }
} }