A C-based chess engine demonstrates how far you can compress game logic while maintaining competitive play against weaker opponents.
sameshi: A 2KB Chess Engine That Plays at 1200 Elo

When most chess engines sprawl across hundreds of thousands of lines of code, sameshi takes the opposite approach. This compact C implementation packs a working chess engine into just 2KB of source code while achieving approximately 1200 Elo rating against human players.
How Small Can a Chess Engine Get?
The project demonstrates that core chess logic can be compressed dramatically. The main header file sameshi.h weighs in at only 1.95KB and includes:
- A 120-cell mailbox board representation
- Negamax search with alpha-beta pruning
- Material-only evaluation function
- Capture-first move ordering
- Full legal move validation (check, mate, stalemate)
What's notably absent are the complex rules that make chess challenging: no castling, no en passant captures, no pawn promotion, and no draw detection for repetition or the 50-move rule. These omissions represent about 90% of chess's rule complexity while preserving the game's fundamental decision-making.
Performance Benchmarks
The engine's strength was measured through 240 games against Stockfish at levels 1320-1600, using fixed depth 5 search and a 60-ply maximum. The results place sameshi at approximately 1170 Elo with a 95% confidence interval of 1110-1225.
This performance is impressive for several reasons:
- Rule constraints: The engine plays with a severely limited rule set
- Shallow search: Fixed depth 5 is relatively shallow for modern engines
- Simple evaluation: Material-only evaluation ignores positional factors
For context, 1200 Elo represents a solid club player who understands basic tactics and can beat casual players consistently. The engine achieves this despite its extreme size constraints.
Technical Implementation
The codebase consists of just two files:
main.c(93.5% of the project): Contains the core engine logicMakefile(6.5%): Build configuration
The author, datavorous, has actively optimized the code for size, with the latest commit specifically noting "trimmed down further by making expressions more compact." This suggests ongoing refinement to squeeze every byte while maintaining functionality.
Why Build Such a Small Engine?
Projects like sameshi serve multiple purposes in the programming community:
Educational Value: Understanding how to compress complex logic teaches efficient coding practices and algorithm optimization.
Demoscene Influence: The project fits within the demoscene tradition of creating impressive technical achievements within extreme constraints.
Minimalism as Art: There's inherent beauty in expressing complex ideas with minimal code—a form of digital minimalism.
Benchmarking: It provides a baseline for understanding what's essential in chess engine design versus what's optional.
Limitations and Trade-offs
The extreme size constraint creates obvious limitations:
- No special moves: Castling and en passant are fundamental chess tactics
- No promotion: Pawns can never become queens or other pieces
- No draw detection: The engine won't recognize drawn positions
- Shallow search depth: Fixed depth 5 limits strategic planning
These constraints mean sameshi plays a simplified version of chess rather than the full game. However, the core mechanics—piece movement, check detection, and basic search—remain intact.
The Broader Context
Chess engines have evolved dramatically since the days of early programs like Chess 0.5 (1977) or even Deep Blue (1997). Modern engines like Stockfish, Leela Chess Zero, and AlphaZero use neural networks, massive opening books, and sophisticated evaluation functions spanning millions of lines of code.
Against this backdrop, sameshi represents a fascinating counterpoint: proof that even in 2024, a chess engine can be tiny yet functional. It's a reminder that sometimes constraints breed creativity, and that complex problems can often be solved with surprisingly simple solutions.
Getting Started
The project is open source and available on GitHub. The codebase is written in standard C and includes a Makefile for compilation. While the engine is primarily a demonstration project rather than a production chess program, it serves as an excellent starting point for understanding chess engine fundamentals.
For developers interested in game AI, constraint programming, or just appreciating elegant code, sameshi offers a compact, well-documented example of how much functionality can fit into a tiny footprint.
The source code is available on GitHub for anyone interested in exploring the implementation details or contributing to this minimalist chess engine.

Comments
Please log in or register to join the discussion