Files
Verbatim/tests/physics_acid.rs
T
Emil 7f4b1dde5e 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
2026-06-20 18:53:21 +03:00

39 lines
1.4 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 acid_dissolves_wood() {
let mut s = setup_empty();
s.perform_action(&AiAction::FillRect { x: 100, y: 120, w: 10, h: 1, material: "stone".into() });
s.perform_action(&AiAction::SetCell { x: 104, y: 118, material: "wood".into() });
s.perform_action(&AiAction::SetCell { x: 105, y: 119, material: "acid".into() });
s.perform_action(&AiAction::SetCell { x: 104, y: 119, material: "acid".into() });
s.step(30);
assert_ne!(s.get_cell(104, 118).material, "wood", "acid should have dissolved the wood");
}
#[test]
fn acid_does_not_dissolve_stone() {
let mut s = setup_empty();
s.perform_action(&AiAction::SetCell { x: 105, y: 110, material: "stone".into() });
s.perform_action(&AiAction::SetCell { x: 105, y: 111, material: "acid".into() });
s.step(20);
assert_eq!(s.get_cell(105, 110).material, "stone", "acid should not dissolve stone");
}
#[test]
fn acid_flows_down() {
let mut s = setup_empty();
s.perform_action(&AiAction::FillRect { x: 100, y: 120, w: 10, h: 1, material: "stone".into() });
s.perform_action(&AiAction::SetCell { x: 105, y: 105, material: "acid".into() });
s.step(20);
assert_ne!(s.get_cell(105, 105).material, "acid", "acid should have flowed down from y=105");
}