Skip to content

Make CMHMEngine2 UCI Compliant #53

@Phillyclause89

Description

@Phillyclause89

Title: Make CMHMEngine2 UCI Compliant

Background:
CMHMEngine2 currently speaks only our internal command format. To allow integration with standard chess GUIs (Arena, SCID, Cute Chess, etc.) and external tools (e.g. e-mail-based tournaments, remote engine tournaments), we need to implement the Universal Chess Interface (UCI) protocol.

Goals:

  • Enable seamless communication between CMHMEngine2 and any UCI-aware front-end.
  • Maintain robust testing and documentation so future contributors can extend or debug UCI handling.

Tasks

1. Specification & Research

  • Review the official UCI protocol specification (e.g. backscattering.de/chess/uci/uci.txt).
  • Identify all mandatory commands (uci, isready, ucinewgame, position, go, stop, quit).
  • List optional but common commands (e.g. debug, setoption) and decide which to support initially.

2. Core Command Implementation

  • Implement uci handshake:

    • Engine prints ID and “uciok” when seeing uci.
    • Handle isready → print “readyok”.
    • Respond to ucinewgame by resetting internal state.
  • Parse position command:

    • Support position startpos [moves …].
    • Support position fen <FEN> [moves …].
  • Parse and execute go subcommands:

    • go movetime <ms>, go depth <d>, go nodes <n>, etc.
    • Send best move via bestmove <move> [ ponder <move>].
  • Handle stop (early termination) and print current best move.

  • Handle quit clean shutdown.

3. Optional / Extended Features

  • Support setoption name <name> value <value> for engine tuning.
  • Support ucinewgame full reinitialization (clearing transposition tables, Q-table, etc.).
  • Add debug on|off for verbose logging.

4. Testing & Validation

  • Write unit tests for each parser function (one per command).

  • Simulate UCI session in tests (feed a sequence of commands, assert outputs).

  • Manual integration tests with at least two GUIs:

    • Arena
    • SCID or Cute Chess

5. Documentation

  • Update README with a “UCI Usage” section: example CLI session.
  • Document all supported setoption parameters.

Acceptance Criteria

  • CMHMEngine2 prints the correct UCI handshake and acknowledges readiness.
  • All mandatory UCI commands are parsed and executed correctly.
  • Engine returns valid bestmove under each go mode tested.
  • CI pipeline runs parser/unit tests and they all pass.
  • README clearly shows how to launch CMHMEngine2 from a UCI-compatible GUI.

Additional Resources for UCI in Python Engines

To help you dive deeper into the Universal Chess Interface and see practical Python implementations, here’s a curated list of specifications, library documentation, tutorials, and community Q&A threads:

Official UCI Specifications

  • UCI Protocol Specification (official text file by Rudolf Huber & Stefan Meyer-Kahlen): the definitive description of every mandatory and optional command in UCI ([Gist]1)
  • UCI History & Design on Wikipedia: background on protocol origins, design goals, and adoption timeline ([Wikipedia]2)

Python Libraries & Example Engines

  • python-chess UCI/XBoard module: comprehensive docs for using and embedding UCI engines in Python (including chess.uci.Engine, uci(), isready(), etc.) ([python-chess.readthedocs.io]3)
  • Disservin/python-chess-engine on GitHub: a minimal UCI-compatible engine implemented with python-chess, complete with alpha-beta search and move ordering ([GitHub]4)
  • Stockfish Discussions: UCI code examples: real-world examples of sending commands to and reading responses from Stockfish via stdin/stdout ([GitHub]5)

Tutorials & Articles

  • “How do I implement UCI in my Python chess engine?” (Chess StackExchange): step-by-step community answers on parsing and responding to UCI commands ([Chess Stack Exchange]6)
  • Writing a UCI Client in Java by André Inc: while in Java, this guide breaks down protocol flows in a language-agnostic way that’s directly applicable to Python ([andreinc]7)

Community Q&A & Troubleshooting

  • “How can I build a chess UCI computer in Python?” (Stack Overflow): detailed answers on wiring up Python code to the UCI protocol for Lichess and GUIs ([Stack Overflow]8)
  • Reddit r/chess: modifying Python engine for UCI: peer discussion on the key implementation pitfalls and deployment considerations ([Reddit]9)
  • Chessprogramming.org: UCI article: in-depth protocol overview plus historical notes and links to variant protocols (USI, UCCI) ([chessprogramming.org]10)

Metadata

Metadata

Labels

enhancementNew feature or request

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions