adam-mcdaniel / chess-engine

A dependency-free chess engine♟️ library built to run anywhere.
https://adam-mcdaniel.github.io/chess-engine/docs/book/index.html
MIT License
422 stars 30 forks source link

Implement UCI protocol #5

Open tom-sherman opened 3 years ago

tom-sherman commented 3 years ago

https://en.m.wikipedia.org/wiki/Universal_Chess_Interface

https://www.shredderchess.com/download.html

As this is crate is no_std, the first step would be to implement a message parser and state machine with an API to send commands to the engine. This API can then be used to wire up to stdin/stdout for chess GUIs for example.

tom-sherman commented 3 years ago

I've whipped up a potential state diagram for the ICU engine, transitions are denoted with gui=* when they are transitions that are to be made on receipt of a command and engine=* for commands to be sent by us to the GUI as a side effect of a transition:

mermaid.js src ```mermaid stateDiagram-v2 [*] --> Ready: gui=uci Ready --> Identifying: engine=id note right of Ready Identify itself with the engine name, author, and options. Finally sending the uciok command. end note Identifying --> Idle Idle-->[*]: gui=quit # Idle --> Idle: gui=debug Idle --> Syncing: gui=isready Idle --> Configuring: gui=setoption Configuring --> Configuring: gui=setoption Configuring --> Syncing Syncing --> Idle: engine=readyok Idle-->Playing: gui=ucinewgame Idle-->Playing: gui=position Playing-->Playing: gui=position Playing-->Searching: gui=go Searching-->Playing: gui=stop Searching-->Playing: engine=bestmove ```

Link

tom-sherman commented 3 years ago

Thinking a little more, ICU might be more of a frontend (like web or terminal), than something that's built into the engine itself.