What this book is
This book documents the design and implementation of the chess engine Rustic. It explains the engine’s structure, how its components work, and how they fit together. The engine is written in Rust, so this is the programming language used throughout the book. Code and examples are taken directly from a working release. Topics covered include:
- How to design a chess engine.
- Software engineering principles.
- Chess engine programming and algorithms.
- Code examples taken straight from the engine.
- Chess knowledge and its application in an engine.
- The Rust programming language, where necessary.
- Guidance on how to build and compile the engine.
- Testing methodology.
When developing your own engine, either in Rust or another programming language, this book provides a way (not the way) to accomplish this. The information in this book was gathered from many sources:
- Websites and technical articles
- YouTube videos
- Forum and newsgroup posts
- Computer science blogs
- Discussions written decades ago
- And, of course, my own knowledge as a software engineer
Listing every source I used would be nearly impossible. It would become an enormous list, especially considering that the internet is volatile. A source found in 2019 may not be available in 2021, or the information may have changed. Some people mentioned in the Rustic credits and on the “Further study” page also provide lots of information on chess programming. You may want to check out their work.
What this book is not
If you are hoping for a step-by-step tutorial, you are probably going to be disappointed. This book is not structured so that you can simply follow it from start to finish and end up with a perfectly working chess engine. This might be possible if you are using Rust and already have a lot of programming experience. Other programming languages may require different design and implementation decisions because not all languages support the same features, and similar features may not work the same way.
The goal of the book is to consolidate enough information in one place to be able to design and write a chess engine from scratch in any modern programming language. The book should provide you with a good foundation in chess engine programming. You will be able to research and implement ideas that are not (yet) described in these pages… or even try to implement your own ideas.
Because of this approach, the book is best used as both a learning resource and a long-term reference. Still, if you were hoping for a step-by-step tutorial, here are some excellent resources to help you get started. The links below were active at the time of writing.
Step-by-step tutorials:
- Programming a chess engine in C (Richard Allbert / Bluefever
Software)
- Bitboard chess engine in C (Maksim
Korzh)
- Chess engine in Java (Software Architecture &
Design)
- Java chess engine tutorial (Logic Crazy)
How to use this book
The best way to use this book is to read it once from beginning to end, to get a general overview of the topics involved in creating a chess engine. It does not matter if you don’t immediately understand everything. After reading the book, you can start designing and writing your own engine. This can be as simple as setting up the main() function, defining two constants for your engine’s name and version number, and printing those to the screen. At that point, your engine has reached the “Hello, world!” stage and you can continue from there. You can refer back to this book time and again when you reach each new topic.
There is also a “Further study” page in the book, referring to some good material to review. The tutorials above are no exception; even if you don’t want to create a chess engine by following a tutorial, those videos can still be valuable if you find one covering the topic you are working on.
Code consistency: book vs. engine
Parts of this book were written during the development of Rustic Alpha 2 and 3, while later sections were written during the development of Rustic 4. Because the engine evolves continuously, some code examples in the book may differ from the latest engine version because the engine continued evolving afterward. If you encounter outdated examples, you can open an issue in the Codeberg repository.