(image generated with DALL·E 2)
Strong, UCI command-line chess engine, written from scratch in C++ in development since early 2021. Optimized for regular chess, FRC (Fischer Random Chess) and DFRC (Double Fischer Random Chess).
Caissa is listed on many chess engines ranking lists:
- CCRL 40/2 FRC - 3965 (#5) (version 1.17)
- CCRL Chess324 - 3701 (#5) (version 1.18)
- CCRL 40/15 - 3601 (#5) (version 1.17 4CPU)
- CCRL Blitz - 3733 (#8) (version 1.16 8CPU)
- SPCC UHO-Top15 - 3671 (#8) (version 1.18)
- IpMan Chess 10+1 (R9-7945HX) - 3496 (#13) (version 1.18 avx512)
- IpMan Chess 10+1 (i9-7980XE) - 3478 (#12) (version 1.17 avx512)
- IpMan Chess 10+1 (i9-13700H) - 3543 (#13) (version 1.18 avx2-bmi2)
- IpMan Chess 5+0 - 3381 (#28) (version 1.8)
- CEGT 40/20 - 3516 (#10) (version 1.16)
- CEGT 40/4 - 3547 (#8) (version 1.15)
- CEGT 5+3 - 3530 (#9) (version 1.13.1)
The engine has been written from the ground up. In early versions it used a simple PeSTO evaluation, which was replaced by the Stockfish NNUE for a short time. Since version 0.7, Caissa uses it's own efficiently updated neural network, trained with Caissa self-play games using a custom trainer. In a way, the first own Caissa network is based on Stockfish's network, but it was much weaker because of the small data set used back then (a few million positions). Currently (as of version 1.18) over 12 billion newly generated positions are used. Also, the old self-play games are successively purged, so that the newer networks are trained only on the most recent games generated by the most recent engine, and so on.
The runtime neural network evaluation code is located in PackedNeuralNetwork.cpp and was inspired by nnue.md document. The neural network trainer is written completely from scratch and is located in NetworkTrainer.cpp, NeuralNetwork.cpp and other NeuralNetwork* files. The trainer is purely CPU-based and is heavily optimized to take advantage of many threads and AVX instructions as well as it exploits the sparse nature of the nets.
The games are generated with the utility SelfPlay.cpp, which generates games with a fixed number of nodes/depth and saves them in a custom binary game format to save space. The opening books used are either Stefan's Pohl UHO books or DFRC openings with few random moves played at the beginning.
- Hash (int) Sets the size of the transposition table in megabytes.
- MultiPV (int) Sets the number of PV lines to search and print.
- MoveOverhead (int) Sets move overhead in milliseconds. Should be increased if the engine loses time.
- Threads (int) Sets the number of threads used for searching.
- Ponder (bool) Enables pondering.
- EvalFile (string) Neural network evaluation file.
- EvalRandomization (int) Allows introducing non-determinism and weakens the engine.
- StaticContempt (int) Static contempt value used throughout whole game.
- DynamicContempt (int) Dynamic contempt value used in the opening/middlegame stage.
- SyzygyPath (string) Semicolon-separated list of paths to Syzygy endgame tablebases.
- SyzygyProbeLimit (int) Maximum number of pieces on the board where Syzygy tablebases can be used.
- UCI_AnalyseMode (bool) Enables analysis mode: search full PV lines and disable any depth constraints.
- UCI_Chess960 (bool) Enables chess 960 mode: castling moves are printed as "king captures rook".
- UCI_ShowWDL (bool) Print win/draw/loss probabilities along with classic centipawn evaluation.
- UseSAN (bool) Enables short algebraic notation output (FIDE standard) instead of default long algebraic notation.
- ColorConsoleOutput (bool) Enables colored console output for better readability.
- AVX-512 - Fastest, requires a x64 CPU with AVX-512 instruction set support. May not be supported on consumer-grade CPUs.
- BMI2 - Fast, requires a x64 CPU with AVX2 and BMI2 instruction set support. Supported by majority of modern CPUs.
- AVX2 - Fast, requires a x64 CPU with AVX2 instruction set support. May be faster than BMI2 on some older CPUs (e.g. Intel Haswell processors).
- POPCNT - Slower, requires a x64 CPU with SSE4 and POPCNT instruction set support. For older CPUs.
- Legacy - Slowest, requires any x64 CPU. For very old x64 CPUs.
- UCI protocol
- Neural network evaluation
- Syzygy and Gaviota endgame tablebases support
- Chess960 (Fischer Random) support
- Negamax with alpha-beta pruning
- Iterative Deepening with Aspiration Windows
- Principal Variation Search (PVS)
- Quiescence Search
- Transposition Table
- Multi-PV search
- Multithreaded search via shared transposition table
- Neural network evaluation
- (5x768→1024)x2→1 architecture
- effectively updated first layer
- manually vectorized code supporting SSE2, AVX2, AVX-512 and ARM NEON instructions
- clipped-ReLU activation function
- 8 variants of last layer weights selected based on piece count
- input features: absolute piece coordinates with horizontal symmetry, 11 king buckets
- Special endgame evaluation routines
- Custom CPU-based trainer using Adam algorithm
- Heavily optimized using AVX instructions, multithreading, and exploiting sparsity of the first layer input
- Network trained on data generated purely from self-play games
- Large Pages Support for Transposition Table
- Magic Bitboards
- Handling non-standard chess positions (e.g. 64 pieces on the board, etc.)
- Outstanding performance at ultra-short games (sub-second for whole game).
The projects comprises following modules:
- backend (library) - engine's core
- frontend (executable) - UCI wrapper for the backend
- utils (executable) - various utilities, such as unit tests, neural network trainer, self-play data generator, etc.
To compile for Linux just call make
in src
directory:
cd src
make -j
NOTE: This will compile the default AVX2/BMI2 version.
To compile for Linux using CMake:
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Final ..
make -j
NOTE: Currently, the project compiles with AVX2/BMI2 support by default.
There are three configurations supported:
- Final - final version, without asserts, etc.
- Release - development version with asserts enabled and with optimizations enabled for better performance
- Debug - development version with asserts enabled and optimizations disabled
To compile for Windows, use GenerateVisualStudioSolution.bat
to generate Visual Studio solution. The only tested Visual Studio version is 2022. Using CMake directly in Visual Studio was not tested.
NOTE: After compilation make sure you copy appropriate neural net file from data/neuralNets
directory to location where executable file is generated (build/bin
on Linux or build\bin\x64\<Configuration>
on Windows).