introduced marlinformat and compress pieces function in utils
This commit is contained in:
1 parent
f05ba64487
commit
14395cbb9f
3 files changed
+61
No files matched your search
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
#include "board.h"
|
||||
#include "utils.h"
|
||||
|
||||
struct PackedBoard {
|
||||
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)
|
||||
uint8_t sideToMove; // 1 byte: 0 = White to move, 1 = Black to move
|
||||
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)
|
||||
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)
|
||||
uint8_t wdl; // 1 byte: Win-Draw-Loss classification (for training or result storage)
|
||||
uint8_t extra; // 1 byte: Reserved for future use or additional data
|
||||
|
||||
void packFrom(Board& board, int16_t eval, uint8_t wdl) {
|
||||
occupancy = board.occupied;
|
||||
pieces = UTILS::CompressPieces(board);
|
||||
sideToMove = board.sideToMove;
|
||||
castlingRights = board.castlingRights;
|
||||
enPassantTarget = (board.enPassantTarget == noEPTarget) ? 64 : board.enPassantTarget;
|
||||
halfmoveClock = board.halfMoves;
|
||||
fullmoveNumber = board.fullMoves;
|
||||
this->eval = eval;
|
||||
this->wdl = wdl;
|
||||
extra = 0;
|
||||
}
|
||||
};
|
||||
@@ -146,4 +146,33 @@ Move parseMove(Board &board, std::string_view str) {
|
||||
|
||||
return Move(from, to, flag);
|
||||
}
|
||||
|
||||
std::array<uint8_t, 32> CompressPieces(Board &board) {
|
||||
std::array<uint8_t, 32> compressed;
|
||||
|
||||
for (int square = a1; square <= h8; square++) {
|
||||
int pieceCode = 0;
|
||||
|
||||
for (int pieceType = Pawn; pieceType <= King; pieceType++) {
|
||||
if (board.pieces[pieceType].IsSet(square)) {
|
||||
if (board.pieces[pieceType] & board.colors[White]) {
|
||||
pieceCode = pieceType + 1; // White pieces: 1-6
|
||||
} else {
|
||||
pieceCode = pieceType + 7; // Black pieces: 7-12
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int byteIndex = square / 2;
|
||||
|
||||
if (square % 2 == 0) {
|
||||
compressed[byteIndex] = (compressed[byteIndex] & 0xF0) | (pieceCode & 0x0F);
|
||||
} else {
|
||||
compressed[byteIndex] = (compressed[byteIndex] & 0x0F) | ((pieceCode & 0x0F) << 4);
|
||||
}
|
||||
}
|
||||
|
||||
return compressed;
|
||||
}
|
||||
}
|
||||
@@ -29,4 +29,7 @@ std::vector<std::string> split(std::string_view str, char delim);
|
||||
int parseSquare(std::string_view str);
|
||||
|
||||
Move parseMove(Board &board, std::string_view str);
|
||||
|
||||
std::array<uint8_t, 32> CompressPieces(Board &board);
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user