wip: current project state
This commit is contained in:
+49
-12
@@ -1,5 +1,5 @@
|
||||
use verbatim::ai::GameSession;
|
||||
use verbatim::ai::AiAction;
|
||||
use verbatim::ai::GameSession;
|
||||
use verbatim::ai::ReplayPlayer;
|
||||
|
||||
#[test]
|
||||
@@ -13,7 +13,8 @@ fn replay_deterministic() {
|
||||
s1.step(10);
|
||||
let state1 = s1.get_state();
|
||||
|
||||
s1.save_replay("/tmp/verbatim_test_replay.json").expect("save replay");
|
||||
s1.save_replay("/tmp/verbatim_test_replay.json")
|
||||
.expect("save replay");
|
||||
|
||||
let player = ReplayPlayer::load("/tmp/verbatim_test_replay.json").expect("load replay");
|
||||
let s2 = player.play();
|
||||
@@ -22,8 +23,18 @@ fn replay_deterministic() {
|
||||
assert_eq!(state1.tick, state2.tick, "ticks should match");
|
||||
if let (Some(p1), Some(p2)) = (&state1.player, &state2.player) {
|
||||
assert_eq!(p1.health, p2.health, "player health should match");
|
||||
assert!((p1.pos[0] - p2.pos[0]).abs() < 0.01, "player x should match: {} vs {}", p1.pos[0], p2.pos[0]);
|
||||
assert!((p1.pos[1] - p2.pos[1]).abs() < 0.01, "player y should match: {} vs {}", p1.pos[1], p2.pos[1]);
|
||||
assert!(
|
||||
(p1.pos[0] - p2.pos[0]).abs() < 0.01,
|
||||
"player x should match: {} vs {}",
|
||||
p1.pos[0],
|
||||
p2.pos[0]
|
||||
);
|
||||
assert!(
|
||||
(p1.pos[1] - p2.pos[1]).abs() < 0.01,
|
||||
"player y should match: {} vs {}",
|
||||
p1.pos[1],
|
||||
p2.pos[1]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,14 +49,25 @@ fn replay_play_until_tick() {
|
||||
s.step(5);
|
||||
s.perform_action(&AiAction::Jump);
|
||||
s.step(10);
|
||||
s.save_replay("/tmp/verbatim_test_replay2.json").expect("save");
|
||||
s.save_replay("/tmp/verbatim_test_replay2.json")
|
||||
.expect("save");
|
||||
|
||||
let player = ReplayPlayer::load("/tmp/verbatim_test_replay2.json").expect("load");
|
||||
let s_half = player.play_until_tick(5);
|
||||
assert_eq!(s_half.tick(), 5, "should stop at tick 5, got {}", s_half.tick());
|
||||
assert_eq!(
|
||||
s_half.tick(),
|
||||
5,
|
||||
"should stop at tick 5, got {}",
|
||||
s_half.tick()
|
||||
);
|
||||
|
||||
let s_full = player.play();
|
||||
assert_eq!(s_full.tick(), 20, "full replay should reach tick 20, got {}", s_full.tick());
|
||||
assert_eq!(
|
||||
s_full.tick(),
|
||||
20,
|
||||
"full replay should reach tick 20, got {}",
|
||||
s_full.tick()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -62,8 +84,18 @@ fn same_seed_same_state() {
|
||||
|
||||
assert_eq!(state1.tick, state2.tick);
|
||||
if let (Some(p1), Some(p2)) = (&state1.player, &state2.player) {
|
||||
assert!((p1.pos[0] - p2.pos[0]).abs() < 0.01, "x mismatch: {} vs {}", p1.pos[0], p2.pos[0]);
|
||||
assert!((p1.pos[1] - p2.pos[1]).abs() < 0.01, "y mismatch: {} vs {}", p1.pos[1], p2.pos[1]);
|
||||
assert!(
|
||||
(p1.pos[0] - p2.pos[0]).abs() < 0.01,
|
||||
"x mismatch: {} vs {}",
|
||||
p1.pos[0],
|
||||
p2.pos[0]
|
||||
);
|
||||
assert!(
|
||||
(p1.pos[1] - p2.pos[1]).abs() < 0.01,
|
||||
"y mismatch: {} vs {}",
|
||||
p1.pos[1],
|
||||
p2.pos[1]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +105,8 @@ fn pipe_protocol_init_and_step() {
|
||||
use std::process::{Command, Stdio};
|
||||
|
||||
let mut child = Command::new(env!("CARGO_BIN_EXE_verbatim"))
|
||||
.arg("--mode").arg("pipe")
|
||||
.arg("--mode")
|
||||
.arg("pipe")
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::null())
|
||||
@@ -98,9 +131,13 @@ fn pipe_protocol_init_and_step() {
|
||||
stdin.flush().expect("flush");
|
||||
let n = stdout.read(&mut buf).expect("read");
|
||||
let output2 = String::from_utf8_lossy(&buf[..n]).to_string();
|
||||
let json2: serde_json::Value = serde_json::from_str(output2.trim()).expect("parse step response");
|
||||
let json2: serde_json::Value =
|
||||
serde_json::from_str(output2.trim()).expect("parse step response");
|
||||
assert_eq!(json2["ok"], true);
|
||||
assert_eq!(json2["state"]["tick"], 10, "tick should be 10 after stepping 10");
|
||||
assert_eq!(
|
||||
json2["state"]["tick"], 10,
|
||||
"tick should be 10 after stepping 10"
|
||||
);
|
||||
|
||||
writeln!(stdin, "{{\"cmd\":\"quit\"}}").expect("write quit");
|
||||
stdin.flush().expect("flush");
|
||||
|
||||
Reference in New Issue
Block a user