2.7 KiB
name, description
| name | description |
|---|---|
| deterministic-game-core | Build and verify deterministic turn-based game simulations with pure transitions, exact previews, replayable state, and vertical behavior tests. |
Deterministic Game Core
When to Use
Use when implementing or changing Adaptive Loop's simulation, scenario rules, previews, saves, replays, or win/lose logic.
Procedure
-
Keep the domain model serializable and independent of rendering.
-
Route every committed action through one pure transition:
nextState(state, action). -
Generate previews by calling the same transition on cloned state. Never maintain separate forecast rules.
-
Resolve each turn in a fixed documented order: chamber rotation → channel reconnection/flow → consumption and growth → biological interactions → migration → adaptation → environmental advance → objective/collapse evaluation.
-
Test vertical behavior through public seams. Use worked states and literal expected outcomes, not assertions that reimplement the production algorithm.
-
Cover at least: clockwise/counterclockwise loop rotation, overlapping-loop movement, flow direction, capped populations/resources, adaptation threshold, local trait activation, trait cost, species spillover, pressure-driven environment mutation, win, collapse, exact save/restore, preview/commit equality, and deterministic replay.
-
When a defect appears, search sibling actions and scenarios for the same failure class; fix the shared transition once.
-
Compare canonical domain state only: stable-key serialization or normalized deep equality must exclude timestamps, animation, focus, hover, and other transient UI state.
-
Scenario verification must replay one known winning and one known losing route per scenario and all reachable campaign inheritance combinations.
Pitfalls
- No randomness unless seeded and serialized; prefer no randomness.
- No floating-point simulation where small capped integers suffice.
- No mutation of input state.
- No UI-owned game rules.
- No private-method or implementation-coupled tests.
- No snapshots whose expected value is generated by the same logic under test.
Verification
- Identical canonical state plus action produces structurally identical canonical output and deterministic event attribution.
- Preview canonical output equals committed canonical output for every legal action in representative states.
- Saving and restoring preserves canonical state and the exact next transition.
- Replaying an action log from a scenario baseline plus inheritance snapshot reproduces final state and outcome.
- Each scenario has verified winning/losing routes; all reachable campaign inheritance combinations remain solvable.