Chess Bevy
Chess GUI
Module Summary
- Built a desktop chess GUI using
Bevy. - Uses a custom chess engine library,
chess_core, based on bitboards for game logic and state management. - Designed as an interactive interface layer over a full rules-compliant chess core.
Technical Challenges
- Managing asynchronous communication with
Stockfishvia theUCIprotocol while keeping the GUI responsive. - Parsing and synchronising real-time engine evaluation updates without desynchronising game state.
- Mapping raw engine evaluation scores into meaningful move quality categories (Best Move → Blunder).
- Maintaining strict synchronisation between GUI state and
chess_coreto prevent board desyncs. - Handling complex chess rules (castling, en passant, promotion) without duplicating logic in the GUI layer.
- Preventing illegal user interactions while keeping the interface responsive.
- Ensuring legal-move highlighting stays consistent with engine-validated state per frame.
- Implementing undo/redo functionality with support for branching move paths.
- Preventing history corruption when users diverge from existing move timelines.
- Designing clear and non-intrusive visual feedback for moves and evaluations.
- Handling rapid user interactions (fast moves, undo spamming) without UI instability or flickering.
Engine Integration (UCI)
- Integrated
Stockfishvia theUCIprotocol for move analysis. - Retrieves best moves and evaluation scores after each player move.
- Uses engine output to classify player moves by quality (Best Move → Blunder).
- Drives an evaluation bar that updates after every move.
Gameplay / Rules Environment
- All moves are validated through the underlying chess engine (preventing illegal states in UI).
- Legal moves displayed when selecting a piece.
- Full Support for:
- Castling (with rights tracking).
- En passant captures.
- Move history consistency across special moves.
Move System
- Undo and redo functionality implemented via engine-backed move history.
- Maintains consistent board state across navigation.
- Tracks and restores full game state per move (including special rule state).
UI Features
- Highlights last move played on the board.
- Shows legal move indicators for selected pieces.
- Displays engine evaluation bar in real-time.
- Shows move classification (from engine evaluation) on the last moved piece.
Board Initialisation
- Board initialised using FEN strings.
- Debug overlays available:
- Bitboard visualisation (Per-piece-per-player).
- Attack square visualisation.
- En passant square state.
Current Limitations
- Pawn promotion partially implemented: only allows promotion to queen currently.
Chess Core
Module Summary
- Low-level chess engine library written in
Rust. - Designed for performance and future extensibility (e.g. full engine implementation).
- Uses bitboards as the primary representation for board state and move computation.
Technical Challenges
- Designing a full chess board representation using only
u64bitboards. - Encoding 12 piece sets efficiently while keeping operations cache-friendly.
- Balancing low-level bitwise control with maintainable abstractions.
- Structuring the library for future extensibility (e.g. full engine integration).
- Implementing move generation using bitwise operations instead of per-tile iteration.
- Ensuring deterministic and consistent move generation across all board states.
- Building a move history system which supports undo/redo as well as branching timelines.
- Ensuring full reproducibility of game state from historical position.
- Handling divergence logic without corrupting or duplicating history.
- Synchronising all state components (castling rights, en passant, counters) across history traversal.
Board Representation
- Board state represented using 12 bitboards (piece_type × player count).
- Each bitboard is stored as a
u64for compact and fast operations. - Supports fast bitwise operations for:
- Move generation.
- Occupancy checks.
- Path clearance validation.
- Central
Boardstruct maintains full game state:- Piece bitboards.
- En passant square.
- Castling rights per player.
- Active player.
- Half-move and full-move counters.
- Move history system.
Move Generation and State Logic
- Move validation built around bitboard operations rather than per-tile iteration.
- Efficient checks for legal movement using bit masking.
- Supports special rule handling (castling, en passant) at engine level.
- Ensures UI and engine remain synchronised through strict state control.
Move History System
- Implements full move history tracking with support for:
- Undo.
- Redo.
- Branching move paths.
- Key design features:
- Detects divergence from existing move timeline.
- Clears invalid future history when a new branch occurs.
- Maintains an index pointer into history for navigation.
- Each history entry stores:
- Move data.
- Captured piece (if any).
- En passant state at time of move.
- Castling rights snapshot.
- Ensures:
- Accurate rollback of full game state.
- Consistency of special rule state across history traversal.