A Simple Chess Engine in Rust
This is a very simple (command-line only + single-threaded) chess engine written in Rust to explore chess engine algorithms and to actually learn the language. This is just be a fun side project with no real intent of making a chess engine that is in any way competetive. I just wanted to see if I could write a chess engine that I couldn't beat (I'm not that good ~1200-1300). It uses chess for move generation and board and game representation. The Chess Programming Wiki has been a great resource for learning how to do this along with The Rust Book.
Some of the algorithms for this engine are:
- NegaMax with Alpha-Beta pruning
- Iterative Deepening
- Null Move Pruning
- Check Extensions
- Quiescence Search
- Transposition Tables
- Zobrist Hashing
There are still a lot of things I'd like to improve upon:
- Adding UCI Protocol for it to play within UCI GUIs and against other chess engines
- Some kind of multi-threaded search to increase speed and depth
- A way to ponder so it's not sitting idle while the other player is making a move
- Time controls
- Better (any) memory handling... This can use a lot of memory
- Improving the way transposition tables are handled
- Better evaluation function. The evaluation function I used is really naive but does suprisingly well. Only piece values and position are currently used.
It's better to build a release version of the code instead of just using cargo run
❯ cargo build --release
Help:
❯ ./target/release/rad1-cli --help
Rad1 Chess Engine 0.2.1
Sam Foster <[email protected]>
A Simple Chess Engine in Rust
USAGE:
rad1-cli <SUBCOMMAND>
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
SUBCOMMANDS:
analyze Analyze a single position
help Prints this message or the help of the given subcommand(s)
play Play against the chess engine from terminal
To play against the engine in the terminal:
❯ ./target/release/rad1-cli play
To evaluate a specific position from a FEN representation
❯ ./target/release/rad1-cli analyze --fen "r3k2r/1p3pp1/p1p4p/3pP3/1PP5/P2P1P2/2qnKQ1P/8 b kq - 7 28"
1 - d2c4 = 145
2 - d2e4 = 224
3 - d2e4 = 234
4 - d2e4 = 237
5 - d2e4 = 32767
6 - d2e4 = 32767
7 - d2e4 = 32767
8 - d2e4 = 32767
Best move: d2e4
Size: 17779