- This is a chess bot I wrote in a single 969-tokens C# file as part of youtuber Sebastian Lague's Chess Coding Challenge.
- The challenge was: Given a chess framework, implement a chess AI under the limit of 1024 tokens only to battle it out against other participants' bots.
- Overall, I enjoyed participating very much, I learned a lot about chess programming, search algorithms and evaluation heuristics, and my bot did surprisingly well in the tournament (see results).
The objective of this challenge was to implement strong chess search and evaluation algorithms in a maximum of 1024 tokens of code, without the overhead of writing an entire chess framework. This limit was (probably) enforced for 2 reasons:
- Preventing participants from copying code from famous open source chess engines (for example: Stockfish)
- Encouraging participants to come up with creative ways of writing tiny chess AI algorithms, for example:
- Designing compression/encoding algorithms for big amounts of values like piece square tables
- Choosing between multiple search extension algorithms, pruning techniques and evaluation parameters (you can't fit'em all in 1024 tokens!)
I learned a lot about chess AI programming and I got a chance to apply my problem-solving techniques to overcome the token-limit problem, like:
- Using bit-manipulation to compress piece square tables (768 tokens) into 64-bit
ulong
s (96 tokens) - Using basic search algorithms like minimax and alpha-beta pruning
- Using dynamic programming techniques in transposition tables to reduce search time
Most chess bots consist of a Search function and an Evaluation function.
-
My Search function:
- Minimax search and alpha-beta pruning inside a negamax framework
- Quiescence search
-
My Evaluation function:
-
Techniques to reduce search time:
My bot ranked 117th out of 624 bots, sadly - but understandably - it wasn't mentioned in Sebastian's results video. Here is a screenshot from the video:
Tournament games played by all bots were published to this repo, I wrote a simple Python script to extract my bot's 64 games out of all games and analyze basic stats like wins/losses and color. Here are the results:
- If you just want to play against the bot, download and run the executable from here
- If you want to run the project in your IDE, you must have
.NET 6.0
, download the source code and openChess-Challenge.sln
- Sebastian Lague
- Organized the challenge, wrote the entire chess framework and its documentation
- Chess coding discord community
- Helped with code and guides, especially users
selenaut
andjw1912
for open-sourcing their code
- Helped with code and guides, especially users
- Chess programming wiki
- Very good hub of chess programming knowledge
- Yours truly
- Wrote
MyBot.cs
andPackingPST.cs
- Wrote