Kriegspiel bot that asks an Anthropic Haiku model to choose the next action from the bot's private game state.
- registers as a listed Kriegspiel bot
- polls assigned games from the live API
- does not create waiting lobby games by default
- can join another bot's waiting lobby game with 0.1% probability while still under its active-game cap
- builds a prompt from the current rule variant, private FEN, legal actions, and private scoresheet
- asks an Anthropic Haiku model for the top ranked next actions in strict JSON
- validates the model output against the server-provided legal actions
- checks Anthropic availability with a tiny cached preflight call before joining a new bot-vs-bot game
- skips the join if Anthropic is unavailable or out of quota
- still falls back safely if the model response itself is malformed
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
cp .env.example .env
python bot.py --register
python bot.pyThe bot reads the live rules text from the sibling ks-content repository:
ks-content/rules/berkeley.mdks-content/rules/README.md
Set KRIEGSPIEL_CONTENT_RULES_DIR to override that rules directory.
By default the registration email is bot-haiku@kriegspiel.org.
By default the bot does not create open lobby games on its own. That behavior is controlled with:
KRIEGSPIEL_AUTO_CREATE_LOBBY_GAME=true|falseKRIEGSPIEL_AUTO_CREATE_RULE_VARIANT=berkeley|berkeley_anyKRIEGSPIEL_AUTO_CREATE_PLAY_AS=white|black|randomKRIEGSPIEL_SUPPORTED_RULE_VARIANTS=berkeley,berkeley_anyKRIEGSPIEL_MAX_ACTIVE_GAMES_BEFORE_CREATE=1
Bot-vs-bot play is also enabled by default:
- the bot samples open waiting games at most once per minute
- it will only consider games created by another bot
- it samples that decision at most once per minute
- it will try to join one with 0.1% probability on that minute check
- it uses the same 1-active-game cap for intentional bot-vs-bot joins
- it keeps the local cooldown even when no join candidate is found, matching backend bot-join limits and avoiding tight lobby scans
Anthropic prompting defaults:
- system prompt carries the rules and overall Kriegspiel scene
- the first user prompt carries private scoresheet history, recent referee items, and legal actions
- later user prompts carry only incremental updates: new referee items, rejected candidates, and refreshed legal options
- the bot keeps per-game conversation history and reuses it on the Anthropic Messages API
- automatic prompt caching is enabled with a 1-hour TTL to maximize cache reuse across retries and later turns
- the bot asks for the top 10 ranked candidate actions by default
- if a batch fails, it asks the model for the next batch of candidates
- defaults can be tuned with:
ANTHROPIC_MODEL=claude-haiku-4-5-20251001ANTHROPIC_MODEL_BATCH_SIZE=10ANTHROPIC_MAX_BATCHES_PER_TURN=5ANTHROPIC_PREFLIGHT_SUCCESS_TTL_SECONDS=60ANTHROPIC_PREFLIGHT_FAILURE_TTL_SECONDS=15
python -m unittest discover -s testsA production host can run the bot as a service with deploy/kriegspiel-haiku-bot.service.