Moonfish is a didactic Python chess engine designed to showcase parallel search algorithms and modern chess programming techniques. Built with code readability as a priority, Moonfish makes advanced concepts easily accessible providing a more approachable alternative to cpp engines.
The engine achieves approximately ~2000 Elo when playing against Lichess Stockfish bots (beats level 5 and loses to level 6) and includes comprehensive test suites including the Bratko-Kopec tactical test positions.
- Python 3.10
Install the python library:
From python:
You can also call the CLI, the CLI works as an UCI Compatible Engine:
You can also run it as an API:
Then send a request:
- Alpha-Beta Pruning - Negamax with α-β cutoffs
- Lazy SMP - Shared memory parallel search utilizing all CPU cores
- Layer-based Parallelization - Distributing work at specific search depths
- Null Move Pruning - Skip moves to detect zugzwang positions
- Quiescence Search - Extended search for tactical positions
- PeSTO Evaluation - Piece-square tables (PST) with tapered evaluation. Using Rofchade's PST.
- Transposition Tables - Caching to avoid redundant calculations
- Move Ordering - MVV-LVA (Most Valuable Victim - Least Valuable Attacker)
- Syzygy Tablebase support for perfect endgame play
- Opening Book integration (Cerebellum format)
- UCI Protocol - Compatible with popular chess GUIs
- Web API - RESTful interface for online integration
- Lichess Bot - Ready for deployment on Lichess.org
| --mode | Engine Mode | uci | uci, api |
| --algorithm | Search algorithm | alpha_beta | alpha_beta, lazy_smp, parallel_alpha_beta_layer_1 |
| --depth | Search depth | 3 | 1-N |
| --null-move | Whether to use null move pruning | False | True, False |
| --null-mov-r | Null move reduction factor | 2 | 1-N |
| --quiescence-search-depth | Max depth of quiescence search | 3 | 1-N |
| --syzygy-path | Tablebase directory | None | Valid path |
We welcome contributions, feel free to open PRs/Issues! Areas of interest:
- New search algorithms
- Improved evaluation functions
- Time constrained search (e.g. find the best move in 40s)
- Additional test positions
- Github CI testing
- Different evaluation functions
- Neural Net integration
- Performance benchmarking on different hardware
- Improving caching
- Chess Programming Wiki
- python-chess library
- Lazy SMP Algorithm
- UCI Protocol Specification
- Rofchade
- THE BRATKO-KOPEC TEST RECALIBRATED
MIT License - see LICENSE file for details.
.png)


