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
53 lines
2.1 KiB
Rust
53 lines
2.1 KiB
Rust
use verbatim::ai::GameSession;
|
|
use verbatim::ai::AiAction;
|
|
use verbatim::world::cell::MaterialId;
|
|
|
|
fn setup_empty() -> GameSession {
|
|
let mut s = GameSession::new_seeded(42);
|
|
s.init_empty();
|
|
s.clear_area(95, 95, 30, 40);
|
|
s
|
|
}
|
|
|
|
#[test]
|
|
fn sand_falls_down() {
|
|
let mut s = setup_empty();
|
|
s.perform_action(&AiAction::FillRect { x: 100, y: 115, w: 10, h: 1, material: "stone".into() });
|
|
s.perform_action(&AiAction::SetCell { x: 105, y: 105, material: "sand".into() });
|
|
s.step(10);
|
|
assert_eq!(s.get_cell(105, 105).material, "empty", "sand should have fallen from y=105");
|
|
assert_eq!(s.get_cell(105, 114).material, "sand", "sand should be resting on stone at y=114");
|
|
}
|
|
|
|
#[test]
|
|
fn sand_displaces_water() {
|
|
let mut s = setup_empty();
|
|
s.perform_action(&AiAction::FillRect { x: 100, y: 115, w: 10, h: 1, material: "stone".into() });
|
|
s.perform_action(&AiAction::FillRect { x: 100, y: 110, w: 10, h: 5, material: "water".into() });
|
|
s.perform_action(&AiAction::SetCell { x: 105, y: 105, material: "sand".into() });
|
|
s.step(20);
|
|
let sand_at_bottom = s.get_cell(105, 114).material == "sand";
|
|
assert!(sand_at_bottom, "sand should sink to bottom through water");
|
|
}
|
|
|
|
#[test]
|
|
fn sand_piles_on_stone() {
|
|
let mut s = setup_empty();
|
|
s.perform_action(&AiAction::FillRect { x: 100, y: 115, w: 10, h: 1, material: "stone".into() });
|
|
s.perform_action(&AiAction::SetCell { x: 105, y: 105, material: "sand".into() });
|
|
s.perform_action(&AiAction::SetCell { x: 105, y: 104, material: "sand".into() });
|
|
s.step(15);
|
|
let count = s.count_material_in_region(104, 112, 3, 4, "sand");
|
|
assert!(count >= 2, "both sand cells should have piled up, got {} sand cells", count);
|
|
}
|
|
|
|
#[test]
|
|
fn sand_does_not_fall_through_stone() {
|
|
let mut s = setup_empty();
|
|
s.perform_action(&AiAction::FillRect { x: 100, y: 110, w: 10, h: 1, material: "stone".into() });
|
|
s.perform_action(&AiAction::SetCell { x: 105, y: 105, material: "sand".into() });
|
|
s.step(10);
|
|
assert_eq!(s.get_cell(105, 109).material, "sand", "sand should rest on top of stone");
|
|
assert_eq!(s.get_cell(105, 110).material, "stone", "stone should remain");
|
|
}
|