A Rust-based chess engine implementing the Universal Chess Interface (UCI) protocol with advanced search algorithms and bitboard-based performance optimizations.
Clockwork is a modular chess engine written in Rust that features:
- Bitboard-based board representation for efficient move generation and evaluation
- Alpha-beta pruning with quiescence search for effective tree pruning
- UCI protocol implementation for compatibility with popular chess GUIs
- Magic bitboard move generation for fast sliding piece attack calculations
- Iterative deepening search with configurable depth and time limits
- Position evaluation using material and piece-square tables
The project is organized into three main crates:
Core chess logic and algorithms:
- Board representation using bitboards
- Move generation for all piece types
- Position evaluation with piece-square tables
- Search algorithms (alpha-beta, iterative deepening)
- FEN notation parsing and generation
- Game state management (check, checkmate, stalemate)
Universal Chess Interface implementation:
- UCI command parsing and response generation
- Engine configuration and parameter management
- Integration with chess GUIs and analysis tools
Main executable that ties everything together:
- Initializes magic bitboards
- Creates and runs the UCI engine
- Entry point for the chess engine
- 64-bit bitboards for efficient piece placement tracking
- Separate bitboards for each piece type and color
- Fast attack generation using magic bitboards
- Optimized move generation algorithms
- Alpha-beta pruning with move ordering
- Quiescence search to avoid horizon effect
- MVV-LVA (Most Valuable Victim - Least Valuable Attacker) capture ordering
- Configurable search depth and time limits
- Iterative deepening for better time management
- Material evaluation using standard piece values
- Piece-square tables for positional evaluation
- Separate tables for each piece type
- Endgame detection for insufficient material
- Standard UCI commands:
uci,isready,ucinewgame,position,go,stop,quit - Position setup from FEN notation or starting position
- Move sequence application
- Search parameter configuration (depth, time, nodes)
- Rust 1.70+ (recommended to use rustup)
- A chess GUI that supports UCI (optional, for playing against the engine)
Clone the repository and build the project:
git clone https://github.com/MasterBrian99/clockwork.git
cd clockwork
cargo build --releaseAfter building, you can run the engine directly:
cargo run --releaseOr run the release binary:
./target/release/clockworkRun the test suite:
cargo test- Configure your chess GUI (Arena, Fritz, SCID, etc.) to use UCI engines
- Point it to the
clockworkexecutable - Start a new game or analysis session
The engine supports the following UCI commands:
uci- Engine identificationisready- Check if engine is readyucinewgame- Start a new gameposition [startpos|fen] [moves ...]- Set board positiongo [parameters]- Start searchingdepth <n>- Search to specific depthmovetime <ms>- Search for specific timenodes <n>- Search specific number of nodesinfinite- Search indefinitely
stop- Stop current searchquit- Exit engine
uci
id name Castono Chess Engine
id author Claude Code
uciok
isready
readyok
position startpos moves e2e4 e7e5
go depth 4
bestmove c7c5 info depth 4 score cp 20 nodes 12345
quit
Boardstruct with bitboard representationPiece,PieceType,Color, andSquareenums/structs- Methods for piece placement and retrieval
Positionstruct maintaining full game state- FEN notation parsing and generation
- Move execution and undo functionality
- Game state detection (check, checkmate, stalemate)
- Efficient move generation for all piece types
- Magic bitboard attack calculations
- Legal move validation
- Alpha-beta pruning implementation
- Quiescence search
- Iterative deepening
- Move ordering heuristics
- Material and positional evaluation
- Piece-square tables
- Endgame detection
- UCI protocol implementation
- Command parsing and response generation
- Engine state management
- 64-bit operations for efficient piece tracking
- Magic bitboards for fast sliding piece attacks
- Precomputed attack tables for knights and kings
- Alpha-beta pruning reduces search tree size
- Move ordering improves pruning effectiveness
- Quiescence search prevents tactical blunders
- Iterative deepening provides better time management
- Compact move representation (32-bit)
- Efficient board state storage
- Minimal allocation during search
The modular structure makes it easy to extend the engine:
- New evaluation terms: Add to
chess-core/src/evaluate.rs - Search improvements: Modify
chess-core/src/search.rs - UCI extensions: Update
uci/src/lib.rs - Performance optimizations: Focus on
chess-core/src/movegen.rs
The project includes comprehensive unit tests for:
- Move generation correctness
- Position manipulation
- Search algorithm behavior
- UCI command handling
Run tests with cargo test and add new tests when implementing features.
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- The Rust chess engine community for inspiration and best practices
- UCI protocol specification for standardization
- Magic bitboard algorithms for efficient move generation