mwg API
    Preparing search index...

    Class SimulationRuntime<State, Command, Event, A>

    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 same scheduler rather than choosing one over the other.

    import { SimulationRuntime, type SimulationRuntimeRule } from '@datamoc/mw_games/simulation';
    import { Scheduler, type Actor } from '@datamoc/mw_games/roguelike';
    import { Generator } from '@datamoc/mw_games/core';

    interface Fighter extends Actor { id: string; hp: number }
    type State = { hero: Fighter; rat: Fighter };
    type Command = 'attack';
    type Event = { type: 'damage'; targetId: string; amount: number };

    const rule: SimulationRuntimeRule<State, Command, Event, Fighter> = (state, _cmd, { random }) => {
    const amount = random.int(3) + 1;
    const rat = { ...state.rat, hp: state.rat.hp - amount };
    const next = { ...state, rat };
    return { state: next, events: [{ type: 'damage', targetId: rat.id, amount }], status: 'ready', cost: 1 };
    };

    const hero: Fighter = { id: 'hero', hp: 10 };
    const rat: Fighter = { id: 'rat', hp: 5 };
    const scheduler = new Scheduler<Fighter>();
    scheduler.add(hero);
    scheduler.add(rat);

    const runtime = new SimulationRuntime<State, Command, Event, Fighter>({
    state: { hero, rat },
    scheduler,
    random: new Generator(1),
    rule,
    actorId: (fighter) => fighter.id,
    });

    const { events } = runtime.dispatch('attack');

    Type Parameters

    Index