Code: Select all
enum PieceIdx
{
Empty = 0b0000,
BP = 0b0001,
BR = 0b0010,
BPR_S = 0b0011,
BB = 0b0100,
BN = 0b0101,
BQ = 0b0110,
BK = 0b0111,
WK_White = 0b1000,
WP = 0b1001,
WR = 0b1010,
WPR_S = 0b1011,
WB = 0b1100,
WN = 0b1101,
WQ = 0b1110,
WK = 0b1111
}But for all legal chess games all 32*4 nibbles fit into 2 registers and together with a third occupy register - a bitboard can be represented via this representation:
Code: Select all
public ulong Occupied;
public ulong A; //16 * 4 bit = First 16 pieces
public ulong B; //16 * 4 bit = Second 16 piecesIn C# this can be unpacked into a quadboard like this:
Code: Select all
public QuadBoard Unpack()
{
ulong P0 = PBI.ParallelBitDeposit((PBI.ParallelBitExtract(B, BoardConstant.b0) << 16) | PBI.ParallelBitExtract(A, BoardConstant.b0), Occupied);
ulong P1 = PBI.ParallelBitDeposit((PBI.ParallelBitExtract(B, BoardConstant.b1) << 16) | PBI.ParallelBitExtract(A, BoardConstant.b1), Occupied);
ulong P2 = PBI.ParallelBitDeposit((PBI.ParallelBitExtract(B, BoardConstant.b2) << 16) | PBI.ParallelBitExtract(A, BoardConstant.b2), Occupied);
ulong P3 = PBI.ParallelBitDeposit((PBI.ParallelBitExtract(B, BoardConstant.b3) << 16) | PBI.ParallelBitExtract(A, BoardConstant.b3), Occupied);
return new QuadBoard(P0, P1, P2, P3);
}Also is there a more compact board representation actually used in an engine? Some sort of compressed binary tree would be interesting to see in action.