World's Worst Chess Engine
I challenged myself to write a rudimenatary chess engine in four hours. That initial challenge was a qualified success. The resulting executable is under 1000 lines of code including comments, and under 64K compiled (on a Macbook).
Here's what's missing to make it really Chess:
- Pawn promotion
- En passant
- Castling
- Draw detection
- Checkmate detection
Here's what's very basic:
- No player input (plays only with itself)
- No understanding of openings
- No understanding of end game
- No look-ahead
- Trivial position evaluation (avoid check and min-max the point value of pieces remaining on the board)
- Selects randomly among moves with equal position evaluations
- No clock
- Non-standard move notation
- ASCII board render (upper case is White, lower case is Black, a "." indicates an empty black square.)
Known bugs:
- Inverted numbering of board ranks
- Black square display algorithm doesn't properly alternate ranks
- Random number generator is not seeded; all runs are the same
- On its first move a pawn will jump over an intervening piece to move two squares
I gave myself this challenge after answering two chess-related questions on Quora. The first was whether an employer should be impressed that a candidate wrote a chess engine. The second was what's the next-worst chess engine after a "random mover."
The bugfixes branch (https://github.com/cyberabi/wwce/tree/bugfixes) has incremental improvements to wwce to address the issues called out above. The main branch has the original 4 hour project. Don't code like this. MIT License. Have fun!
Chris Burke chris@cyberabi.com 01/25/2023