# SME (SAN Kit Minimal Engine)

Minimal CECP engine based on SAN Kit.

## How `ChooseMove()` works

No command-line strategy selection this time — there's only one
built-in algorithm, in `ChooseMove()`:

1. **Mate in one.** `SANGenMoves()` itself already flags every
   candidate move with `mf_chmt` whenever playing it would
   checkmate the opponent (`SANMLScanMate()` in `sanmlm.c`, which
   `SANGenMoves()` always calls). So this step needs no search at
   all: it just scans the already-generated list for that flag.

2. **Avoid a mate-in-one reply.** For every candidate move, this
   plays it with `SANExecute()` (the lightweight, history-free
   primitive `SANEnumerate()` itself uses — not `SANPlayMove()`,
   which would pollute the *real* game history with moves being
   tried out rather than actually played), regenerates the
   opponent's replies with `SANGenMoves()` — which again come back
   pre-flagged for any mate-in-one of theirs — checks whether one
   exists, and undoes the trial move with `SANRetract()`. This is a
   plain one-ply-deeper safety check, not a real search: it only
   ever looks at the two half-moves directly ahead. Each depth's
   move list lives in its own slice of the shared `Tree[]` array
   (`sangen.c`), so this scan never disturbs the root candidate list
   it's iterating over.

3. **Tie-break.** Among the survivors of step 2 (or every legal
   move, if none survived — i.e. the position is simply lost against
   best defense), prefer the move that captures the most valuable
   piece (the SAN Kit's own `valcpv[]` material table), then a
   checking move, then pick at random.
