feat: AI integration - pipe protocol, test framework, replay system
AI Session API (src/ai/session.rs): - GameSession wraps Game with seeded determinism - init/init_empty, step(n), perform_action, get_state - get_cell, get_region, get_entities, get_player, count_material JSON Pipe Protocol (src/ai/protocol.rs): - --mode pipe: stdin/stdout JSON line protocol - Commands: init, step, action, get_state, get_view, get_cell, get_region, get_entities, get_player, count_material, find_material, record_start/stop, replay_save, run_scenario, quit Test Framework: - 27 Rust integration tests (tests/*.rs) covering sand, water, lava, acid, fire physics + entity movement, damage, ragdoll - 8 JSON scenarios (scenarios/*.json) runnable via --mode test - Scenario assertions: cell_is, cell_is_not, no_material_in_region, material_count_in_region, entity_alive/dead, player_on_ground, etc. Replay System (src/ai/replay.rs): - Record all actions + seed for deterministic playback - ReplayPlayer::play() and play_until_tick() for debugging - --mode replay --replay-file PATH Other changes: - src/lib.rs: library target for integration tests - Collision: post-constraint collision pass to reduce tunneling - serde + serde_json dependencies - All enums use rename_all = snake_case for JSON compatibility
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "acid_dissolves_wood",
|
||||
"description": "Acid should dissolve wood but not stone",
|
||||
"seed": 42,
|
||||
"init_mode": "empty",
|
||||
"setup": [
|
||||
{"type": "fill_rect", "x": 100, "y": 115, "w": 20, "h": 3, "material": "stone"},
|
||||
{"type": "fill_rect", "x": 103, "y": 112, "w": 5, "h": 1, "material": "stone"},
|
||||
{"type": "set_cell", "x": 105, "y": 111, "material": "wood"},
|
||||
{"type": "set_cell", "x": 104, "y": 111, "material": "acid"},
|
||||
{"type": "set_cell", "x": 106, "y": 111, "material": "acid"},
|
||||
{"type": "set_cell", "x": 105, "y": 110, "material": "acid"}
|
||||
],
|
||||
"steps": 30,
|
||||
"assertions": [
|
||||
{"type": "no_material_in_region", "x": 103, "y": 109, "w": 5, "h": 4, "material": "wood"}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "entity_burns_in_lava",
|
||||
"description": "An entity placed on lava should catch fire and take damage",
|
||||
"seed": 42,
|
||||
"init_mode": "empty",
|
||||
"setup": [
|
||||
{"type": "fill_rect", "x": 100, "y": 130, "w": 20, "h": 1, "material": "stone"},
|
||||
{"type": "fill_rect", "x": 118, "y": 128, "w": 2, "h": 2, "material": "lava"},
|
||||
{"type": "spawn", "kind": "goblin", "x": 119, "y": 125}
|
||||
],
|
||||
"steps": 60,
|
||||
"assertions": [
|
||||
{"type": "entity_health_less_than", "id": 1, "health": 40}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "fire_spreads_through_grass",
|
||||
"description": "Fire should spread through a line of grass",
|
||||
"seed": 42,
|
||||
"init_mode": "empty",
|
||||
"setup": [
|
||||
{"type": "fill_rect", "x": 100, "y": 115, "w": 20, "h": 1, "material": "stone"},
|
||||
{"type": "fill_rect", "x": 100, "y": 114, "w": 10, "h": 1, "material": "grass"},
|
||||
{"type": "set_cell", "x": 100, "y": 114, "material": "fire"}
|
||||
],
|
||||
"steps": 30,
|
||||
"assertions": [
|
||||
{"type": "no_material_in_region", "x": 100, "y": 113, "w": 10, "h": 2, "material": "grass"}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "lava_ignites_wood",
|
||||
"description": "Lava next to wood should set the wood on fire",
|
||||
"seed": 42,
|
||||
"init_mode": "empty",
|
||||
"setup": [
|
||||
{"type": "fill_rect", "x": 100, "y": 110, "w": 20, "h": 1, "material": "stone"},
|
||||
{"type": "fill_rect", "x": 105, "y": 108, "w": 3, "h": 2, "material": "wood"},
|
||||
{"type": "set_cell", "x": 108, "y": 108, "material": "lava"},
|
||||
{"type": "set_cell", "x": 108, "y": 109, "material": "lava"}
|
||||
],
|
||||
"steps": 20,
|
||||
"assertions": [
|
||||
{"type": "no_material_in_region", "x": 105, "y": 107, "w": 3, "h": 3, "material": "wood"}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "lava_plus_water_makes_steam",
|
||||
"description": "Lava and water adjacent should produce steam and stone",
|
||||
"seed": 42,
|
||||
"init_mode": "empty",
|
||||
"setup": [
|
||||
{"type": "fill_rect", "x": 100, "y": 115, "w": 20, "h": 1, "material": "stone"},
|
||||
{"type": "fill_rect", "x": 100, "y": 100, "w": 20, "h": 1, "material": "stone"},
|
||||
{"type": "set_cell", "x": 105, "y": 110, "material": "lava"},
|
||||
{"type": "set_cell", "x": 106, "y": 110, "material": "water"}
|
||||
],
|
||||
"steps": 15,
|
||||
"assertions": [
|
||||
{"type": "no_material_in_region", "x": 100, "y": 105, "w": 20, "h": 10, "material": "lava"}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "player_falls_and_lands",
|
||||
"description": "Player spawned above ground should fall and land on solid surface",
|
||||
"seed": 42,
|
||||
"init_mode": "empty",
|
||||
"setup": [
|
||||
{"type": "fill_rect", "x": 120, "y": 130, "w": 10, "h": 1, "material": "stone"},
|
||||
{"type": "spawn", "kind": "player", "x": 125, "y": 120}
|
||||
],
|
||||
"steps": 60,
|
||||
"assertions": [
|
||||
{"type": "player_alive"},
|
||||
{"type": "player_on_ground"}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "sand_falls_down",
|
||||
"description": "Sand placed in empty space should fall due to gravity",
|
||||
"seed": 42,
|
||||
"init_mode": "empty",
|
||||
"setup": [
|
||||
{"type": "fill_rect", "x": 100, "y": 110, "w": 10, "h": 1, "material": "stone"},
|
||||
{"type": "set_cell", "x": 105, "y": 105, "material": "sand"}
|
||||
],
|
||||
"steps": 10,
|
||||
"assertions": [
|
||||
{"type": "cell_is", "x": 105, "y": 109, "material": "sand"},
|
||||
{"type": "cell_is_not", "x": 105, "y": 105, "material": "sand"}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "water_flows_sideways",
|
||||
"description": "Water on a flat surface should spread horizontally",
|
||||
"seed": 42,
|
||||
"init_mode": "empty",
|
||||
"setup": [
|
||||
{"type": "fill_rect", "x": 100, "y": 110, "w": 20, "h": 1, "material": "stone"},
|
||||
{"type": "set_cell", "x": 105, "y": 108, "material": "water"},
|
||||
{"type": "set_cell", "x": 105, "y": 109, "material": "water"}
|
||||
],
|
||||
"steps": 30,
|
||||
"assertions": [
|
||||
{"type": "material_count_in_region", "x": 110, "y": 108, "w": 5, "h": 3, "material": "water", "min": 1, "max": 10}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user