Game Manual

Build a Better Bot — design pages, rendered from the repo docs.

Engine — how the code that runs the game is organized

settled decided — build to this page

The engine is organized by what owns each piece of code. Records hold data and guard it. The bot and its threads are shared by every station and know none of them. Each station owns its board and everything that acts on it, and the code for a mod, glitch or specialization lives in the station it acts on. The full design, with the reasons behind each rule, is ../engine.md.

The tree. The engine package, engine/bbsb_engine/, holds twelve packages beside its tests, each importing only the packages above it:

packagerole
state/records and their own checks: play state, and the game data read from files; the random streams, the activity log and the process settings
constellation/how a bot decides: threads, the shared turn, the thread-turn loop both stations run (turn_loop.py), the plan search, station-neutral foresight with urgency, interest and a turn’s score (foresight.py), what a mod is, and the station’s two calls
bot/the chassis: Bot, the bot stable, building and loading a bot, what a specialization is, and the specializations every station shares
station/the stations, siblings that never import each other: arena/ (combat) and shop/ (the generator board, the supply bin and its tickets), and below both grid/, the geometry they walk by: walk lengths, the walk memo, the grid directions and the tiles no walk enters
player/what the player owns and earns: progression, research, the stable, glitches and story
level/running a level: the scheduler, the modes, the bracket and the battle a level runs
engine/one game: the Engine, its start-up, its holds, and the occasions read off its log
assets/content packs: where they live, publishing them, and checking a pack against the game
sim/the engine without a player: checkpoints, scenarios, and the fight that plays a scenario on a level, for the Balance Lab, the base levels’ playthroughs and the tests
session/many games in one process: handles, the tick loop, saves and storage
editors/the level editor’s and the story’s design seams
app/the process: start-up, one module per router, the WebSocket and the snapshot

The rules. A package imports only the packages above it in that table, and the stations never import each other: they meet only in the packages that import them, in records, and on the activity log. import-linter checks both on every run of the suite. Records keep only their own checks, and every decision is a function in the domain that owns it. Code lives in the lowest package that owns it, and outside the tests no engine import happens inside a function. All tuning is fixed before a game starts, and only an entry point (the app, sim/, the asset command line, tools/, the Balance Lab, a test fixture) starts one.

Inside a station. Each station has the same seven parts, each importing only the parts after it: station (its hooks on the shared turn loop and its answers to a thread), mods/, glitches/ and specializations/ (one file each, named after it), foresight/ (how a thread plans there), actions/ (one module per request kind, and the steps several share) and board/ (the board, its geometry and reads, and the view a mod sees).

Threads choose; stations act. A thread reaches its station through two calls. Plan plays each plan the thread could make on a copy of the station’s board and reports its payoff, denial and threat. Act carries out the chosen plan’s first action and reports the bodies its fire damaged, the pips the fire earned and whether the bot still stands. Only a station reads or changes its board; a mod reads it through a read-only view from the acting bot’s eyes, built anew whenever the board changes.

Mods list requests. What a mod or an arena glitch does is a list of requests: frozen records carrying their numbers in named fields and the target a plan chose. The station carries out each one with the handler its kind registers, and that handler writes the kind’s log entries. An action’s targets are listed once, read by both the plan and the handler. Core abilities names the requests behind each ability.

The records. Each kind of data has one form, chosen for how often it is made and copied:

whatformrule
game data (data/ and the story pack)frozen pydantic modelsread once per location into one record every game shares; among the references it checks, it refuses one to a name no file declares (GDT-002)
play stateslotted dataclasseseach record’s own copy() copies only what a copy may change
savesone TypeAdapter per record typea name is saved as a name and resolved at load through the game’s lookups
requests and log entriesfrozen, slotted dataclassesmade constantly, on plan boards too; validated never
the built mods, glitches and specializationsread-only lookupsbuilt once per game data and overlay at start-up, shared by every game

Log entries are typed. Each kind of log entry is a class named after its type, and together they form one union. Its JSON Schema and the admin UI’s types generated from it are committed in @bbsb/activity, and each entry type’s look, motion, sound and narration live in one admin UI module (state § The activity log).

Derived specs — engine/bbsb_engine/test/engine/engine_spec.yaml (GDT game data · SUP start-up · LAY layout), state/activity_log_spec.yaml (ENT entries), constellation/threads_spec.yaml (STN station calls) and combat/combat_spec.yaml (REQ requests).