A sophisticated chess engine written in C++ using Bitboards.
- Board Representation: Bitboard-based representation (Little-Endian Rank-File Mapping).
- Move Generation: Strictly legal move generator.
- Specialized logic for Pins, Checks, and Check Evasions.
- Full support for Castling and En Passant with safety verification.
- Pre-calculated Ray and Attack tables (
rays.cpp,attacks.cpp).
- Search Algorithm: Alpha-Beta Pruning with Move Ordering.
- Move Ordering: MVV-LVA (Most Valuable Victim - Least Valuable Aggressor), Killer Heuristic, History Heuristic.
- Quiescence Search: Solves horizon effects by extending search for non-quiet positions (captures).
- Evaluation:
- Piece-Square Tables (PST) for positional scoring.
- Material imbalance calculation.
- UCI Protocol: Fully compliant Universal Chess Interface (UCI).
- Supports
position,go,isready,uci,quitcommands. - Compatible with standard GUIs (Arena, Fritz, Banksia, Lichess).
- Supports
g++ -std=c++17 main.cpp uci.cpp board.cpp move.cpp movegen.cpp search.cpp eval.cpp attacks.cpp rays.cpp -o chess.exemkdir build
cd build
cmake ..
makeThe engine runs in UCI mode by default.
On Windows:
.\chess.exe| Metric | v2.0 (Alpha-Beta) | v3.0 Exp (PVS + TT) | Delta |
|---|---|---|---|
| Total Nodes | 3,807,160 | 2,521,056 | -33.8% |
| Time to Depth | 14.81s | 8.93s | -39.7% |
| NPS (Throughput) | 257,146 | 282,403 | +9.8% |
| Branching Factor | ~6.62 | ~6.31 | Superior Efficiency |
- Search Efficiency: The integration of Principal Variation Search (PVS) significantly reduced the effective branching factor by searching the first move with a full window and subsequent moves with a null window.
- Cache Locality: The Transposition Table (Zobrist Hashing) provided a ~10% NPS boost by avoiding redundant evaluations of transposed positions, confirming that the hash table alignment is optimized for modern CPU L1/L2 caches.
- Node Reduction: The 34% reduction in nodes proves that move ordering (aided by TT best-moves) is functioning correctly, allowing for deeper searches in the same time-slice.
main.cpp: Entry point (connects UCI to Engine).uci.cpp: UCI protocol loop and command parsing.board.cpp: Bitboards, state tracking (castle rights, ep), make/unmake.movegen.cpp: Legal move generation (Checks, Pins, Evasions).search.cpp: Alpha-Beta, Ordering, Quiescence.eval.cpp: Piece-Square Table evaluation.attacks.cpp: Pre-calculated sliding attack tables (Magic-style logic).rays.cpp: Pre-calculated directional rays.
Version 2.0
- Transposition Tables (Zobrist Hashing)
- Iterative Deepening & Time Management
- Principal Variation Search (PVS)
- Late Move Reduction (LMR)