Files
Verbatim/tests/entity_movement.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

58 lines
2.1 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, 35);
s.perform_action(&AiAction::FillRect { x: 80, y: 135, w: 80, h: 15, material: "stone".into() });
s
}
#[test]
fn player_falls_and_lands() {
let mut s = GameSession::new_seeded(42);
s.init_empty();
s.clear_area(120, 128, 10, 5);
s.perform_action(&AiAction::FillRect { x: 118, y: 132, w: 14, h: 10, material: "stone".into() });
s.step(30);
let player = s.get_player().expect("player should exist");
assert!(player.alive, "player should be alive");
assert!(player.pos[1] < 132.0, "player should land on stone at y=132, got y={}", player.pos[1]);
assert!(player.pos[1] > 125.0, "player should have fallen from center");
}
#[test]
fn player_blocked_by_stone_wall() {
let mut s = setup_empty();
s.step(30);
let player = s.get_player().expect("player should exist");
let x = player.pos[0] as i32;
s.perform_action(&AiAction::FillRect { x: x + 5, y: 125, w: 1, h: 10, material: "stone".into() });
s.perform_action(&AiAction::MoveRight);
s.step(10);
let player = s.get_player().expect("player should exist");
assert!(player.pos[0] < (x + 5) as f32, "player should be blocked by wall");
}
#[test]
fn player_can_move_right() {
let mut s = setup_empty();
s.step(30);
let player = s.get_player().expect("player should exist");
let initial_x = player.pos[0];
s.perform_action(&AiAction::MoveRight);
s.step(10);
let player = s.get_player().expect("player should exist");
assert!(player.pos[0] > initial_x, "player should have moved right: {} -> {}", initial_x, player.pos[0]);
}
#[test]
fn player_survives_fall() {
let mut s = setup_empty();
s.step(60);
let player = s.get_player().expect("player should exist");
assert!(player.alive, "player should survive a fall onto stone");
assert!(player.health > 50.0, "player should not take significant damage from landing, hp={}", player.health);
}