A chess library that supports Chess960 and is decently fast enough.
- Chess960 Support: Full support for Chess960 (Fischer Random Chess) with specialized castling rules
- Fast Move Generation: Optimized move generation using precomputed attack tables and magic bitboards
- Zobrist Hashing: Efficient position hashing for transposition tables and repetition detection
- Perft Testing: Built-in perft testing framework for performance measurement
- UCI Compatibility: Can operate in UCI mode for integration with chess GUIs
- Extensive API: Comprehensive chess position representation with all standard chess features
The library uses CMake and requires C++17. To build:
mkdir build && cd build
cmake ..
cmake --build .The build produces:
- A static library
libchesslib.a - Test executables:
test_normal,test_chess960,NonImportantTests,perft_example
#include "position.h"
#include "printers.h"
#include <iostream>
using namespace chess;
int main() {
Position pos;
// Set up standard starting position
pos.setFEN(Position::START_FEN);
// Print the position
std::cout << pos << std::endl;
// Generate all legal moves for white
Movelist moves;
pos.legals(moves);
std::cout << "Legal moves for white: " << moves.size() << std::endl;
return 0;
}Move move = pos.parse_uci("e2e4");
pos.doMove(move); // Execute the move
std::cout << pos << std::endl;Build the existing perft_example executable, then run a depth-6 perft with one
thread from the repository root:
cmake --build build --target perft_example
./build/perft_example --depth 6 --threads 1On Windows (Release, with multi-configuration generator such as Visual Studio):
cmake --build build --config Release --target perft_example
.\build\Release\perft_example.exe --depth 6 --threads 1This project is licensed under the GNU General Public License v3.0. See the LICENSE file for details.
- Stockfish: The enums, structures, and Move class in
types.hare derived from Stockfish and are included under the GNU GPLv3 license. - chess-library: References to the chess-library project (MIT license) are for documentation purposes.
The documentation is available in the doc directory and can also be generated using Doxygen.
Contributions are welcome! Please feel free to open issues or submit pull requests.
For questions or support, please open an issue on the GitHub repository.