A while ago I started getting into chess programming, writing a legal move generator in JS as my final project for school. Recently I started to pick up chess programming again and decided to write a full engine in Zig. I'm very much a beginner and I haven't worked with lower-level languages before, so this project is a challenge for me both in respect to the language and to chess programming. Nevertheless I'm at a point where I want to post about it here. All of the source code is based on the chess programming wiki, there is no novelty in regards to heuristics or algorithms but the source code is handwritten by myself.
I haven't identified the engine's current elo rating yet but it manages to win a bit more than half of games out of 1000 against Stockfish 1800 Elo.
What's included:
Board Representation
- Bitboards for piece sets
- Incremental make/unmake
- Null move make/unmake
- Incremental Zobrist hashing
- FEN parsing
- Compact 16-bit move encoding
Search
- Negamax alpha-beta
- Iterative deepening
- Aspiration windows
- Principal variation tracking
- Quiescence search with SEE Pruning, standpat
- Transposition table
- TT exact / lower-bound / upper-bound node types, always replace
- Hash move ordering
- Null move pruning
- Late move reductions
- PVS-style zero-window search on later moves
- Check extension
- Mate score normalization for TT storage
- Basic time-based stop check during node polling
Move Ordering
- Hash move
- Queen promotions prioritized
- Capture ordering with MVV-LVA
- SEE-based capture discrimination
- Killer heuristic
- History heuristic
- Selection-sort style pick-next move loop
Evaluation
- PeSTO-style tapered PST evaluation
- Middlegame / endgame interpolation by phase
You can find the source code here:
https://github.com/timojokinen/haraki-zig
I would be happy to hear the community's thoughts.