# xboard-engine — a minimal CECP engine

A minimal CECP ("chess engine communication protocol", the protocol
spoken by xboard/WinBoard and understood by most chess GUIs) engine
built directly on the SAN Kit library. It **plays instantly**: no
search, no time management, no pondering — whenever it's asked to
move, it just asks the chosen move-selection strategy for one move
and plays it right away.

The strategy is picked with a command-line argument:

```sh
./xboard-engine eat     # default: best simple capture, else a plausible move
./xboard-engine ran     # a purely random legal move
./xboard-engine gtp     # the "Gillogly TECH program" strategy
./xboard-engine sc0     # Stanback Chess Program, internal variant
./xboard-engine sc1     # Stanback Chess Program, external variant
./xboard-engine -h      # usage / list of strategies
```

None of these are strong players — see `../../SAN_DOC/DIY` (and
`../../examples/13_search_strategies.c`) for how to plug in a real
one.

## Building

```sh
make
```

## Using it with a GUI

Any CECP-speaking GUI can drive it directly, for example:

```sh
xboard -fcp ./xboard-engine -fd .
xboard -fcp "./xboard-engine ran" -fd .          # pick a strategy
xboard -fcp ./xboard-engine -scp "./xboard-engine ran" -fd .   # engine vs engine
```

## Using it without a GUI

It just reads CECP commands from stdin and writes replies to
stdout, so you can drive it by hand too:

```
$ ./xboard-engine eat
xboard
protover 2
feature myname="SME-A (eat)" setboard=1 usermove=1 sigint=0 sigterm=0 colors=0 draw=0 analyze=0 variants="normal" done=1
new
force
usermove e2e4
go
move e7e5
usermove g1f3
move b8c6
quit
```

Moves are read and written in plain coordinate notation (`e2e4`,
`e7e8q` for a promotion, `e1g1` for castling) rather than SAN, since
that's what CECP itself uses.

## Protocol coverage

Implemented: `xboard`, `protover`, `new`, `setboard <FEN>`, `force`,
`go`, `usermove <move>` (a bare coordinate move sent without the
`usermove ` prefix is also accepted), `undo`, `remove`, `ping <n>`,
`quit`. The end of a game (checkmate, stalemate, the fifty-move
rule...) is announced with a standard `1-0`/`0-1`/`1/2-1/2 {...}`
line as soon as it's reached.

Everything else — time control (`level`/`st`/`time`/`otim`),
pondering (`hard`/`easy`), analysis mode, `post`/`nopost`, `hint`,
draw offers, colors, variants, and so on — is accepted and silently
ignored. This is a deliberately minimal demo engine built to show
how little code it takes to wrap the SAN Kit library in a working
CECP engine, not a competitive one.

## A note on the "instant move" design

Because it never thinks, this engine will happily play a losing
strategy's move immediately even when it's clearly not asked to
`go` yet — it only reacts to `force`/`go` to decide whether to reply
*automatically* after the opponent's move, exactly like a real CECP
engine, but it never spends any time on the move it does make. See
`xboard-engine.c` for exactly which commands are recognized; the
main loop is a single, deliberately short `while`/`if` chain that's
meant to be easy to extend (e.g. to add real time control or a
stronger strategy) rather than a complete implementation of the
CECP specification.
