Tick Execution
How the VM processes each simulation tick.
Tick Loop
tick(): void {
// 1. Clear events from previous tick
this.state.events = [];
// 2. Sort rules by priority (higher first)
const sortedRules = [...this.ir.rules]
.sort((a, b) => b.priority - a.priority);
// 3. Execute each rule
for (const rule of sortedRules) {
this.executeRule(rule);
}
// 4. Increment tick counter
this.state.tick++;
// 5. Emit callback
this.config.onTick?.(this.state);
}Rule Execution
- Select agents matching the rule's selector
- For each agent, evaluate the condition
- If condition passes, execute the action
- Action may modify agent state or emit events
Running Multiple Ticks
const vm = new CruxVM(worldIR);
// Run 100 ticks
const result = vm.run(100);
console.log(result.ticksExecuted);
console.log(result.finalState);
console.log(result.events);