Chapter 23 — Deterministic Replay
Part VII — Debugging and Tools
Action log replay.
How It Works
Section titled “How It Works”Every player action is recorded in an action log alongside the random seed used for that session. Because the engine is deterministic, replaying the same actions with the same seed produces the exact same sequence of events.
Running a Replay
Section titled “Running a Replay”ai-rpg-engine replayThe engine re-executes every recorded action and verifies that the resulting events match the original session.
Debugging Workflows
Section titled “Debugging Workflows”Replay is the primary debugging tool for AI RPG Engine:
- Reproduce a bug — replay the session that triggered it
- Isolate the cause — add logging or breakpoints and replay again
- Verify the fix — replay the same session after changing code
Because events are deterministic, a bug that happened once will happen every time on replay.
Regression Testing
Section titled “Regression Testing”Action logs can be committed to the repository as regression tests. If a code change causes different events from the same inputs, the replay will fail — catching unintended behavior changes automatically.
Example
Section titled “Example”3 actions → 13 events (deterministic)
Action 1: move crypt → 4 eventsAction 2: attack ghoul → 6 eventsAction 3: use draught → 3 eventsEvery replay of this session produces exactly these 13 events in the same order.