On the topic of Quadboards vs Triboards (Nibbleboard)

Discussion of chess software programming and technical issues.

Moderator: Ras

dangi12012
Posts: 1062
Joined: Tue Apr 28, 2020 10:03 pm
Full name: Daniel Infuehr

On the topic of Quadboards vs Triboards (Nibbleboard)

Post by dangi12012 »

If you define a quadboard with a "vertical nibble" this way:

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
}
So the canonical way of all 12 pieces + empty + special flag indicating enpassant pawn or a castling rook. And a special white king that tells us that white is moving - gives a board of 4x64 bit.

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 pieces

In 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);
}
My question now is - has someone experimented (and knows the name) for this 3x 64 bit sceme?
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.
Worlds-fastest-Bitboard-Chess-Movegenerator
Daniel Inführ - Software Developer