thomasahle/sunfish
Sunfish: a Python Chess Engine in 111 lines of code
What it solves
Sunfish is a compact, open-source chess engine written in Python. It provides a simple and strong enough for casual play, while serving as a highly accessible platform for developers to experiment with search algorithms, evaluation functions, and deep learning in chess programming.
How it works
The engine uses the MTD-bi search algorithm (also known as C*) and incorporates classic chess engine optimizations. It employs Piece Square Tables for an efficiently updatable evaluation function and uses standard Python collections for clarity. A separate NNUE version is available, which combines a classical piece-square score with a trained neural residual, packing the entire network into a single Python integer for high-performance evaluation.
Who it’s for
It is designed for chess enthusiasts and developers who want a minimal, readable codebase to learn about chess engines or to build their own derivatives. It is also compatible with standard UCI GUIs and tournament tools.
Highlights
- Ultra-compact: The core engine takes up just 126 lines of code when compressed.
- UCI Compatible: Works with standard chess GUIs like Arena, Cute Chess, and PyChess.
- ** uma PyPy Support**: Optimized for the PyPy JIT interpreter, which can search up to 2.7x faster than CPython.
- NNUE Integration: Includes a small, certified neural network evaluation version (nnue_4k) that improves Elo rating over the classic version.
Related
- Project
- Project
- Project
- Project
- Project