| from __future__ import annotations |
|
|
| from world_simulator.config import GameConfig, NpcConfig, ServerConfig, SimulationConfig, WorldConfig |
| from world_simulator.rendering.scene_contract import to_scene_snapshot |
| from world_simulator.simulation.spawning import create_world |
| from world_simulator.simulation.survival import add_episode |
|
|
|
|
| def test_scene_snapshot_contains_terrain_and_entities() -> None: |
| world = create_world( |
| GameConfig( |
| world=WorldConfig(width=80, depth=80, terrain="plain_green", seed=42), |
| npcs=NpcConfig(count=2), |
| simulation=SimulationConfig(tick_ms=500), |
| server=ServerConfig(host="127.0.0.1", port=8000), |
| ) |
| ) |
|
|
| snapshot = to_scene_snapshot(world) |
|
|
| assert snapshot["schema_version"] == 1 |
| assert snapshot["simulation"]["last_tick_source"] == "initial" |
| assert snapshot["simulation"]["tick_in_progress"] is False |
| assert snapshot["simulation"]["pending_tick"] is None |
| assert snapshot["terrain"]["color"] == "#43a047" |
| assert snapshot["terrain"]["width"] == 80 |
| assert snapshot["terrain"]["grid_blocks"] == 20 |
| assert snapshot["terrain"]["block_size"] == 4.0 |
| assert len(snapshot["entities"]) == 2 |
| assert snapshot["entities"][0]["kind"] == "npc" |
| assert snapshot["entities"][0]["render"]["primitive"] == "capsule" |
| assert snapshot["entities"][0]["state"]["health"] == 100 |
| assert snapshot["entities"][0]["state"]["max_health"] == 100 |
| assert snapshot["entities"][0]["state"]["is_alive"] is True |
| assert 5 <= snapshot["entities"][0]["state"]["attack_damage"] <= 15 |
| assert snapshot["entities"][0]["state"]["personality"] == "neutral" |
| assert snapshot["entities"][0]["state"]["god_directive"] is None |
| assert snapshot["entities"][0]["state"]["memory_count"] == 1 |
| assert snapshot["entities"][0]["state"]["memory_summary"] is None |
| assert snapshot["entities"][0]["state"]["memories"] == [ |
| {"tick": 0, "text": "Ada arrived as a citizen."} |
| ] |
|
|
|
|
| def test_survival_snapshot_contains_world_and_structured_memory() -> None: |
| world = create_world( |
| GameConfig( |
| world=WorldConfig(width=80, depth=80, terrain="plain_green", seed=42, survival=True), |
| npcs=NpcConfig(count=2), |
| simulation=SimulationConfig(tick_ms=500), |
| server=ServerConfig(host="127.0.0.1", port=8000), |
| ) |
| ) |
| npc = world.npcs[0] |
| add_episode( |
| npc, |
| 1, |
| "transfer", |
| world.npcs[1].id, |
| "Boris gave me food", |
| target_id=npc.id, |
| object_id="food", |
| subject_kind="npc", |
| perspective="recipient", |
| tags=["food", "help", "trade"], |
| ) |
|
|
| snapshot = to_scene_snapshot(world) |
| entity_state = snapshot["entities"][0]["state"] |
|
|
| assert snapshot["resource_nodes"] |
| assert snapshot["beasts"] |
| assert entity_state["relationships"] |
| assert entity_state["recent_episodes"][-1]["kind"] == "transfer" |
| assert entity_state["recent_episodes"][-1]["summary"] == "Boris gave me food" |
|
|