Sporkfish is a Python-based chess engine. Chess programming techniques, although numerous, are not always well-documented. This project aims to bridge that gap by offering clear, working, and accessible code, providing a resource for developers interested in understanding and implementing chess engine algorithms.
See any of the following sections to quickly setup your development environment.
Prerequisites:
Instructions:
Docker Desktop
is up and running.Dev Containers: Rebuild Container
[Dev Container]
in the URL bar as well as on the status bar bottom left of the window to indicate your setup is complete.Prerequisites:
Instructions:
https://www.jetbrains.com/help/pycharm/connect-to-devcontainer.html
Prerequisites:
Instructions:
Create
.2-core
(this can be changed later if you require more power).An active internet connection will be required for this. This will also use up your monthly allowance for Github codespace.
Prerequisites:
After cloning the repository, from the root directory, run:
docker pull kylchiu/sporkfish-dev:latest
docker build -t kylchiu/sporkfish-dev:latest .
docker run -it kylchiu/sporkfish-dev:latest
This generates an interactive bash shell for you to run the program in.
Check out the bot on lichess here! To run the bot, create a file in the root directory named api_token.txt
. Add your Lichess bot API token. Then run:
python3 -O main.py
Once you create a game via your bot account, the bot will automatically play. We currently do not support simultaneous games.
Functional library: encourage free functions whilst avoiding mutable data unless the task specifically and inherently demands it (e.g. statistics, transposition table, board state).
Well documented: classes should always have docstrings. Where the code is complex, additional inline comments should be made.
Search:
Move ordering:
Evaluation:
Communication:
Gentle introduction to how to set up a chess bot by Sebastian Lague
How to improve a chess bot by Sebastian Lague
Introduction to Minimax and Alpha-Beta Pruning:
Iterative Deepening Search:
To run all tests (excluding slow tests):
python3 -m pytest -v
You may also run a specific test class or function, e.g.:
python3 -m pytest tests/test_searcher.py::TestMvvLvaHeuristic -sv
Slow tests are not run on CI. Developers should run these before raising PRs by doing (this can be very slow, so please be patient):
python3 -m pytest -sv --runslow
This may or may not work depending if Copilot is happy on that day. Simply ask Copilot to generate your class with Sphinx docstrings. If that does not work, you could try:
__init__
function. This can be done using Ctrl + Shift + 2
(Windows, Linux) or Command + Shift + 2
(Mac). Add ":param:" in your string if it isn't auto generated.