Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:4thfever Cultivation world simulator finalize step

From Leeroopedia
Knowledge Sources
Domains Simulation, Game_Engine
Last Updated 2026-10-22 14:00 GMT

Overview

Concrete tool for finalizing a simulation step by deduplicating events, enriching close-relation observations, persisting events, logging, and advancing the world time, provided by the Cultivation World Simulator engine.

Description

The finalize_step function is the last phase (phase 29) in the simulation pipeline. It:

  1. Records metrics for tracked avatars
  2. Deduplicates events by ID
  3. Enriches major events (excluding story events and special kinds) with close-relation observation data
  4. Persists all final events to `world.event_manager`
  5. Logs each event
  6. Increments `world.month_stamp` by 1

This function does NOT do a final reset check (its `reset_check_after` is `False`), ensuring the step completes atomically.

Usage

Import and call this function when:

  • Simulation pipeline: called automatically as the final phase by `SimulationPhaseRunner.run()`
  • Testing: can be called directly with a mock context to test event finalization

Code Reference

Source Location

Signature

def finalize_step(ctx: SimulationStepContext) -> list[Event]:
    """Finalize events, persist them, and advance the month stamp."""

def log_events(events: list[Event]) -> None:
    """Log each event via the game logger."""

Import

from src.sim.simulator_engine.finalizer import finalize_step

I/O Contract

Inputs

Name Type Required Description
ctx SimulationStepContext Yes Shared step context with accumulated events and world

Outputs

Name Type Description
return Deduplicated, finalized events; same as persisted to event_manager
(side effects) Events persisted to world.event_manager; world.month_stamp incremented by 1; metrics recorded

Usage Examples

Direct Call (for testing)

from src.sim.simulator_engine.context import SimulationStepContext
from src.sim.simulator_engine.finalizer import finalize_step

ctx = SimulationStepContext.create(world)
ctx.events = test_events  # inject test events
final_events = finalize_step(ctx)
assert world.month_stamp == original_stamp + 1

Related Pages

Implements Principle

Required Environments

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment