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
44 lines
1.9 KiB
Rust
44 lines
1.9 KiB
Rust
use verbatim::ai::GameSession;
|
|
use verbatim::ai::AiAction;
|
|
|
|
fn setup_empty() -> GameSession {
|
|
let mut s = GameSession::new_seeded(42);
|
|
s.init_empty();
|
|
s.clear_area(95, 95, 40, 40);
|
|
s
|
|
}
|
|
|
|
#[test]
|
|
fn water_flows_down() {
|
|
let mut s = setup_empty();
|
|
s.perform_action(&AiAction::FillRect { x: 95, y: 115, w: 40, h: 3, material: "stone".into() });
|
|
s.perform_action(&AiAction::SetCell { x: 110, y: 105, material: "water".into() });
|
|
s.perform_action(&AiAction::SetCell { x: 110, y: 106, material: "water".into() });
|
|
s.perform_action(&AiAction::SetCell { x: 110, y: 107, material: "water".into() });
|
|
s.step(20);
|
|
let water_near_bottom = s.count_material_in_region(105, 112, 10, 4, "water");
|
|
assert!(water_near_bottom > 0, "water should have flowed down to near the stone floor, found {} water cells near bottom", water_near_bottom);
|
|
}
|
|
|
|
#[test]
|
|
fn water_spreads_sideways() {
|
|
let mut s = setup_empty();
|
|
s.perform_action(&AiAction::FillRect { x: 95, y: 115, w: 50, h: 3, material: "stone".into() });
|
|
s.perform_action(&AiAction::FillRect { x: 110, y: 111, w: 1, h: 4, material: "water".into() });
|
|
s.step(50);
|
|
let left_count = s.count_material_in_region(100, 110, 10, 5, "water");
|
|
let right_count = s.count_material_in_region(111, 110, 10, 5, "water");
|
|
assert!(left_count > 0 || right_count > 0, "water should spread sideways: left={} right={}", left_count, right_count);
|
|
}
|
|
|
|
#[test]
|
|
fn water_does_not_pass_through_stone_wall() {
|
|
let mut s = setup_empty();
|
|
s.perform_action(&AiAction::FillRect { x: 95, y: 115, w: 50, h: 3, material: "stone".into() });
|
|
s.perform_action(&AiAction::FillRect { x: 115, y: 110, w: 1, h: 5, material: "stone".into() });
|
|
s.perform_action(&AiAction::FillRect { x: 100, y: 110, w: 15, h: 5, material: "water".into() });
|
|
s.step(30);
|
|
let right_water = s.count_material_in_region(116, 108, 10, 10, "water");
|
|
assert_eq!(right_water, 0, "water should not pass through stone wall");
|
|
}
|