Optionalhistory?: SimulationRuntimeHistoryOptions<A>Optionaljournal?: ActionJournal<Command, Event> | nullWhere committed commands are recorded. Pass null for a journal-free
dispatch facade: no append (and no structuredClone cost),
snapshot() carries an empty journal, and replay/undo have nothing
to replay. restore() always resumes with recording enabled from
the snapshot's journal.
Runs one command through the rule, commits the resulting state, and charges its cost to the scheduler's current actor when one is given.
Restores the next checkpoint after an undo, or null when no redo is available.
Restores the previous committed simulation checkpoint, or null when undo is disabled.
StaticrestoreRebuilds a runtime from a snapshot taken by snapshot(). The caller supplies
actorOf to resolve the scheduler's ids back to live actor objects, the same way
Scheduler.restore does - the runtime has no identity primitive of its own to lean on.
Optionalrandom?: Random.GeneratorAdopt this generator instead of creating one: its state is set from the snapshot, so passing the ambient global generator reconciles the two streams and later draws stay in lockstep. Defaults to a new generator.
A small facade over one state + one scheduler + one RNG, for the interactive half of a turn-based simulation: the command a player just issued, dispatched through the game's own rule.
advanceToInput/runScenario(simulation/Turns.ts/Scenario.ts) still cover the automatic-actor loop and fixed-command replay respectively; a game composes both against the sameschedulerrather than choosing one over the other.Every command and event batch is journalled (pass
journal: nullto disable the journal entirely:dispatchthen skips the append,snapshot()exposes an empty journal, and replay/undo have nothing to replay), and withhistoryevery committed state is checkpointed, all throughstructuredClone:Command,EventandStatemust be plain data. A command naming its target as a live actor object (one that owns aReactionTable, or any other callback) cannot be copied, so carry the actor's id and resolve it in the rule. Adispatchwhose command, events or checkpoint cannot be copied throws aTypeErrornaming the offending path and commits nothing: state, scheduler, random stream and journal stay as they were before the call. The type system cannot enforce this, since a class instance with methods is perfectly cloneable while a plain object with one function field is not.Example