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
HashTableDecrement
Line 565Decrements 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 573Frees all memory used by the hash table.
history
MAX_MOVES
Line 584Maximum number of moves stored in history
Undo
Line 588Stores the necessary data to undo a move.
NULL_UNDO
Line 598Null undo object representing no previous move
UndoPrint
Line 602Prints the contents of an Undo struct (for debugging).
undo
—
The undo struct to print
History
Line 608Stores full game history for repetition detection and undo functionality.
HistoryRemove
Line 616Removes the last move from history (pop operation). Updates position table and count.
history
—
Pointer to a history struct
HistoryGetLast
Line 623Returns the most recent Undo record from history.
history
—
Pointer to a history struct
Undo
board
PieceType
Line 653Piece type used for indexing and logic
EMPTY_SQUARE
Line 664Used to indicate no piece on a square
STARTING_FEN
Line 668Standard starting position in Forsyth-Edwards Notation (FEN)
BOARD_SIZE
Line 672The board dimensions
PIECE_TYPES
Line 676The number of different pieces
Board
Line 686Core board structure combining bitboards and grid for performance and simplicity.
AddUndo
Line 706Records an undo step into the board's history.
board
—
The board to update
move
—
The move to be undone later
true
LoadLastUndo
Line 715Loads and removes the last undo record.
board
—
The board to restore
Undo
PIECES
Line 723All 12 supported pieces, as characters
PieceColor
Line 751Color of pieces
PromotionToChar
Line 759Converts a promotion code to its corresponding character.
promotion
—
Numeric code (0 = queen, 1 = rook, etc.)
Promotion
CharToPromotion
Line 767Converts a promotion piece character to a numeric code.
promotion
—
Piece character (e.g., 'q', 'n')
Numeric
BoardInitFen
Line 775Initializes a board from a FEN string. Must be freed with BoardFree().
board
—
Pointer to the board
fen
—
The FEN string
BoardInitFenHeap
Line 783Heap-allocates and initializes a board from FEN. Must be freed with BoardFree().
fen
—
The FEN string
Board*
BoardFree
Line 792Frees heap-allocated board (from BoardInitFenHeap).
board
—
The pointer to the board
BoardUpdateOccupancy
Line 798Recomputes and stores white, black, empty from bitboards. Call after any direct bitboard change.
board
—
The pointer to the board
GetWhite
Line 805Returns a bitboard of all white pieces.
board
—
Pointer to the board
Bitboard
GetBlack
Line 813Returns a bitboard of all black pieces.
board
—
Pointer to the board
Bitboard
GetEnemyColor
Line 821Returns a bitboard of all opponent pieces.
board
—
Pointer to the board
us
—
The color of the active player
Bitboard
GetEnemy
Line 830Returns a bitboard of all enemy pieces (based on current turn).
board
—
Pointer to the board
Bitboard
GetEmpty
Line 838Returns a bitboard of all empty squares.
board
—
Pointer to the board
Bitboard
CountPieces
Line 846Counts 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
HasCastlingRights
Line 856Checks if a board has certain castling rights.
board
—
Pointer to the board
castling_rights
—
The byte representing the castling rights
int
RevokeCastlingRights
Line 865Revokes specific castling rights from a board.
board
—
Pointer to the board
castling_rights
—
The byte contining the castle rights to revoke
IsSquareAttacked
Line 872Checks 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 882Checks if a square is empty.
board
—
Pointer to the board
square
—
The square we want to check
bool
castro_IsSquareOccupiedBy
Line 891Checks 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 901Returns 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 910Checks if a specific color is in check.
board
—
Pointer to the board
color
—
The color to check
bool
castro_IsInCheck
Line 919Checks if the player currently to move is in check.
board
—
Pointer to the board
bool
castro_BoardCopy
Line 928Returns a deep copy of the board.
board
—
Pointer to the source board
Board
printing
Uint32Print
Line 939Prints a 32-bit unsigned integer (e.g. in binary or hex).
value
—
The uint32_t number
Uint64Print
Line 944Prints a 64-bit unsigned integer (e.g. in binary or hex).
value
—
The uint64_t number
BitboardPrint
Line 949Prints a visual representation of a bitboard. Useful for debugging. Marks set bits on an 8x8 grid
bitboard
—
The bitboard to print
castro_BoardPrintSquares
Line 955Prints 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 963Highlights a bitboard on the board (used for debugging).
board
—
Pointer to the board
highlight
—
The bitboard to overlay/highlight
castro_BoardPrint
Line 970Prints 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 977Prints all bitboards in the board structure (for debugging).
board
—
The board structure
castro_BoardPrintGrid
Line 983Prints the character grid of the board.
board
—
Pointer to the board
zobrist
CASTLING_OPTIONS
Line 996Total number of castling rights encoded (K, Q, k, q)
zobrist_table
Line 1000Zobrist 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 1008Zobrist keys for each of the 4 castling rights (K, Q, k, q)
zobrist_en_passant
Line 1012Zobrist keys for each en passant file (a-h)
zobrist_black_to_move
Line 1016Zobrist key to represent "black to move"
InitZobrist
Line 1020Initializes the Zobrist tables.
CalculateZobristHash
Line 1024Calculates 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 1037Convenience function to calculate a Zobrist hash directly from a FEN string.
fen
—
Forsyth-Edwards Notation string
64-bit
ZobristPieceToIndex
Line 1045Translates piece as a character to expected zobrist index
piece
—
The piece as a character (example: white queen -> 'Q')
int
masks
Bitboard
Line 1055A 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 1114Initializes all masks
GeneralOccupancy
Line 1118Computes 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 1127Calculates 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 1138Generates a mask for the diagonal passing through the given square
square
—
The target square index
Bitboard
ComputeAntiDiagonalMask
Line 1144Generates a mask for the anti-diagonal passing through the given square
square
—
The target square index
Bitboard
ComputeHorizontalMask
Line 1150Generates a mask for the rank (row) of the given square
square
—
The target square index
Bitboard
ComputeVerticalMask
Line 1156Generates a mask for the file (column) of the given square
square
—
The target square index
Bitboard
DiagonalMask
Line 1162Retrieves the pre-computed diagonal mask for a square
square
—
The target square index
Bitboard
AntiDiagonalMask
Line 1168Retrieves the pre-computed anti-diagonal mask for a square
square
—
The target square index
Bitboard
HorizontalMask
Line 1174Retrieves the pre-computed horizontal mask for a square
square
—
The target square index
Bitboard
VerticalMask
Line 1180Retrieves the pre-computed vertical mask for a square
square
—
The target square index
Bitboard
ComputePawnPushMask
Line 1188Calculates 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 1195Calculates the two-square initial push for a pawn
square
—
The starting square of the pawn
color
—
The color of the pawn
Bitboard
ComputePawnPromotionMask
Line 1202Generates 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 1209Generates 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 1216Calculates standard diagonal attack squares for a pawn
square
—
The starting square of the pawn
color
—
The color of the pawn
Bitboard
ComputeKnightMoveMask
Line 1223Generates all possible L-shaped jumps for a knight on a given square
square
—
The starting square of the knight
Bitboard
ComputeBishopMoveMask
Line 1229Calculates all diagonal sliding moves for a bishop (ignoring blockers)
square
—
The starting square of the bishop
Bitboard
ComputeRookMoveMask
Line 1235Calculates all horizontal and vertical sliding moves for a rook (ignoring blockers)
square
—
The starting square of the rook
Bitboard
ComputeQueenMoveMask
Line 1241Calculates the union of rook and bishop moves for a queen
square
—
The starting square of the queen
Bitboard
ComputeKingMoveMask
Line 1247Generates a mask for all adjacent squares reachable by a king
square
—
The starting square of the king
Bitboard
PawnPushMask
Line 1253Retrieves pre-computed single push mask
square
—
starting square
color
—
piece color
Bitboard
PawnDoublePushMask
Line 1260Retrieves pre-computed double push mask
square
—
starting square
color
—
piece color
Bitboard
PawnPromotionMask
Line 1267Retrieves pre-computed promotion mask
square
—
starting square
color
—
piece color
Bitboard
PawnPromotionAttackMask
Line 1274Retrieves pre-computed promotion attack mask
square
—
starting square
color
—
piece color
Bitboard
PawnAttackMask
Line 1281Retrieves pre-computed pawn attack mask
square
—
starting square
color
—
piece color
Bitboard
KnightMoveMask
Line 1288Retrieves pre-computed knight move mask
square
—
starting square
Bitboard
BishopMoveMask
Line 1294Retrieves pre-computed bishop move mask
square
—
starting square
Bitboard
RookMoveMask
Line 1300Retrieves pre-computed rook move mask
square
—
starting square
Bitboard
QueenMoveMask
Line 1306Retrieves pre-computed queen move mask
square
—
starting square
Bitboard
KingMoveMask
Line 1312Retrieves pre-computed king move mask
square
—
starting square
Bitboard
move
Flag
Line 1331Flags representing special move types.
Promotion
Line 1342Types of piece promotions.
Castling bytes
Line 1352Bit flags representing castling rights.
NullMoveState
Line 1361Used to store minimal board state when making a null move.
nullState
Line 1370Stores the state of the board before a null move is made
Move
Line 1374Encoded 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 1382Special constant representing no move
MOVES_CAPACITY
Line 1386Max number of moves in a move list
Moves
Line 1390Represents a dynamic list of moves.
NO_MOVES
Line 1397Empty move list constant
MovesAppend
Line 1401Appends a move to a move list.
moves
—
Pointer to the Moves list structure.
move
—
The specific move to add to the list.
MovesAppendList
Line 1407Appends one move list to another.
dest
—
Pointer to the destination Moves list.
src
—
The source Moves list to copy from.
MovesCombine
Line 1413Combines two move lists into a new one.
m1
—
The first move list.
m2
—
The second move list.
Moves
MakeUndo
Line 1420Creates 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 1451Decodes a move into its components (used inside a scope).
MoveIsValid
Line 1462Checks 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 1470Returns 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 1477Returns 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 1484Piece 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 1490Reorders 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 1500Encodes 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 1509Encodes 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 1518Decodes 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 1527Sets the move flag field in an existing move.
move
—
Pointer to the move to modify.
flag
—
The flag value to set.
MoveSetPromotion
Line 1533Sets the promotion field in an existing move.
move
—
Pointer to the move to modify.
promotion
—
The promotion piece type.
DoMove
Line 1543Applies 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 1550Undoes 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 1561Makes 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 1569Unmakes the last move and restores previous board state using stored history.
board
—
Pointer to the board state to restore.
MakeNullMove
Line 1574Performs 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 1580Reverts a null move and restores the original side to move and state.
board
—
Pointer to the board state to restore.
Castle
Line 1589Executes 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 1596Checks 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 1603Executes 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 1610Checks 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 1617Checks 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 1624Checks if a move is a pawn promotion.
board
—
Pointer to the board state.
move
—
Pointer to the move to check.
bool
IsCapture
Line 1631Checks if a move is a capture (regular or en passant).
board
—
Pointer to the board state.
move
—
The move to check.
bool
IsInCheckAfterMove
Line 1638Simulates 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 1645Makes 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 1652Applies 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 1659Prints a move to stdout in algebraic format (e.g., "e2e4").
move
—
The move to print.
StringToMove
Line 1664Converts an algebraic string (e.g., "e2e4") to an encoded 32-bit Move integer.
str
—
The source algebraic string.
Move
MoveToString
Line 1670Converts 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 1680Compares 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 1687Compares 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 1698Extracts and returns the source (starting) square index from an encoded move.
move
—
The encoded 32-bit move.
Square
GetTo
Line 1704Extracts and returns the destination (target) square index from an encoded move.
move
—
The encoded 32-bit move.
Square
GetPromotion
Line 1710Retrieves the promotion piece type from the move bitfield.
move
—
The encoded 32-bit move.
uint8_t
GetFlag
Line 1716Extracts 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 1726Updates 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 1735Updates 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 1742Updates 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 1753Iterates 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 1760Aggregates the destination squares of all moves in a list into a single bitboard representation.
moves
—
The list of moves to process.
Bitboard
BoardPrintMove
Line 1770Prints a move on a board (highlighted view).
board
—
Pointer to the current board
move
—
The move to highlight on the board
MOVE_PRINT
Line 1776Debug macro alias for MovePrint
piece
Piece
Line 1787Represents 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 1797Prints the contents of a Piece struct (for debugging).
IS_PAWN
Line 1806Checks if a piece is a pawn.
IS_KNIGHT
Line 1811Checks if a piece is a knight.
IS_BISHOP
Line 1816Checks if a piece is a bishop.
IS_ROOK
Line 1821Checks if a piece is a rook.
IS_QUEEN
Line 1826Checks if a piece is a queen.
IS_KING
Line 1831Checks if a piece is a king.
IS_COLOR
Line 1836Checks if a piece has a given color.
IS_WHITE
Line 1841Checks if a piece is white.
IS_BLACK
Line 1846Checks if a piece is black.
GetPieceColor
Line 1855Gets 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 1861Returns 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 1868Compares two Piece structs for type and color equality.
p1
—
First piece to compare.
p2
—
Second piece to compare.
bool
notation
FenImport
Line 1885Imports 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 1893Exports the current board state to a FEN string.
board
—
Board to serialize
fen
—
Output buffer (must be large enough)
MAX_HEADER_LENGTH
Line 1900Maximum length for PGN header fields (Event, Site, etc.)
SanMove
Line 1908Represents a move in Standard Algebraic Notation (e.g., "e4", "Nf3").
Game
Line 1914PGN/notation-based game format. Stores metadata and the list of SAN moves.
move_name
Line 1929Parses 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 1939Shorthand for move_name(board, game, move)
GameInit
Line 1948Initializes 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 1958Runs a game move-by-move, showing each updated board. Useful for debugging or terminal-based visualization.
game
—
The game object to execute.
GamePrint
Line 1963Prints the full PGN representation of a game, including metadata tags and the formatted move list.
game
—
The game object to print.
GameAddMove
Line 1968Appends 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 1974Setters for PGN metadata: Sets the event field.
game
—
Pointer to the Game structure.
event
—
The event string.
GameSetSite
Line 1980Setters for PGN metadata: Sets the site field.
game
—
Pointer to the Game structure.
site
—
The site string.
GameSetDate
Line 1986Setters for PGN metadata: Sets the date field.
game
—
Pointer to the Game structure.
date
—
The date string (typically YYYY.MM.DD).
GameSetWhite
Line 1992Setters for PGN metadata: Sets the white player's name.
game
—
Pointer to the Game structure.
white
—
The player's name.
GameSetBlack
Line 1998Setters for PGN metadata: Sets the black player's name.
game
—
Pointer to the Game structure.
black
—
The player's name.
GameSetFen
Line 2004Setters for PGN metadata: Sets the starting FEN position.
game
—
Pointer to the Game structure.
fen
—
The FEN string.
GameSetResult
Line 2010Setters 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 2020Parses 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 2026Serializes 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 2032Serializes 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 2042Converts 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 2049Converts 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 2063Enumeration of possible game outcomes.
result_score
Line 2076String 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 2092Human-readable messages describing the result. Matches the Result enum index.
IsResult
Line 2109Determines 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 2118Determines if the current position is checkmate.
board
—
Pointer to the board
IsStalemate
Line 2125Determines if the current position is stalemate.
board
—
Pointer to the board
IsInsufficientMaterial
Line 2132Checks if neither player has sufficient material to checkmate.
board
—
Pointer to the board
IsThreefoldRepetition
Line 2139Determines 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 2154Enumeration of move types to control legality enforcement.
GeneratePseudoLegalMoves
Line 2167Generates 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 2173Generates 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 2179Pseudo-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 2187Pseudo-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 2196Pseudo-legal attacks for knights.
knights
—
Bitboard of knights.
empty
—
Bitboard of empty squares.
enemy
—
Bitboard of enemy pieces.
Bitboard
GeneratePseudoLegalBishopAttacks
Line 2204Pseudo-legal attacks for bishops.
bishops
—
Bitboard of bishops.
empty
—
Bitboard of empty squares.
enemy
—
Bitboard of enemy pieces.
Bitboard
GeneratePseudoLegalRookAttacks
Line 2212Pseudo-legal attacks for rooks.
rooks
—
Bitboard of rooks.
empty
—
Bitboard of empty squares.
enemy
—
Bitboard of enemy pieces.
Bitboard
GeneratePseudoLegalQueenAttacks
Line 2220Pseudo-legal attacks for queens.
queens
—
Bitboard of queens.
empty
—
Bitboard of empty squares.
enemy
—
Bitboard of enemy pieces.
Bitboard
GeneratePseudoLegalKingAttacks
Line 2228Pseudo-legal attacks for kings.
kings
—
Bitboard of kings.
empty
—
Bitboard of empty squares.
enemy
—
Bitboard of enemy pieces.
Bitboard
GeneratePseudoLegalAttacks
Line 2236Generates 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 2243Generates 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 2251Generates 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 2259Generates 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 2267Generates 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 2275Generates 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 2283Generates 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 2295Contains pre-calculated data used to accelerate legality checks, such as check evasions and pins.
CalculateLegality
Line 2303Pre-calculates the check and pin masks for the current board state.
board
—
Pointer to the board state.
LegalityContext
IsLegal
Line 2309Returns 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 2316Generates all strictly legal moves for the current board position.
board
—
Pointer to the constant board state.
Moves
GenerateLegalCaptures
Line 2322Generates only legal captures (including en passant). Ideal for quiescence search algorithms.
board
—
Pointer to the constant board state.
Moves
GenerateLegalMovesSquare
Line 2328Generates all legal moves that originate from a specific square.
board
—
Pointer to the board.
square
—
The source square index.
Moves
GenerateLegalMovesBitboard
Line 2335Returns a bitboard of all legal destination squares for the side to move.
board
—
Pointer to the board.
Bitboard
GenerateLegalPawnMoves
Line 2341Generates 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 2351Generates 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 2361Generates 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 2371Generates 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 2381Generates 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 2391Generates 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 2405Dispatches to legal or pseudo-legal move generation.
board
—
The board to generate moves from
type
—
MoveType
perft
u64
Line 2415Perft
Line 2418See [https://www.chessprogramming.org/Perft](https://www.chessprogramming.org/Perft)
PerftPseudoLegal
Line 2422Pseudo-legal perft: same node count as legal perft, faster (no pin/check pre-filter).
polyglot
PolyglotEntry
Line 2428Represents 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 2439cross-platform u64 macro
Random64
Line 2447See [http://hgm.nubati.net/book_format.html](http://hgm.nubati.net/book_format.html)
ConvertMove
Line 2669Converts 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 2675Probes 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 ""