createQuadrille(width, bitboard, value, littleEndian?)

Creates a quadrille by decoding a bitboard—passed as a JavaScript BigInt—into a rectangular quadrille. Each bit in the bitboard determines whether a corresponding cell is filled (1) or empty (0). The number of columns is set by width, and rows are inferred as needed.

The quadrille height is inferred automatically as the minimum number of rows needed to fit all bits in the bitboard, using row-major, big-endian order by default.
To explicitly define the height, use
createQuadrille(width, height, bitboard, value[, littleEndian]).

Example 1 — Big-endian (default) #

code
let quadrille;

function setup() {
  createCanvas(300, 200);
  /*
  | 5 | 4 | 3 |
  | 2 | 1 | 0 |
  (0)2⁰ + (1)2¹ + (0)2² + (1)2³ + (1)2⁴ + (1)2⁵ = 58
  */
  quadrille = createQuadrille(3, 58n, color('blue'));
}

function draw() {
  background('orange');
  drawQuadrille(quadrille);
}

This example fills a quadrille using a bitboard (58n = 0b111010) in row-major, big-endian order:

  • Most significant bit (2⁵) goes to (0,0) (top-left)
  • Least significant bit (2⁰) goes to (1,2) (bottom-right)
| 5 | 4 | 3 |
| 2 | 1 | 0 |
(0)2⁰ + (1)2¹ + (0)2² + (1)2³ + (1)2⁴ + (1)2⁵ = 58

Example 2 — Little-endian #

code
let quadrille;

function setup() {
  createCanvas(300, 200);
  /*
  | 0 | 1 | 2 |
  | 3 | 4 | 5 |
  (0)2⁰ + (1)2¹ + (0)2² + (1)2³ + (1)2⁴ + (1)2⁵ = 58
  */
  quadrille = createQuadrille(3, 58n, color('blue'), true); // littleEndian = true
}

function draw() {
  background('orange');
  drawQuadrille(quadrille);
}

This example uses the same bitboard value (58n) but reads it in row-major, little-endian order:

  • Least significant bit (2⁰) goes to (0,0) (top-left)
  • Most significant bit (2⁵) goes to (1,2) (bottom-right)
| 0 | 1 | 2 |
| 3 | 4 | 5 |
(0)2⁰ + (1)2¹ + (0)2² + (1)2³ + (1)2⁴ + (1)2⁵ = 58

This layout is often used in chess engines such as Stockfish, which represent bitboards in little-endian rank-file order.

To define different values in createQuadrille(width, bigint, value), refer to createQuadrille(jagged_array).

Syntax #

createQuadrille(width, bitboard, value[, littleEndian])

Parameters #

ParamDescription
widthNumber: The total number of columns for the quadrille
bigintBigInt (or Number): A bigint whose binary representation will determine the filled cells in the quadrille
valueAny: valid JavaScript value, with null representing empty cells
littleEndianOptional Boolean: If true, use little-endian bit ordering (default is false, i.e., big-endian)