Handbook
Games engine API (`forge_lcdl.games.engine`)
Pure, stdlib-facing rules surface. Detailed split with LCDL is in GAMES-ARCHITECTURE.md; alpha checklist in GAMES-ALPHA-STATUS.md.
Games engine API (forge_lcdl.games.engine)
Pure, stdlib-facing rules surface. Detailed split with LCDL is in GAMES-ARCHITECTURE.md; alpha checklist in GAMES-ALPHA-STATUS.md.
Game lifecycle
setup(seed=None, ...)— Authoritative starting state (seedis optional metadata for rules that need RNG inside setup).acting_player(state)— Who must act, orNoneif terminal / undefined.player_view(state, player_id)— JSON-serializablePlayerView; never leaks hidden opponent data through this path.legal_moves(state, player_id)— Stable, finite tuple ofMoveinstances;move_idis the externally stable handle.apply_move(state, move)— ReturnsTransitionResult; illegal plays usetransition_fail("…")without raising.is_terminal(state), thenscore(state)(InvalidStateErrorif not terminal—by contract).
Error surface
| Situation | Preferred API |
|---|---|
| Illegal move | TransitionResult(ok=False, error='…') |
| Caller bug / corrupt state decode | ValueError, InvalidStateError |
| Scoring non-terminal state | InvalidStateError |
Hashing and logs
stable_state_hash and serialization.state_hash delegate to the same SHA-256 of canonical JSON. Use replay.replay_log to verify persisted GameLog rows.
Serialization facade
serialization.to_canonical_json / from_canonical_json coerce JSON-stable trees; ensure_json_serializable raises TypeError on unsupported leaves.
Bundled reference move_id prefixes
GAME_ID |
Prefix examples |
|---|---|
tic_tac_toe |
place_<row>_<col> |
nim |
take_<n> |
connect_four_like |
drop_col_<col> |
CLI (stdlib-only)
python -m forge_lcdl.games.engine list-reference-games
python -m forge_lcdl.games.engine replay path/to/fixture.json
python -m forge_lcdl.games.engine random-play tic_tac_toe --seed 1
See GAMES-EXAMPLES.md for scripted demos.