Skip to content

kelseyde/calvin-chess-engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

release lichess-badge

Calvin is a superhuman chess engine written in Java.

It features a a traditional alpha-beta search algorithm paired with an NNUE evaluation function.

The NNUE neural network was trained using bullet on a dataset of 950 million positions taken from the Leela dataset, that I re-scored using Calvin's own search and evaluation. The network architecture is (768->512)x2->1.

Calvin is rated roughly 3224 elo (~106th place) on the Computer Chess Rating Lists leaderboards, and is currently playing on Lichess.

My aim with this project was to combine my passion (playing mediocre chess) with my profession (writing mediocre code). My secondary goal was to learn about chess programming. I have certainly learned a great deal, and I hope that my code is well-documented so that first-time readers can learn too. If you find some information is missing or poorly explained, don't hesitate to let me know!

How to Play

Like most engines, Calvin does not implement its own user interface. Instead, it communicates using the UCI protocol, meaning it can either be used directly from the command line, or via any popular chess GUI, such as Arena Chess, Banksia or Cute Chess.

To run Calvin locally, you will need Java (minimum Java 17) installed on your machine. The binary calvin.jar can be downloaded from the Releases section. Start up Calvin by executing the command:

java --add-modules jdk.incubator.vector -jar calvin-chess-engine-4.0.1.jar

From there, use the "help" option or refer to UCI documentation for further information on available commands.

Strength

The table below tracks the strength of previous Calvin releases, both on the CCRL leaderboards and on Lichess.

Version Release date Estimated Lichess CCRL Blitz CCRL Rapid
4.2.0 2024-10-05 3300 - - -
4.2.0 2024-09-19 3230 - - 3224
4.1.0 2024-09-04 3150 ~2850 3171 3161
4.0.0 2024-07-30 3000 ~2700 3011 3029
3.4.0 2024-05-19 2500 ~2580 - 2492
3.3.0 2024-05-10 2450 ~2550 2453 -
3.2.0 2023-12-09 2250 ~2400 2233 -
3.1.0 2023-12-05 2220 ~2390 - -
3.0.0 2023-12-02 2200 ~2380 - -
2.6.2 2023-11-12 2175 ~2300 2173 -

Features

Calvin features a pretty traditional chess engine architecture. The engine can broadly be split into three parts: Move Generation, Search, and Evaluation.

Move Generation

Every chess engine requires an internal board representation, in order to track the position of the pieces, the move history, and so on. From there, for any given chess position the engine needs to be able to generate legal moves for that position, to be used during exploration of the game tree during search. As with everything chess-engine-related, the faster the movegen the better!

Search

The search algorithm is all about exploring the possible positions in the game tree, in the most efficient manner possible. To achieve this Calvin uses a classical alpha/beta negamax algorithm.

Search enhancements

Pruning, reductions, extensions

Move ordering

Time Management

  • Hard/soft time bounds
  • Best move stability scaling
  • Score stability scaling
  • Node TM scaling

Communication

  • Calvin communicates using the Universal Chess Interface (UCI) protocol.
  • Pondering, where the engine thinks on the opponent's move. Can be disabled using the 'Ponder' UCI option.
  • Hash size and number of search threads are also configurable via UCI.
  • Calvin is connected to Lichess where he plays regularly in the engine pool: https://lichess.org/@/Calvin_Bot

Evaluation

For any given chess position, the engine needs a method of obtaining an estimate of how good the position is for the side to move. Chess engine evaluation mechanisms can be split into two camps: traditional Hand-Crafted Evaluation (HCE), and Efficiently Updatable Neural Networks (NNUE). Since version 4.0.0, Calvin has switched to a neural-net based eval.

The neural network was trained using the excellent bullet trainer on a dataset of 950 million positions taken from the Leela dataset, that I re-scored using Calvin's own search and evaluation. The network architecture is (768->512)x2->1.

Special Thanks To...

  • The Chess Programming Wiki - A brilliant resource for all chess engine programmers, this wiki has been my go-to reference for every new topic.
  • The kind folks in the Engine Programming Discord server, who were very helpful for answering my various questions related to NNUE implementation.
  • The TalkChess forums - The home for chess engine geeks to talk about geeky chess engine stuff.
  • Other engines - I have drawn inspiration from countless others' engines, including but not limited to: Chess Coding Adventure (whose Youtube video inspired me to write my own engine); Stockfish (the queen of all engines); Leorik (whose author keeps an excellent devlog on the TalkChess forum); Lynx (my frequent Lichess rival); Rustic, Simbelyne and Mantissa (who taught me that Rust is Cool); and many others.

If you would like to contribute, or just talk about chess/chess programming, get in touch!