Internal API Reference
OrbisChessEngine.TTEntry — Type
Transposition table entry.
- key: Zobrist hash of the position (for collision checking)
- value: evaluation score
- depth: search depth at which this value was computed
- node_type: type of node (EXACT, LOWERBOUND, UPPERBOUND)
- best_move: best move found from this position
Base.show — Method
Base.show(io::IO, x::Union{Board,Game})Display a simple ASCII representation of the given Board (or a Game's board) in the terminal.
Each square shows either a piece or a dot . for empty squares. Piece symbols:
- White:
P(pawn),N(knight),B(bishop),R(rook),Q(queen),K(king) - Black:
p(pawn),n(knight),b(bishop),r(rook),q(queen),k(king)
The board is printed with rank 8 at the top and file a on the left.
Example
b = Board() # prints the initial chess positionOrbisChessEngine._filter_legal_moves! — Method
_filter_legal_moves!(board, pseudo, start, stop, moves, n_moves)Filters pseudo-legal moves into legal moves, avoiding full make/undo for moves that clearly cannot expose the king.
OrbisChessEngine.attackers_to — Method
attackers_to(board::Board, sq::Int, occ::UInt64) -> UInt64Bitboard of every piece (either color) that attacks sq, given a custom occupancy occ – not necessarily board's actual occupancy. Used by see to simulate a shrinking board as pieces are captured off in an exchange, without ever touching board itself. Pawn/knight/king attacks are read straight from board.bitboards (their attack masks don't depend on occupancy) and filtered against occ at the end; sliding attacks already respect occ via sliding_attack_from_occupancy.
OrbisChessEngine.clearbit — Method
Clear bit at square sq.
OrbisChessEngine.compute_eval_and_phase — Method
compute_eval_and_phase(board::Board) -> (Int, Int)Compute the evaluation score (from White's perspective) and the game phase value from scratch for a given board.
OrbisChessEngine.count_bits — Method
Count the number of bits set in a UInt64.
OrbisChessEngine.extract_root_pv — Method
Reconstruct the principal variation (PV) from the transposition table
OrbisChessEngine.file_rank — Method
file_rank(sq) -> (Int, Int)Return file (1..8) and rank (1..8) for a square index
OrbisChessEngine.find_magic — Method
Try to find a magic number for a given square.
- sq: square index 0-63
- masks: precomputed mask table (bishop or rook)
- attack_fn: function (sq, occ) → attacks
- tries: number of random candidates to attempt
OrbisChessEngine.find_uci_move — Method
find_uci_move(board::Board, uci_str::AbstractString) -> MoveResolve a UCI move string (e.g. "e2e4", "e7e8q", "e1g1" for castling) to the matching legal Move on board. Throws an ErrorException if no legal move matches.
OrbisChessEngine.flip_table — Method
Flip a piece-square table vertically (white → black perspective). Input is a 64-element vector (row-major, starting at A8). Returns a new 64-element vector with ranks mirrored.
OrbisChessEngine.generate_magics — Method
Compute magic numbers for all squares.
- masks: precomputed mask table (bishop or rook)
- attack_fn: function (sq, occ) → attacks
OrbisChessEngine.generate_pawn_moves! — Method
Generate pseudo-legal pawn moves in-place
board: Board structmoves: preallocated buffer to append moves
Returns: number of moves added
OrbisChessEngine.generate_pawn_moves — Method
Generate pseudo-legal pawn moves for the side to move
board: Board struct
Returns: Vector of Move
OrbisChessEngine.gives_check — Method
gives_check(board::Board, m::Move) -> BoolCheap static test for whether making m gives check, without the cost of a full make_move!/undo_move! round trip: computes the post-move occupancy and the moved (or promoted-to) piece's attack pattern from m.to, and tests whether it covers the enemy king's square.
Only detects direct checks from the moved/promoted piece itself – not discovered checks, nor a check delivered by the rook on a castling move.
OrbisChessEngine.is_fifty_move_rule — Method
Check for fifty-move rule
board: Board struct
Returns: Bool
OrbisChessEngine.is_insufficient_material — Method
is_insufficient_material(board::Board) -> BoolCheck for insufficient material to mate
board: Board struct
OrbisChessEngine.is_threefold_repetition — Method
Check for threefold repetition
board: Board struct
Returns: Bool
OrbisChessEngine.king_ray_squares — Method
king_ray_squares(occ, king_sq) -> UInt64Bitboard of every square a piece could move from and possibly open a sliding discovered check on king_sq: for each of the 8 rook/bishop directions from king_sq, every square out to and including the first occupied square in that direction.
Computed once per node.
OrbisChessEngine.king_square — Method
king_square(board::Board, side::Side) -> IntGet the square index of the king for the given side
board: Board structside: Side (WHITE or BLACK)
Returns: Int (square index 0..63)
OrbisChessEngine.make_null_move! — Method
Apply a null move (pass) to the board, modifying it in place. Used for null-move pruning.
OrbisChessEngine.mobility_and_king_safety — Method
mobility_and_king_safety(board::Board) -> IntMobility and king-safety term for evaluate, from White's point of view. Each minor/major piece's attack bitboard is computed once and used both for its own side's mobility score and (if it reaches into the enemy king's zone) the enemy king's attacker weight.
OrbisChessEngine.move_ordering_score — Method
move_ordering_score(board::Board, m::Move, ply::Int)Heuristic to score moves for ordering:
- Promotions are prioritized highest.
- Captures are prioritized higher, ordered by true exchange value (SEE).
- Moves giving check are prioritized.
- Killer moves (quiet moves that caused a cutoff at this ply before) next.
- Other quiet moves are ordered by the history heuristic.
OrbisChessEngine.next_square — Method
next_square(sq::Int, dir::Tuple{Int,Int}) -> Union{Int,Nothing}Returns the next square index in direction dir = (df, dr) from sq. Returns nothing if it goes off-board.
OrbisChessEngine.occupancy — Method
occupancy(board::Board) -> UInt64Returns a bitboard of all occupied squares.
OrbisChessEngine.occupancy_variations — Method
Generate all possible occupancy bitboards for the given mask
OrbisChessEngine.pawn_shield_score — Method
pawn_shield_score(board::Board) -> IntPenalize a king still on its own back two ranks for missing pawns on the 3 files around it, one rank ahead.
OrbisChessEngine.piece_at — Method
piece_at(board::Board, sq) -> IntReturn the piece type at a given square (0..63) using bitboards.
OrbisChessEngine.piece_from_symbol — Method
piece_from_symbol(c::AbstractChar, side::Side)Return the piece constant corresponding to promotion symbol c and the moving side (WHITE or BLACK).
OrbisChessEngine.piece_square_value — Method
Return the PSQT value of a piece on a given square.
- piece: Piece.WPAWN..Piece.BKING
- square: 0..63 (a1=0, h8=63)
- phase: Int (0..MAX_PHASE)
OrbisChessEngine.see — Method
see(board::Board, m::Move) -> IntStatic Exchange Evaluation for capture move m: play out the full capture sequence on m.to (each side recaptures with its least valuable attacker, alternating, only continuing if doing so doesn't lose material) using bitboards only – no make_move!/undo_move!. Returns the net material result in centipawns for the side making m (positive = m wins material). m is assumed to be an actual capture (m.capture != 0 or m.en_passant).
Simplifications:
- A promoting capture's attacker is valued at the pawn's own value, not the promoted piece.
- Pins are ignored.
OrbisChessEngine.setbit — Method
Set bit at square sq.
OrbisChessEngine.sliding_attack_from_occupancy — Method
Generic sliding attack generator.
- sq: square index
- occ: occupancy bitboard
- directions: list of (df, dr) directions
OrbisChessEngine.sliding_mask — Method
Generic sliding mask generator.
- sq: square index (0..63)
- directions: list of (df, dr) directions
OrbisChessEngine.square_attacked — Method
square_attacked(board, sq, attacker) -> BoolCheck if a square is attacked by the given side.
board: Board structsq: Int (square index 0..63)attacker: Side (WHITE or BLACK)
Returns: Bool
OrbisChessEngine.square_index — Method
Map algebraic notation (e.g. 'e3') → square index (0..63).
OrbisChessEngine.square_index — Method
Map (file, rank) → square index (0..63). file=1→a, rank=1→1.
OrbisChessEngine.store_killer! — Method
Store a killer move for the given ply. Only quiet moves (non-captures) are stored.
- m: the move to store
- ply: the current ply
OrbisChessEngine.testbit — Method
Check if bit at square sq is set.
OrbisChessEngine.to_uci — Method
to_uci(m::Move) -> StringFormat a Move in UCI long algebraic notation, e.g. "e2e4", "e7e8q". Unlike string(m) (used for human-readable display), this never uses "O-O" or "=", since UCI represents castling as the king's from/to squares and promotions with a bare lowercase letter.
OrbisChessEngine.tt_index — Method
Get index in transposition table from hash.
OrbisChessEngine.tt_probe — Function
Look up a position in the transposition table.
- hash: Zobrist hash of the position
- depth: current search depth
- α: alpha value
- β: beta value
- ply: current node's distance from this search's root
Returns a tuple (value, best_move, hit) where hit is true if a valid entry was found.
OrbisChessEngine.tt_store — Function
Store an entry in the transposition table.
- ply: current node's distance from this search's root
OrbisChessEngine.uci_info_line — Method
Print a UCI "info" line for the given depth's result: score (relative to the side to move, per the UCI spec), elapsed time, node count/rate, and PV in UCI notation.
OrbisChessEngine.undo_null_move! — Method
Undo a null move, restoring the previous board state.
OrbisChessEngine.update_history! — Method
Update the history heuristic for a quiet move that caused a beta cutoff. Only quiet (non-capture) moves are tracked; captures already order via SEE. Score is bumped by depth^2 (moves that caused cutoffs deeper in the tree are weighted more heavily), clamped at HISTORY_MAX.
- side: the side that made the move
- m: the move to reward
- depth: remaining search depth at the node where the cutoff occurred