Personal projectPython, python-chess

Dumbfish — a Chess Engine in Python

A UCI-compatible chess engine with single-threaded search and three-phase handcrafted position evaluation.

Dumbfish — a Chess Engine in Python

This project was my third-year coursework for the “Software Engineering” program at the CSIT, Chernyshevsky SSU, titled “Developing the Dumbfish Chess Engine Based on an Evaluation Function Using Positional Features and Three-Phase Interpolation”.

A UCI-compatible chess engine in Python — despite the name, it’s not that dumb: at the default search depth it plays around 1300 Elo (about 1800 on Lichess), and it obviously does better at greater depth.

The Problem

Ordinary hand-crafted chess evaluation engines use a linear combination of positional features, each with its own weight. But a feature’s ideal weight can depend on the stage of the game — for example, the king should stay safe in the opening but be centralized in the endgame.

The most primitive evaluation functions use a binary interpolation between the middlegame and the endgame — based on, say, the material left on the board. More advanced engines use an approach called interpolation: the final evaluation becomes a linear combination of two intermediate scores — middlegame and endgame — weighted by an interpolant.

Notice, though, that none of the approaches above account for the opening specifically. In the middlegame, pieces should generally be pushed into action (so to speak, “depth-first”), whereas the opening calls for prioritizing piece development and castling instead (“breadth-first”).

Dumbfish is, as far as I know, the first prototype chess engine with three-phase interpolation that distinguishes opening evaluations from middlegame ones. This lets it evaluate positions that fall between the extremes of a feature much more precisely, which in turn lets the engine pick opening plans far more accurately than comparable engines (Sunfish, for instance).

Architecture

Dumbfish implements a UCI-compatible chess engine in Python. It includes:

  • a basic UCI protocol (no time management or ponder-hit);
  • a transposition table with Zobrist hashing;
  • single-threaded search with alpha-beta pruning, iterative deepening, and a handful of heuristic optimizations;
  • three-phase handcrafted evaluation based on positional features and piece-square tables.

The project is structured like this:

  • main.pyEntry point
  • uci.pyUCI protocol handler
  • game.pyGame state management
  • search.pyIterative search
  • score.pyPosition evaluation (HCE)
  • tt.pyTransposition table with Zobrist hashing
  • pst.pyPST tables and evaluation data
  • config.pyEngine configuration

How to Run

git clone https://github.com/tolstovrob/dumbfish
cd dumbfish
pip install -r requirements.txt
python main.py

This starts the UCI loop — the engine can be plugged into any UCI-compatible interface (Arena, Cute Chess, etc.).

Lichess Integration

To play on Lichess, set the bot token and the path to the executable in config.yml.