Add UCI chess engine support #5

Open
opened 2025-10-14 15:33:20 -06:00 by navan · 0 comments
Owner

Originally created by @navanchauhan on 9/15/2025

Summary

Implement Universal Chess Interface (UCI) support so the Swift engine can plug into popular chess GUIs.

Goals

  • Provide a compliant UCI command loop that mediates between GUI clients and the engine.
  • Teach the search layer to respect UCI time controls, depth limits, and reporting requirements.
  • Expose configurable UCI options while keeping the engine thread-safe.

Plan

  1. Protocol Analysis
    • Review the latest UCI specification and document mandatory/optional commands.
    • Define a Swift-friendly message model for uci, isready, position, go, stop, quit, etc.
  2. Engine Core Integration
    • Translate UCI position commands (FEN + move list) into engine state.
    • Ensure the search exposes principal variation, scores, nodes, and timing data.
  3. Command Dispatcher
    • Implement an async command loop that parses stdin, dispatches handlers, and serializes responses.
    • Maintain concurrency-safe shared state for ongoing searches and pending commands.
  4. Option Management
    • Add configurable UCI options (e.g., Hash, Threads, Contempt, Ponder).
    • Validate and apply updates at runtime, falling back to defaults when invalid.
  5. Search Loop & Timing
    • Honor go parameters (time controls, movestogo, depth, nodes, mate, infinite).
    • Implement stop, ponderhit, and ucinewgame semantics cleanly.
  6. Output Formatting
    • Emit spec-compliant info lines (depth, seldepth, score, nodes, nps, pv, hashfull).
    • Respond with bestmove (and optional ponder) when searches conclude.

Testing

  • Create integration harnesses that replay known UCI command transcripts.
  • Exercise the protocol against reference GUIs (e.g., CuteChess headless) in CI.
  • Add regression tests to verify timing accuracy and option handling.
*Originally created by @navanchauhan on 9/15/2025* ## Summary Implement Universal Chess Interface (UCI) support so the Swift engine can plug into popular chess GUIs. ## Goals - Provide a compliant UCI command loop that mediates between GUI clients and the engine. - Teach the search layer to respect UCI time controls, depth limits, and reporting requirements. - Expose configurable UCI options while keeping the engine thread-safe. ## Plan 1. **Protocol Analysis** - Review the latest UCI specification and document mandatory/optional commands. - Define a Swift-friendly message model for `uci`, `isready`, `position`, `go`, `stop`, `quit`, etc. 2. **Engine Core Integration** - Translate UCI `position` commands (FEN + move list) into engine state. - Ensure the search exposes principal variation, scores, nodes, and timing data. 3. **Command Dispatcher** - Implement an async command loop that parses stdin, dispatches handlers, and serializes responses. - Maintain concurrency-safe shared state for ongoing searches and pending commands. 4. **Option Management** - Add configurable UCI options (e.g., `Hash`, `Threads`, `Contempt`, `Ponder`). - Validate and apply updates at runtime, falling back to defaults when invalid. 5. **Search Loop & Timing** - Honor `go` parameters (time controls, movestogo, depth, nodes, mate, infinite). - Implement `stop`, `ponderhit`, and `ucinewgame` semantics cleanly. 6. **Output Formatting** - Emit spec-compliant `info` lines (depth, seldepth, score, nodes, nps, pv, hashfull). - Respond with `bestmove` (and optional `ponder`) when searches conclude. ## Testing - Create integration harnesses that replay known UCI command transcripts. - Exercise the protocol against reference GUIs (e.g., CuteChess headless) in CI. - Add regression tests to verify timing accuracy and option handling.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: navan/swift-chess-neo#5
No description provided.