Utility Functions and Bitboard Helpers

Neighbour Enumeration

getNeighbors(const BoardCoord& pos)Function

Parameters: pos – a board coordinate

Returns: std::vector<BoardCoord> – up to 8 valid neighbouring squares

Returns all 8-connected neighbours of pos that lie within the board boundary. Used by both the BFS parking-spot finder and the A* pathfinder. Corner squares yield 3 neighbours, edge squares yield 5, and interior squares yield 8.

Inline Helper

sign(int val)Inline Function

Parameters: val – any integer

Returns: int – $-1$, $0$, or $1$

Returns the arithmetic sign of val. Used extensively in path generation to compute step directions along rows and columns.

Bitboard Utilities

These are standalone utility functions operating on Bitboard (uint64_t) values. They mirror the conventions of the Kirin engine’s own bitboard layer so that occupancy information received from the engine can be consumed directly.

Function

Signature

Description

bb_setBit

(Bitboard&, int)

Set bit at square index

bb_clearBit

(Bitboard&, int)

Clear bit at square index

bb_getBit

(Bitboard, int) -> bool

Test bit at square index

bb_countBits

(Bitboard) -> int

Popcount via Kernighan’s method

bb_getLSB

(Bitboard) -> int

Index of least significant set bit; $-1$ if zero

Bitboard utility functions

bb_setBit, bb_clearBit, and bb_getBit are declared inline in the header for maximum performance. bb_countBits uses the bit-manipulation trick bb &= bb - 1 to clear the lowest set bit on each iteration.

Position Parsing

parseBoardPosition(const char* pieces)Function

Parameters: pieces – space-separated list of piece-square tokens (e.g. "Pe2 Nd5 Rb1")

Returns: Bitboard – occupancy bitboard

Converts a human-readable piece list into an occupancy bitboard for testing or manual board setup. Each token consists of an optional piece-type letter followed by a two-character square name. The function is tolerant of extra whitespace and skips malformed tokens.