How namebrandon/seajay-chess works
1. SeaJay is a single-process C++20 chess engine whose runtime path is: UCI command input, position setup, search, evaluation, and best-move/output reporting. The top-level entry point is src/main.cpp, which wires the engine into UCI mode.
2. The codebase is organized into three primary subsystems under src/: core/ for board state and move legality, evaluation/ for static score computation, and search/ for deciding moves. uci/ is the protocol boundary to external GUIs, and tools/ plus tests/ provide diagnostics and validation outside the engine loop.
3. src/core/ is the foundational engine layer. It holds board representation, bitboards, move generation, attack detection, legality/safety checks, static exchange evaluation, perft, and transposition-table primitives. This is the layer that everything else depends on for accurate chess semantics.
4. Move generation is heavily infrastructure-driven: magic bitboards, attack caches, and helper types in core/types.h and core/bitboard.* support fast legal move production and attack queries. The presence of attack_cache, board_safety, and magic_validator suggests a strong emphasis on correctness and speed for king safety and sliding attacks.
5. src/evaluation/ computes the static position score used by the search. It is split into material, piece-square tables, pawn structure, and king safety, with an evaluate.cpp front end and trace support in eval_trace.h. This is a classic handcrafted evaluation pipeline rather than NNUE or external model inference.
6. src/search/ contains the main decision engine. The visible architecture is iterative deepening negamax with alpha-beta pruning, quiescence search, aspiration windows, move ordering, LMR, null-move pruning, killer/history/countermove heuristics, and singular extension support. Search state is factored into info/context/scratch structs so the engine can carry per-node and per-iteration metadata cleanly.
7. The transposition table sits at the boundary between core and search: core/transposition_table.* provides the shared hash store, while search consumes it for pruning, move ordering, and repetition/history efficiency. There is also an experimental clustered TT implementation under src/experimental/tt/, indicating active exploration of alternative TT layouts.
8. src/uci/ is the external interface layer. It parses UCI commands, manages uci/isready/position/go/stop, and formats engine info output. uci_draw_integration.cpp suggests the engine also has explicit handling for draw claims or draw-related protocol behavior.
9. Time control and search lifecycle are handled inside search/time_management.*, search/search_info.h, and related iteration data structs. This boundary is important because the search must respond to stop, time budgets, and iterative-deepening limits without leaking protocol logic into core search routines.
10. src/benchmark/ and src/tools/perft_tool.cpp are performance-oriented auxiliary entry points. They let the same engine code be exercised outside the normal UCI loop for speed measurements and move-generation validation.
11. tests/ is broad and architecture-relevant, not just unit coverage. It includes perft suites, regression tests, FEN parsing coverage, SEE tests, transposition-table tests, move-generation utilities, and tactical/EPD position packs. This shows the project treats correctness of chess semantics as a first-class subsystem alongside performance.
12. tools/ and docs/project_docs/telemetry/ form an analysis pipeline around engine strength and bug hunting. Scripts collect tactical failures, node explosion data, null-move metrics, and eval harness results; the documentation directories capture investigation reports, tuning plans, and bug audits. In diagram terms, this is an offline feedback loop feeding search/eval refactors and tuning.
13. The build/runtime story is conventional CMake plus Makefile wrappers, with scripts for local builds, OpenBench builds, and a devcontainer for reproducible environments. The README also indicates OpenBench is used for performance validation, so external benchmark infrastructure is part of the development workflow even though it is not part of the engine runtime.
14. src/experimental/move_picker/ and the many docs/project_docs/* refactor plans show the repo has a stable core but active experimentation around move ordering, evaluation refactors, and search API changes. For architecture diagrams, treat these as side branches or feature incubators rather than primary runtime dependencies.
Main entry points: negamax.cpp Negamax · uci.cpp UCI · evaluate.cpp Eval · search.cpp Search
Components 22
Core
Board state, legality, and shared chess primitives
- Board · Position representation and move application
src/core/board.cpp - Move gen · Produces legal and pseudo-legal moves
src/core/move_generation.cpp - Attack cache · Fast attack lookup support
src/core/attack_cache.cpp - Safety · King safety and legality checks
src/core/board_safety.cpp - SEE · Captures exchange evaluation for move filtering
src/core/see.cpp - TT · Shared transposition table implementation
src/core/transposition_table.cpp - Perft · Move-generation validation and counting
src/core/perft.cpp
Evaluation
Static scoring pipeline
- Eval · Computes static position score
src/evaluation/evaluate.cpp - PST · Piece-square and positional tables
src/evaluation/pst.cpp - Pawns · Pawn structure features and scoring
src/evaluation/pawn_structure.cpp - King safety · King safety terms for evaluation
src/evaluation/king_safety.cpp
Search
Move selection and tree exploration
- Search · Iterative deepening search driver
src/search/search.cpp - Negamax · Main tree search with pruning
src/search/negamax.cpp - Q-search · Quiescence search for tactical stability
src/search/quiescence.cpp - Order · Ranks moves using heuristics and history
src/search/move_ordering.cpp - Time · Time budgets and stop handling
src/search/time_management.cpp
Interfaces
UCI, benchmarking, and external tooling
- UCI · Parses commands and produces engine responses
src/uci/uci.cpp - Info · Builds UCI info strings and reporting payloads
src/uci/info_builder.cpp - Draw logic · Handles draw-related UCI behavior
src/uci/uci_draw_integration.cpp - Bench · Non-UCI performance entrypoint
src/benchmark/benchmark.cpp - Perft tool · Standalone perft runner
src/tools/perft_tool.cpp
Connections 27
- main → UCI: starts · Main wires the engine into UCI mode
- UCI → Board: position · Protocol commands build or update positions
- UCI → Search: go · Search is launched from UCI requests
- UCI → Time: stop/time · Protocol lifecycle feeds search control
- UCI → Info: info · Formats engine output for the GUI
- UCI → Draw logic: draw · Handles draw-related protocol paths
- Search → Negamax: iterates · Driver coordinates deepening and principal search
- Search → Time: limits · Search obeys time and stop constraints
- Search → TT: hash · Search consults transposition table data
- Negamax → Q-search: leafs · Main search falls through to quiescence
- Negamax → Order: orders · Heuristics rank candidate moves
- Negamax → Eval: scores · Static evaluation anchors tree decisions
- Negamax → TT: prunes · Hash entries support cutoffs and ordering
- Negamax → Board: explores · Search advances and undoes positions
- Q-search → SEE: filters · SEE helps manage tactical capture search
- Q-search → Eval: leaf eval · Static score is used at quiescent leaves
- Board → Move gen: generates · Board state drives legal move production
- Move gen → Attack cache: queries · Fast attack tables support generation
- Move gen → Safety: checks · Legality depends on king safety logic
- Safety → Attack cache: attacks · Safety uses attack queries for checks and evasion
- Eval → PST: uses · Positional scoring includes piece-square terms
- Eval → Pawns: uses · Pawn structure contributes to static score
- Eval → King safety: uses · King safety terms feed evaluation
- Perft → Board: tests · Perft counts rely on accurate board semantics
- Perft tool → Perft: runs · Standalone tool exercises perft logic
- Bench → Search: measures · Benchmark entrypoint stresses search performance
- Bench → Eval: measures · Benchmarks can isolate evaluation cost