castro
Konstantinos Despoinidis (KDesp73)
Line 61
MIT
Line 62version
Line 86Fills in the provided pointers with the current version numbers.
major
—
Pointer to an int to store the major version
minor
—
Pointer to an int to store the minor version
patch
—
Pointer to an int to store the patch version
square
Square
Line 114Represents a square on the chessboard (0-63).
SQUARE_PRINT
Line 118Prints a square's name and index to stdout.
square
—
The square to print
e4 = E4 28
COORDS
Line 131Macro to convert a square index to (row, col) coordinates.
square
—
Square index in [0, 63]
board[COORDS(s)] = ...;` → expands to `board[(s)/8][(s)%8]
SquareToName
Line 139Converts a square index (0-63) to algebraic notation (e.g. "e4").
buffer
—
[out] A 3-character buffer (e.g., `char name[3]`) to store the result.
square
—
[in] Square index from 0 to 63.
NameToSquare
Line 146Converts algebraic notation (e.g. "e4") to a square index (0-63).
buffer
—
A null-terminated string containing the square name.
Square
Rank
Line 154Returns the rank (0–7) of a square index.
square
—
The square as an index
int
File
Line 162Returns the file (0–7) of a square index.
square
—
The square as an index
int
IsSquareValid
Line 170Checks whether a square index is valid (0–63).
square
—
The square as an index
bool
SquareFromCoords
Line 178Converts (rank, file) coordinates to a square index.
y
—
Rank (0 = rank 1, 7 = rank 8)
x
—
File (0 = file A, 7 = file H)
Square
SquareFromName
Line 187Converts a square name (e.g. "d2") to an index.
name
—
A 2-character string like "e4".
Square
SR
Line 194Flips a square vertically (used for mirror board logic).
s
—
The square to flip
SR(E2) returns the square index of E7.
SQUARE_NONE
Line 284Special marker for an invalid or uninitialized square
bitboard
Bitboard
Line 295A 64-bit bitboard where each bit represents a square.
Direction
Line 299Cardinal and diagonal directions for sliding piece movement or bitboard shifting.
BB
Line 312Converts a square index to a bitboard with a single set bit.
square
—
The Square to covert into a bitboard
Bitboard
lsb
Line 320Returns the index of the least significant bit set (LSB).
b
—
Input bitboard.
Square
msb
Line 328Returns the index of the most significant bit set (MSB).
b
—
Input bitboard.
Square
shift
Line 335Shifts a bitboard in a specified direction.
b
—
Input bitboard.
D
—
Direction to shift in.
Resulting
poplsb
Line 344Pops and returns the index of the least significant bit set. The bit is cleared from the input bitboard.
b
—
Pointer to bitboard.
Square
popcount
Line 352Counts the number of bits set in the bitboard.
bb
—
Input bitboard.
Number
on
Line 360Sets the bit corresponding to the square in the bitboard.
bitboard
—
Pointer to the bitboard
square
—
The square we want to turn on
off
Line 367Clears the bit corresponding to the square in the bitboard.
bitboard
—
Pointer to the bitboard
square
—
The square we want to turn off
pseudo
PawnAttacks
Line 379Computes pseudo-legal pawn attacks.
pawn
—
Square of pawn.
enemySquares
—
Bitboard of enemy pieces.
color
—
0 = white, 1 = black.
The
PawnPushes
Line 389Computes pseudo-legal pawn forward pushes.
pawn
—
Square of pawn.
emptySquares
—
Bitboard of empty squares.
color
—
0 = white, 1 = black.
The
PawnPromotions
Line 399Computes pawn promotions (non-capturing).
pawns
—
Bitboard of pawns eligible to promote.
emptySquares
—
Bitboard of empty target squares.
color
—
0 = white, 1 = black.
The
PawnPromotionCaptures
Line 409Computes pawn promotion captures.
pawns
—
Bitboard of pawns eligible to promote by capture.
opponentPieces
—
Bitboard of capturable opponent pieces.
color
—
0 = white, 1 = black.
The
KnightAttacks
Line 419Computes knight attacks from a given square.
knights
—
Bitboard of knights
emptySquares
—
Bitboard with the empty squares on the board
enemySquares
—
Bitboard containing the enemy pieces positions
The
KingAttacks
Line 429Computes king attacks from a given square.
king
—
Bitboard containing the king's position
emptySquares
—
Bitboard with the empty squares on the board
enemySquares
—
Bitboard containing the enemy pieces positions
The
BishopAttacksFromOccupancy
Line 439Computes bishop attacks based on an occupancy bitboard
square
—
The square to calculate from
occupancy
—
The occupancy bitboard
The
RookAttacksFromOccupancy
Line 448Computes rook attacks based on an occupancy bitboard
square
—
The square to calculate from
occupancy
—
The occupancy bitboard
The
BishopAttacks
Line 457Computes bishop attacks using a sliding attack method.
bishops
—
The bishop's position
emptySquares
—
Bitboard with the empty squares on the board
enemySquares
—
Bitboard containing the enemy pieces positions
The
RookAttacks
Line 467Computes rook attacks using a sliding attack method.
rook
—
The rook's position
emptySquares
—
Bitboard with the empty squares on the board
enemySquares
—
Bitboard containing the enemy pieces positions
The
QueenAttacks
Line 477Computes queen attacks as the union of rook and bishop attacks.
queen
—
The queen's position
emptySquares
—
Bitboard with the empty squares on the board
enemySquares
—
Bitboard containing the enemy pieces positions
The
InitMagic
Line 487This function initializes the magic tables
BishopAttacksMagic
Line 491RookAttacksMagic
Line 495kingsafety
IsKingInCheck
Line 502Checks whether the king is in check.
kingPosition
—
Bitboard with one bit set where the king is.
enemyAttacks
—
Bitboard of all enemy attacks.
bool
hashing
HashEntry
Line 520Represents a single hash entry (position and repetition count).
HASH_TABLE_CAPACITY
Line 527Capacity of the repetition hash table (power of two for fast modulo).
HashTable
Line 531Tracks position repetition using Zobrist hashes. Uses open addressing (linear probing). Empty buckets have hash == 0.
InitHashTable
Line 540Initializes a hash table from a FEN string. Parses the FEN, computes the initial Zobrist hash, and sets up the table.
table
—
Pointer to an uninitialized HashTable
starting_fen
—
FEN string of the initial position
InitHashTableHash
Line 548Initializes a hash table directly from a known Zobrist hash.
table
—
Pointer to HashTable
starting_hash
—
Precomputed Zobrist hash of the position
UpdateHashTable
Line 555Adds a new position hash or updates an existing entry. If the hash already exists, increments the count.
table
—
Pointer to HashTable
hash
—
New Zobrist hash to insert
true
HashTableGetCount
Line 565Returns the current repetition count for a position (lookup only).
table
—
Pointer to HashTable
hash
—
The hash of the position to look up
The
HashTableDecrement
Line 573Decrements the repetition count for a position (used on unmake). Call with the hash that was last added before the move being undone.
table
—
Pointer to HashTable
hash
—
The hash of the position to decrement its repetition count
FreeHashTable
Line 581Frees all memory used by the hash table.
history
MAX_MOVES
Line 592Maximum number of moves stored in history
Undo
Line 596Stores the necessary data to undo a move.
NULL_UNDO
Line 606Null undo object representing no previous move
UndoPrint
Line 610Prints the contents of an Undo struct (for debugging).
undo
—
The undo struct to print
History
Line 616Stores full game history for repetition detection and undo functionality.
HistoryRemove
Line 624Removes the last move from history (pop operation). Updates position table and count. Decrements the given position hash (the position we're unmaking from), not last_added.
history
—
Pointer to a history struct
hash_to_remove
—
Zobrist hash of the position being left (child node)
HistoryGetLast
Line 633Returns the most recent Undo record from history.
history
—
Pointer to a history struct
Undo
board
PieceType
Line 663Piece type used for indexing and logic
EMPTY_SQUARE
Line 674Used to indicate no piece on a square
STARTING_FEN
Line 678Standard starting position in Forsyth-Edwards Notation (FEN)
BOARD_SIZE
Line 682The board dimensions
PIECE_TYPES
Line 686The number of different pieces
Board
Line 696Core board structure combining bitboards and grid for performance and simplicity.
AddUndo
Line 723Records an undo step into the board's history.
board
—
The board to update
move
—
The move to be undone later
true
LoadLastUndo
Line 732Loads and removes the last undo record.
board
—
The board to restore
Undo
PIECES
Line 740All 12 supported pieces, as characters
PieceColor
Line 768Color of pieces
PromotionToChar
Line 776Converts a promotion code to its corresponding character.
promotion
—
Numeric code (0 = queen, 1 = rook, etc.)
Promotion
CharToPromotion
Line 784Converts a promotion piece character to a numeric code.
promotion
—
Piece character (e.g., 'q', 'n')
Numeric
BoardInitFen
Line 792Initializes a board from a FEN string. Must be freed with BoardFree().
board
—
Pointer to the board
fen
—
The FEN string
BoardInitFenHeap
Line 800Heap-allocates and initializes a board from FEN. Must be freed with BoardFree().
fen
—
The FEN string
Board*
BoardFree
Line 809Frees heap-allocated board (from BoardInitFenHeap).
board
—
The pointer to the board
BoardUpdateOccupancy
Line 815Recomputes and stores white, black, empty from bitboards. Call after any direct bitboard change.
board
—
The pointer to the board
GetWhite
Line 822Returns a bitboard of all white pieces.
board
—
Pointer to the board
Bitboard
GetBlack
Line 830Returns a bitboard of all black pieces.
board
—
Pointer to the board
Bitboard
GetEnemyColor
Line 838Returns a bitboard of all opponent pieces.
board
—
Pointer to the board
us
—
The color of the active player
Bitboard
GetEnemy
Line 847Returns a bitboard of all enemy pieces (based on current turn).
board
—
Pointer to the board
Bitboard
GetEmpty
Line 855Returns a bitboard of all empty squares.
board
—
Pointer to the board
Bitboard
CountPieces
Line 863Counts the number of a specific piece color/type on the board.
board
—
Pointer to the board
color
—
The color of the pieces to count
type
—
The type of piece to count
HasNonPawnMaterial
Line 873Returns true if the side to move has material other than pawns and the king
PieceCount
Line 877HasCastlingRights
Line 881Checks if a board has certain castling rights.
board
—
Pointer to the board
castling_rights
—
The byte representing the castling rights
int
RevokeCastlingRights
Line 890Revokes specific castling rights from a board.
board
—
Pointer to the board
castling_rights
—
The byte contining the castle rights to revoke
IsSquareAttacked
Line 897Checks if a square is attacked by a given color.
board
—
Pointer to the board
square
—
The square we want to check
color
—
The color of the side that might attack the square
bool
IsSquareEmpty
Line 907Checks if a square is empty.
board
—
Pointer to the board
square
—
The square we want to check
bool
castro_IsSquareOccupiedBy
Line 916Checks if a square is occupied by a given color.
board
—
Pointer to the board
square
—
The square we want to check
color
—
The color to check for
bool
castro_NumberOfPieces
Line 926Returns the number of pieces on the board for a given color.
board
—
Pointer to the board
color
—
The color to count
size_t
castro_IsInCheckColor
Line 935Checks if a specific color is in check.
board
—
Pointer to the board
color
—
The color to check
bool
castro_IsInCheck
Line 944Checks if the player currently to move is in check.
board
—
Pointer to the board
bool
castro_BoardCopy
Line 953Returns a deep copy of the board.
board
—
Pointer to the source board
Board
printing
Uint32Print
Line 964Prints a 32-bit unsigned integer (e.g. in binary or hex).
value
—
The uint32_t number
Uint64Print
Line 969Prints a 64-bit unsigned integer (e.g. in binary or hex).
value
—
The uint64_t number
BitboardPrint
Line 974Prints a visual representation of a bitboard. Useful for debugging. Marks set bits on an 8x8 grid
bitboard
—
The bitboard to print
castro_BoardPrintSquares
Line 980Prints a list of squares (e.g. legal moves) on the board.
board
—
Pointer to the board
squares
—
Array of squares to print
count
—
Number of squares in the array
castro_BoardPrintBitboard
Line 988Highlights a bitboard on the board (used for debugging).
board
—
Pointer to the board
highlight
—
The bitboard to overlay/highlight
castro_BoardPrint
Line 995Prints the board with a list of highlighted squares.
board
—
Pointer to the board
first
—
The first square to highlight (followed by variadic list)
castro_BoardPrintBitboards
Line 1002Prints all bitboards in the board structure (for debugging).
board
—
The board structure
castro_BoardPrintGrid
Line 1008Prints the character grid of the board.
board
—
Pointer to the board
zobrist
CASTLING_OPTIONS
Line 1021Total number of castling rights encoded (K, Q, k, q)
zobrist_table
Line 1025Zobrist random numbers for each piece on each square. Dimensions: - PIECE_TYPES: 12 (black/white * 6 types) - BOARD_SIZE: 8x8 squares Indexed as [piece][rank][file]
zobrist_castling
Line 1033Zobrist keys for each of the 4 castling rights (K, Q, k, q)
zobrist_en_passant
Line 1037Zobrist keys for each en passant file (a-h)
zobrist_black_to_move
Line 1041Zobrist key to represent "black to move"
InitZobrist
Line 1045Initializes the Zobrist tables.
CalculateZobristHash
Line 1049Calculates the Zobrist hash of a board. This includes: - Pieces on the board - Side to move - Castling rights - En passant square
board
—
Pointer to the Board structure
64-bit
CalculateZobristHashFen
Line 1062Convenience function to calculate a Zobrist hash directly from a FEN string.
fen
—
Forsyth-Edwards Notation string
64-bit
ZobristPieceToIndex
Line 1070Translates piece as a character to expected zobrist index
piece
—
The piece as a character (example: white queen -> 'Q')
int
masks
Bitboard
Line 1080A 64-bit unsigned integer representing the squares of the chessboard. Each bit corresponds to a square (0-63), where a set bit (1) indicates the presence of a piece or a targeted square, and a cleared bit (0) indicates its absence. This allows for high-performance board manipulation using bitwise operators.
InitMasks
Line 1139Initializes all masks
GeneralOccupancy
Line 1143Computes the general occupancy into a bitboard
whitePieces
—
The bitboard containing the positions of the white pieces
blackPieces
—
The bitboard containing the positions of the black pieces
Bitboard
BlockerMasks
Line 1152Calculates the blocker mask for a sliding piece
slidingPiece
—
The bitboard with the sliding piece's square bit turned on
occupancy
—
The general occupancy bitboard
Bitboard
ComputeDiagonalMask
Line 1163Generates a mask for the diagonal passing through the given square
square
—
The target square index
Bitboard
ComputeAntiDiagonalMask
Line 1169Generates a mask for the anti-diagonal passing through the given square
square
—
The target square index
Bitboard
ComputeHorizontalMask
Line 1175Generates a mask for the rank (row) of the given square
square
—
The target square index
Bitboard
ComputeVerticalMask
Line 1181Generates a mask for the file (column) of the given square
square
—
The target square index
Bitboard
DiagonalMask
Line 1187Retrieves the pre-computed diagonal mask for a square
square
—
The target square index
Bitboard
AntiDiagonalMask
Line 1193Retrieves the pre-computed anti-diagonal mask for a square
square
—
The target square index
Bitboard
HorizontalMask
Line 1199Retrieves the pre-computed horizontal mask for a square
square
—
The target square index
Bitboard
VerticalMask
Line 1205Retrieves the pre-computed vertical mask for a square
square
—
The target square index
Bitboard
ComputePawnPushMask
Line 1213Calculates the single-square forward push for a pawn
square
—
The starting square of the pawn
color
—
The color of the pawn (determines direction)
Bitboard
ComputePawnDoublePushMask
Line 1220Calculates the two-square initial push for a pawn
square
—
The starting square of the pawn
color
—
The color of the pawn
Bitboard
ComputePawnPromotionMask
Line 1227Generates a mask for squares where a pawn push results in promotion
square
—
The starting square of the pawn
color
—
The color of the pawn
Bitboard
ComputePawnPromotionAttackMask
Line 1234Generates a mask for diagonal attacks that result in a promotion
square
—
The starting square of the pawn
color
—
The color of the pawn
Bitboard
ComputePawnAttackMask
Line 1241Calculates standard diagonal attack squares for a pawn
square
—
The starting square of the pawn
color
—
The color of the pawn
Bitboard
ComputeKnightMoveMask
Line 1248Generates all possible L-shaped jumps for a knight on a given square
square
—
The starting square of the knight
Bitboard
ComputeBishopMoveMask
Line 1254Calculates all diagonal sliding moves for a bishop (ignoring blockers)
square
—
The starting square of the bishop
Bitboard
ComputeRookMoveMask
Line 1260Calculates all horizontal and vertical sliding moves for a rook (ignoring blockers)
square
—
The starting square of the rook
Bitboard
ComputeQueenMoveMask
Line 1266Calculates the union of rook and bishop moves for a queen
square
—
The starting square of the queen
Bitboard
ComputeKingMoveMask
Line 1272Generates a mask for all adjacent squares reachable by a king
square
—
The starting square of the king
Bitboard
PawnPushMask
Line 1278Retrieves pre-computed single push mask
square
—
starting square
color
—
piece color
Bitboard
PawnDoublePushMask
Line 1285Retrieves pre-computed double push mask
square
—
starting square
color
—
piece color
Bitboard
PawnPromotionMask
Line 1292Retrieves pre-computed promotion mask
square
—
starting square
color
—
piece color
Bitboard
PawnPromotionAttackMask
Line 1299Retrieves pre-computed promotion attack mask
square
—
starting square
color
—
piece color
Bitboard
PawnAttackMask
Line 1306Retrieves pre-computed pawn attack mask
square
—
starting square
color
—
piece color
Bitboard
KnightMoveMask
Line 1313Retrieves pre-computed knight move mask
square
—
starting square
Bitboard
BishopMoveMask
Line 1319Retrieves pre-computed bishop move mask
square
—
starting square
Bitboard
RookMoveMask
Line 1325Retrieves pre-computed rook move mask
square
—
starting square
Bitboard
QueenMoveMask
Line 1331Retrieves pre-computed queen move mask
square
—
starting square
Bitboard
KingMoveMask
Line 1337Retrieves pre-computed king move mask
square
—
starting square
Bitboard
move
Flag
Line 1356Flags representing special move types.
Promotion
Line 1367Types of piece promotions.
Castling bytes
Line 1377Bit flags representing castling rights.
Move
Line 1386Encoded move type (bitfield). Format: - bits 0–5: from square - bits 6–11: to square - bits 12–14: promotion type - bits 15–17: move flag
NULL_MOVE
Line 1394Special constant representing no move
MOVES_CAPACITY
Line 1398Max number of moves in a move list
Moves
Line 1402Represents a dynamic list of moves.
NO_MOVES
Line 1409Empty move list constant
MovesAppend
Line 1413Appends a move to a move list.
moves
—
Pointer to the Moves list structure.
move
—
The specific move to add to the list.
MovesAppendList
Line 1419Appends one move list to another.
dest
—
Pointer to the destination Moves list.
src
—
The source Moves list to copy from.
MovesCombine
Line 1425Combines two move lists into a new one.
m1
—
The first move list.
m2
—
The second move list.
Moves
MakeUndo
Line 1432Creates an Undo struct representing a move played on a board.
board
—
Pointer to the current board state.
move
—
The move intended to be played.
Undo
MOVE_DECODE
Line 1463Decodes a move into its components (used inside a scope).
MoveIsValid
Line 1474Checks whether a move is legal and does not leave the king in check.
board
—
Pointer to the constant board state.
move
—
The move to validate.
color
—
The color of the player making the move.
_Bool
MoveIsCapture
Line 1482Returns true if the move captures a piece (or en passant).
board
—
Pointer to the constant board state.
move
—
The move to check.
_Bool
MoveGivesCheck
Line 1489Returns true if the move gives check. Temporarily modifies the board (make/unmake).
board
—
Pointer to the board state (will be modified and restored).
move
—
The move to test.
_Bool
PieceValueFromType
Line 1496Piece value for MVV-LVA (pawn=1, knight/bishop=3, rook=5, queen=9, king=0).
piece_type
—
The character representation of the piece.
int
OrderLegalMoves
Line 1502Reorders a legal move list for search: hash move first, then captures (MVV-LVA), killers, then checks, then quiet moves.
board
—
Pointer to the current board.
moves
—
Pointer to the list of moves to be sorted in place.
hash_move
—
The move retrieved from the transposition table (use NULL_MOVE if none).
killer0
—
The first killer move for the current ply.
killer1
—
The second killer move for the current ply.
score_checks
—
Boolean to determine if check detection should be part of the ordering.
MoveEncode
Line 1512Encodes a move from components into a 32-bit integer.
from
—
The starting square index.
to
—
The destination square index.
promotion
—
The piece type to promote to (if applicable).
flag
—
Metadata flags (capture, double push, etc.).
Move
MoveEncodeNames
Line 1521Encodes a move from algebraic names ("e2", "e4", etc.).
from
—
String representing the starting square.
to
—
String representing the destination square.
promotion
—
Promotion type index.
flag
—
Move flag index.
Move
MoveDecode
Line 1530Decodes a move into from-square, to-square, promotion, and flag.
move
—
The encoded 32-bit move.
from
—
Pointer to store the extracted starting square.
to
—
Pointer to store the extracted destination square.
promotion
—
Pointer to store the extracted promotion type.
flag
—
Pointer to store the extracted flag.
MoveSetFlag
Line 1539Sets the move flag field in an existing move.
move
—
Pointer to the move to modify.
flag
—
The flag value to set.
MoveSetPromotion
Line 1545Sets the promotion field in an existing move.
move
—
Pointer to the move to modify.
promotion
—
The promotion piece type.
DoMove
Line 1555Applies a move on a bitboard by updating the piece positions.
current
—
Pointer to the specific bitboard (e.g., WhitePawns) to be updated.
move
—
The encoded move containing source and destination squares.
Bitboard
UndoMove
Line 1562Undoes a move on a bitboard, reverting the piece to its previous position.
current
—
Pointer to the bitboard to be reverted.
move
—
The encoded move that was previously applied.
Bitboard
MakeMove
Line 1573Makes a move and updates board state accordingly. Handles piece movement, captures, and state updates (castling rights, en passant, etc.).
board
—
Pointer to the board state to modify.
move
—
The encoded move to execute.
bool
UnmakeMove
Line 1581Unmakes the last move and restores previous board state using stored history.
board
—
Pointer to the board state to restore.
MakeNullMove
Line 1586Performs a null move (swapping sides without moving a piece). Used primarily in search algorithms like Null Move Pruning.
board
—
Pointer to the board state to modify.
UnmakeNullMove
Line 1592Reverts a null move and restores the original side to move and state.
board
—
Pointer to the board state to restore.
Castle
Line 1601Executes a castling move, updating both the king and the rook positions on the bitboards.
board
—
Pointer to the board state to modify.
move
—
The encoded castling move.
bool
IsCastle
Line 1608Checks if a move is a castling move based on piece type and move flags.
board
—
Pointer to the current board state.
move
—
Pointer to the move to check.
bool
Enpassant
Line 1615Executes an en passant capture, removing the opponent's pawn and moving the current pawn.
board
—
Pointer to the board state.
move
—
The encoded en passant move.
bool
IsEnpassant
Line 1622Checks if a move is an en passant capture by checking the target square and pawn flags.
board
—
Pointer to the board state.
move
—
Pointer to the move to check.
bool
IsDoublePawnPush
Line 1629Checks if a move is a two-square pawn advance from the starting rank.
board
—
Pointer to the board state.
move
—
The move to check.
bool
IsPromotion
Line 1636Checks if a move is a pawn promotion.
board
—
Pointer to the board state.
move
—
Pointer to the move to check.
bool
IsCapture
Line 1643Checks if a move is a capture (regular or en passant).
board
—
Pointer to the board state.
move
—
The move to check.
bool
IsInCheckAfterMove
Line 1650Simulates a move to check if it leaves the friendly king in check (illegal move detection).
board
—
Pointer to the board state.
move
—
The move to simulate.
bool
MoveMake
Line 1657Makes a move with full legality rules, ensuring the move is valid and updates all board state.
board
—
Pointer to the board state.
move
—
The move to execute.
_Bool
MoveFreely
Line 1664Applies a move directly to the bitboards, ignoring turn-order or check legality.
board
—
Pointer to the board state.
move
—
The move to apply.
color
—
The color of the piece being moved.
MovePrint
Line 1671Prints a move to stdout in algebraic format (e.g., "e2e4").
move
—
The move to print.
StringToMove
Line 1676Converts an algebraic string (e.g., "e2e4") to an encoded 32-bit Move integer.
str
—
The source algebraic string.
Move
MoveToString
Line 1682Converts a move to a string in algebraic format (e.g., "e2e4").
move
—
The move to convert.
buffer
—
Pointer to the character buffer to store the result.
MoveCmp
Line 1692Compares two moves for equality by checking only the source and destination squares, ignoring internal metadata like flags or search scores.
m1
—
The first move to compare.
m2
—
The second move to compare.
bool
MoveCmpStrict
Line 1699Compares two moves strictly, ensuring that the squares, promotion piece, and all metadata flags are identical.
m1
—
The first move to compare.
m2
—
The second move to compare.
bool
GetFrom
Line 1710Extracts and returns the source (starting) square index from an encoded move.
move
—
The encoded 32-bit move.
Square
GetTo
Line 1716Extracts and returns the destination (target) square index from an encoded move.
move
—
The encoded 32-bit move.
Square
GetPromotion
Line 1722Retrieves the promotion piece type from the move bitfield.
move
—
The encoded 32-bit move.
uint8_t
GetFlag
Line 1728Extracts the metadata flag associated with the move (e.g., double pawn push, en passant, or castling).
move
—
The encoded 32-bit move.
uint8_t
UpdateHalfmove
Line 1738Updates the 50-move counter (halfmove clock). The counter is reset if a pawn is moved or a capture occurs; otherwise, it is incremented.
board
—
Pointer to the board state to update.
move
—
The move being executed.
piece_count_before
—
Total piece count on the board before the move.
piece_count_after
—
Total piece count on the board after the move.
piece
—
The character type of the piece that was moved.
UpdateCastlingRights
Line 1747Updates the castling rights bitmask after a move. Rights are lost if the king or a rook moves, or if a rook is captured on its starting square.
board
—
Pointer to the current board.
move
—
The move that may affect castling rights.
uint8_t
UpdateEnpassantSquare
Line 1754Updates the en passant target square. This is set if a pawn makes a double-square push, otherwise it is cleared.
board
—
Pointer to the current board.
move
—
The move being executed.
Square
BitboardToMoves
Line 1765Iterates through all set bits in a destination bitboard and appends a corresponding move to a Moves list, using the provided source square.
bitboard
—
The bitboard representing valid target squares.
from
—
The starting square shared by all generated moves.
Moves
MovesToBitboard
Line 1772Aggregates the destination squares of all moves in a list into a single bitboard representation.
moves
—
The list of moves to process.
Bitboard
BoardPrintMove
Line 1782Prints a move on a board (highlighted view).
board
—
Pointer to the current board
move
—
The move to highlight on the board
MOVE_PRINT
Line 1788Debug macro alias for MovePrint
piece
Piece
Line 1799Represents a chess piece. Each piece is defined by a type (character) and a color. - Uppercase letters: white pieces (e.g., 'P', 'N') - Lowercase letters: black pieces (e.g., 'p', 'n')
PIECE_PRINT
Line 1809Prints the contents of a Piece struct (for debugging).
IS_PAWN
Line 1818Checks if a piece is a pawn.
IS_KNIGHT
Line 1823Checks if a piece is a knight.
IS_BISHOP
Line 1828Checks if a piece is a bishop.
IS_ROOK
Line 1833Checks if a piece is a rook.
IS_QUEEN
Line 1838Checks if a piece is a queen.
IS_KING
Line 1843Checks if a piece is a king.
IS_COLOR
Line 1848Checks if a piece has a given color.
IS_WHITE
Line 1853Checks if a piece is white.
IS_BLACK
Line 1858Checks if a piece is black.
GetPieceColor
Line 1867Gets the color of a piece given its character representation (e.g., 'P' for white, 'p' for black).
piece
—
The character representing a piece.
int
PieceAt
Line 1873Returns the Piece located at a specific square on the board by inspecting the active bitboards.
board
—
Pointer to the board state.
square
—
Square index (0–63).
Piece
PieceCmp
Line 1880Compares two Piece structs for type and color equality.
p1
—
First piece to compare.
p2
—
Second piece to compare.
bool
notation
FenImport
Line 1897Imports a FEN string into a board. Sets up position, castling rights, side to move, en passant, etc.
board
—
Pointer to the board to initialize
fen
—
FEN string
FenExport
Line 1905Exports the current board state to a FEN string.
board
—
Board to serialize
fen
—
Output buffer (must be large enough)
MAX_HEADER_LENGTH
Line 1912Maximum length for PGN header fields (Event, Site, etc.)
SanMove
Line 1920Represents a move in Standard Algebraic Notation (e.g., "e4", "Nf3").
Game
Line 1926PGN/notation-based game format. Stores metadata and the list of SAN moves.
move_name
Line 1941Parses a SAN move and applies it to the board and game state.
board
—
Current board
game
—
Game context
move_str
—
SAN move string (e.g., "e4", "O-O")
MOVE
Line 1951Shorthand for move_name(board, game, move)
GameInit
Line 1960Initializes a Game object with basic metadata and a starting FEN string.
game
—
Pointer to the Game structure to initialize.
event
—
The name of the tournament or event.
site
—
The location of the game.
white
—
The name of the player playing white.
black
—
The name of the player playing black.
fen
—
The starting position in Forsyth-Edwards Notation.
GameRun
Line 1970Runs a game move-by-move, showing each updated board. Useful for debugging or terminal-based visualization.
game
—
The game object to execute.
GamePrint
Line 1975Prints the full PGN representation of a game, including metadata tags and the formatted move list.
game
—
The game object to print.
GameAddMove
Line 1980Appends a move in Standard Algebraic Notation (SAN) to the game's move history.
game
—
Pointer to the Game structure.
move
—
The SanMove object to append.
GameSetEvent
Line 1986Setters for PGN metadata: Sets the event field.
game
—
Pointer to the Game structure.
event
—
The event string.
GameSetSite
Line 1992Setters for PGN metadata: Sets the site field.
game
—
Pointer to the Game structure.
site
—
The site string.
GameSetDate
Line 1998Setters for PGN metadata: Sets the date field.
game
—
Pointer to the Game structure.
date
—
The date string (typically YYYY.MM.DD).
GameSetWhite
Line 2004Setters for PGN metadata: Sets the white player's name.
game
—
Pointer to the Game structure.
white
—
The player's name.
GameSetBlack
Line 2010Setters for PGN metadata: Sets the black player's name.
game
—
Pointer to the Game structure.
black
—
The player's name.
GameSetFen
Line 2016Setters for PGN metadata: Sets the starting FEN position.
game
—
Pointer to the Game structure.
fen
—
The FEN string.
GameSetResult
Line 2022Setters for PGN metadata: Sets the game result (e.g., "1-0", "0-1", "1/2-1/2").
game
—
Pointer to the Game structure.
result
—
The result string.
PgnImport
Line 2032Parses a standard PGN string and populates the Game object with its metadata and move history.
game
—
Pointer to the Game structure to be populated.
pgn
—
The source string containing the PGN data.
PgnExport
Line 2038Serializes the current Game state into a PGN formatted string.
game
—
Pointer to the Game structure to serialize.
pgn
—
Buffer to store the resulting PGN string.
PgnExportFile
Line 2044Serializes the Game to PGN format and writes it directly to a specified file path.
game
—
Pointer to the Game structure to save.
path
—
The filesystem path where the PGN file will be created or overwritten.
Notate
Line 2054Converts a Move to a SAN notation string (e.g., "Nf3", "O-O"). This requires the board state to determine move ambiguity (e.g., which knight moved) and whether the move results in check or checkmate.
board
—
Pointer to the current board state.
move
—
The internal encoded move to be converted.
san
—
Pointer to the SanMove structure where the resulting string will be stored.
SanToMove
Line 2061Converts a SAN move string back into an internal 32-bit Move. It validates the notation against the current board to find the correct source square and piece type.
board
—
Pointer to the current board state.
san
—
The SanMove structure containing the notation string.
Move
result
Result
Line 2075Enumeration of possible game outcomes.
result_score
Line 2088String representations of results for PGN output. Matches the Result enum index: - "*" for ongoing - "1-0", "0-1" for wins - "1/2-1/2" for all draws
result_message
Line 2104Human-readable messages describing the result. Matches the Result enum index.
IsResult
Line 2121Determines the current result of the game. Checks for checkmate, stalemate, 3-fold repetition, 50-move rule, or insufficient material.
board
—
Current board state
IsCheckmate
Line 2130Determines if the current position is checkmate.
board
—
Pointer to the board
HasNonPawnMaterial
Line 2137Returns true if the position is a draw by 50-move rule, threefold repetition, or insufficient material.
board
—
Board to check.
bool
IsStalemate
Line 2143Determines if the current position is stalemate.
board
—
Pointer to the board
IsInsufficientMaterial
Line 2150Checks if neither player has sufficient material to checkmate.
board
—
Pointer to the board
IsThreefoldRepetition
Line 2157Determines if the current position has occurred three times (3-fold repetition). Uses the board's `History` and `HashTable` to detect repeated positions.
board
—
Pointer to the board
movegen
MoveType
Line 2172Enumeration of move types to control legality enforcement.
GeneratePseudoLegalMoves
Line 2185Generates all pseudo-legal moves for the current position. Includes moves that may leave the king in check.
board
—
Pointer to the constant board state.
Moves
GeneratePseudoLegalMovesBitboard
Line 2191Generates a bitboard representing all pseudo-legal destination squares for all pieces of the side to move.
board
—
Pointer to the constant board state.
Bitboard
GeneratePseudoLegalPawnMoves
Line 2197Pseudo-legal push moves for pawns, including single and double pushes.
pawns
—
Bitboard of the pawns to move.
enemy
—
Bitboard of all enemy pieces.
color
—
The color of the pawns.
Bitboard
GeneratePseudoLegalPawnAttacks
Line 2205Pseudo-legal pawn attacks. If strict is true, diagonal movement is restricted to squares with capturable enemies.
pawns
—
Bitboard of the attacking pawns.
enemy
—
Bitboard of all enemy pieces.
color
—
The color of the pawns.
strict
—
Boolean to enforce capture-only diagonal movement.
Bitboard
GeneratePseudoLegalKnightAttacks
Line 2214Pseudo-legal attacks for knights.
knights
—
Bitboard of knights.
empty
—
Bitboard of empty squares.
enemy
—
Bitboard of enemy pieces.
Bitboard
GeneratePseudoLegalBishopAttacks
Line 2222Pseudo-legal attacks for bishops.
bishops
—
Bitboard of bishops.
empty
—
Bitboard of empty squares.
enemy
—
Bitboard of enemy pieces.
Bitboard
GeneratePseudoLegalRookAttacks
Line 2230Pseudo-legal attacks for rooks.
rooks
—
Bitboard of rooks.
empty
—
Bitboard of empty squares.
enemy
—
Bitboard of enemy pieces.
Bitboard
GeneratePseudoLegalQueenAttacks
Line 2238Pseudo-legal attacks for queens.
queens
—
Bitboard of queens.
empty
—
Bitboard of empty squares.
enemy
—
Bitboard of enemy pieces.
Bitboard
GeneratePseudoLegalKingAttacks
Line 2246Pseudo-legal attacks for kings.
kings
—
Bitboard of kings.
empty
—
Bitboard of empty squares.
enemy
—
Bitboard of enemy pieces.
Bitboard
GeneratePseudoLegalAttacks
Line 2254Generates a combined bitboard of all squares attacked by a given color.
board
—
Pointer to the constant board state.
color
—
The color of the attacking side.
Bitboard
GeneratePawnMoves
Line 2261Generates potential destination squares for a single pawn.
board
—
Pointer to the board state.
piece
—
Square index of the pawn.
color
—
Color of the pawn.
Bitboard
GenerateKnightMoves
Line 2269Generates potential destination squares for a single knight.
board
—
Pointer to the board state.
piece
—
Square index of the knight.
color
—
Color of the knight.
Bitboard
GenerateBishopMoves
Line 2277Generates potential destination squares for a single bishop.
board
—
Pointer to the board state.
piece
—
Square index of the bishop.
color
—
Color of the bishop.
Bitboard
GenerateRookMoves
Line 2285Generates potential destination squares for a single rook.
board
—
Pointer to the board state.
piece
—
Square index of the rook.
color
—
Color of the rook.
Bitboard
GenerateQueenMoves
Line 2293Generates potential destination squares for a single queen.
board
—
Pointer to the board state.
piece
—
Square index of the queen.
color
—
Color of the queen.
Bitboard
GenerateKingMoves
Line 2301Generates potential destination squares for a single king.
board
—
Pointer to the board state.
piece
—
Square index of the king.
color
—
Color of the king.
Bitboard
LegalityContext
Line 2313Contains pre-calculated data used to accelerate legality checks, such as check evasions and pins.
CalculateLegality
Line 2321Pre-calculates the check and pin masks for the current board state.
board
—
Pointer to the board state.
LegalityContext
IsLegal
Line 2327Returns whether a move is fully legal, ensuring it doesn't leave the friendly king in check.
board
—
Pointer to the constant board state.
move
—
The move to validate.
bool
GenerateLegalMoves
Line 2334Generates all strictly legal moves for the current board position.
board
—
Pointer to the constant board state.
Moves
GenerateLegalCaptures
Line 2340Generates only legal captures (including en passant). Ideal for quiescence search algorithms.
board
—
Pointer to the constant board state.
Moves
GenerateLegalMovesSquare
Line 2346Generates all legal moves that originate from a specific square.
board
—
Pointer to the board.
square
—
The source square index.
Moves
GenerateLegalMovesBitboard
Line 2353Returns a bitboard of all legal destination squares for the side to move.
board
—
Pointer to the board.
Bitboard
GenerateLegalPawnMoves
Line 2359Generates legal pawn moves, applying check and pin constraints.
board
—
Pointer to the board.
pieces
—
Bitboard of pawns.
color
—
Color of the side to move.
ctx
—
Pointer to the pre-calculated legality context.
moves
—
Pointer to the list to append moves to.
captures_only
—
If true, only captures are generated.
GenerateLegalKnightMoves
Line 2369Generates legal knight moves, applying check and pin constraints.
board
—
Pointer to the board.
pieces
—
Bitboard of knights.
color
—
Color of the side to move.
ctx
—
Pointer to the legality context.
moves
—
Pointer to the list to append moves to.
captures_only
—
If true, only captures are generated.
GenerateLegalBishopMoves
Line 2379Generates legal bishop moves, applying check and pin constraints.
board
—
Pointer to the board.
pieces
—
Bitboard of bishops.
color
—
Color of the side to move.
ctx
—
Pointer to the legality context.
moves
—
Pointer to the list to append moves to.
captures_only
—
If true, only captures are generated.
GenerateLegalRookMoves
Line 2389Generates legal rook moves, applying check and pin constraints.
board
—
Pointer to the board.
pieces
—
Bitboard of rooks.
color
—
Color of the side to move.
ctx
—
Pointer to the legality context.
moves
—
Pointer to the list to append moves to.
captures_only
—
If true, only captures are generated.
GenerateLegalQueenMoves
Line 2399Generates legal queen moves, applying check and pin constraints.
board
—
Pointer to the board.
pieces
—
Bitboard of queens.
color
—
Color of the side to move.
ctx
—
Pointer to the legality context.
moves
—
Pointer to the list to append moves to.
captures_only
—
If true, only captures are generated.
GenerateLegalKingMoves
Line 2409Generates legal king moves, ensuring the king does not move into check.
board
—
Pointer to the board.
pieces
—
Bitboard of kings.
color
—
Color of the side to move.
ctx
—
Pointer to the legality context.
moves
—
Pointer to the list to append moves to.
captures_only
—
If true, only captures are generated.
GenerateMoves
Line 2423Dispatches to legal or pseudo-legal move generation.
board
—
The board to generate moves from
type
—
MoveType
perft
u64
Line 2433Perft
Line 2436See [https://www.chessprogramming.org/Perft](https://www.chessprogramming.org/Perft)
PerftPseudoLegal
Line 2440Pseudo-legal perft: same node count as legal perft, faster (no pin/check pre-filter).
polyglot
PolyglotEntry
Line 2446Represents a single entry in a Polyglot-formatted opening book (.bin). This structure maps a specific board position to a recommended move with associated metadata for move selection.
U64
Line 2457cross-platform u64 macro
Random64
Line 2465See [http://hgm.nubati.net/book_format.html](http://hgm.nubati.net/book_format.html)
ConvertMove
Line 2687Converts a move from the Polyglot 16-bit format (typically used in .bin opening books) to the Castro 32-bit internal move format.
polyglotMove
—
The 16-bit integer representing the move in Polyglot format.
Move
LookupBookMove
Line 2693Probes an external Polyglot opening book file to find a move matching the current position's Zobrist hash. If multiple moves exist, it typically selects one based on weight.
position_hash
—
The 64-bit Zobrist hash of the current board position.
book_path
—
The filesystem path to the Polyglot .bin opening book.
Move
No matches found
We couldn't find anything matching ""