positionFromTranspositionId

Reconstructs a Position instance from a dynamically sized, compressed ByteArray generated by the Position.transpositionId extension function.

This function reverses the lossless sparse array encoding by performing the following steps:

  1. Extracts the 64-bit occupancy bitboard from the first 8 bytes.

  2. Calculates the expected array length based on the active piece count and validates data.

  3. Unpacks the piece types (stored as 4-bit nibbles) sequentially to rebuild the 12 distinct piece bitboards.

  4. Restores the side to move, castling rights, en passant target square, and half-move clock from the trailing metadata bytes.

Because the full-move counter is intentionally omitted from the transposition identifier (as it does not affect position equivalency for repetition purposes), it must be provided separately to fully restore the position's true state (e.g., for accurate FEN string generation).

Return

A fully reconstructed Position object (either WhitePosition or BlackPosition).

Since

1.0.0-beta.13

Author

lunalobos

Parameters

movesCounter

The full-move number to assign to the reconstructed position.

data

The compressed byte array containing the serialized position data.

Throws

if the size of data does not strictly match the expected size derived from the decoded occupancy bitboard.