//! Smart v2 comparison runner (#149): the simple mode, the current (legacy) Smart and the //! candidate, on fixed seeds and one scenario set — open map, hills, a configuration changed //! between waves, and a recon flight shot down before its report. //! //! It prints one JSON array of rows: the share of useful decisions (a smart drone whose last //! aim was a live public hint), the diversity of aims, the reasons (intents) on the review, //! the share of jittery drones (two switches or more), the bearing picker's typed reason, the //! refresh count, and the CPU/worst-job figures. The goal is interesting counterplay and clear //! mistakes, not a maximised hit count — read the reasons and the jitter beside the losses. //! //! cargo run --release --example smart_bench #[path = "sim_run/harness.rs"] mod harness; use airdef::sim::{Aim, Approach, DroneKind, Sam, SamKind, Sim}; use glam::DVec3; use harness::{Report, Scenario, Terrain}; #[derive(Clone, Copy, PartialEq)] enum Mode { Simple, Current, Candidate, } impl Mode { fn name(self) -> &'static str { match self { Mode::Simple => "simple", Mode::Current => "current", Mode::Candidate => "candidate", } } fn apply(self, sc: &mut Scenario) { sc.legacy = self == Mode::Current; let aim = match self { Mode::Simple => Aim::ObjectsAndSams, _ => Aim::Smart, }; for raid in &mut sc.raids { raid.aim = aim; } } } fn esc(s: &str) -> String { s.chars().flat_map(|c| match c { '"' => "\\\"".chars().collect::>(), '\\' => "\\\\".chars().collect::>(), c => vec![c], }).collect() } fn row(sc: &str, mode: Mode, r: &Report) -> String { format!( "{{\"scenario\":\"{}\",\"mode\":\"{}\",\"seed\":{},\"ticks\":{},\"all_ended\":{},\"launched\":{},\"kills\":{},\"hits\":{},\"fired\":{},\"sams_lost\":{},\"smart_seen\":{},\"useful_share\":{:.3},\"diversity\":{:.3},\"jittery_share\":{:.3},\"intents\":\"{}\",\"bearing_reason\":\"{}\",\"refresh_applied\":{},\"switches_max\":{},\"retargets_max\":{},\"tick_p95_ms\":{:.3},\"tick_max_ms\":{:.3},\"planning_ms\":{:.1},\"air_bytes\":{}}}", esc(sc), mode.name(), r.seed, r.ticks_run, r.all_ended, r.launched, r.kills, r.hits, r.fired, r.sams_lost, r.smart_seen, r.useful_share, r.diversity, r.jittery_share, esc(&r.intents), esc(&r.bearing_reason), r.refresh_applied, r.switches_max, r.retargets_max, r.tick_p95.as_secs_f64() * 1000.0, r.tick_max.as_secs_f64() * 1000.0, r.planning.as_secs_f64() * 1000.0, r.air_bytes, ) } /// An open map: a ring of systems on flat land, one combined strike. fn open() -> Scenario { let mut sc = Scenario::new("open"); sc.terrain = Terrain::Flat(70); for i in 0..18 { let a = i as f64 * 2.399_963; let r = 120.0 + (i as f64 / 18.0) * 320.0; let kind = [SamKind::Radar, SamKind::S400, SamKind::Pantsir, SamKind::Ew, SamKind::Tor][i % 5]; sc.unit(kind, a.sin() * r, a.cos() * r).heading = a; } sc.raids.push(harness::RaidSpec { kinds: vec![(DroneKind::Gerbera, 6), (DroneKind::Shahed, 10), (DroneKind::Kh101, 3), (DroneKind::Kh22, 2), (DroneKind::Lancet, 3)], approach: Approach::AllSides, aim: Aim::Smart, dist: 500.0, at: 1, }); sc.ticks = 20 * 60 * 6; sc } /// Hills: the standard big smart scenario's terrain and force. fn hills() -> Scenario { let mut sc = harness::big_smart(); sc.name = "hills".into(); sc.ticks = 20 * 60 * 6; sc } /// Two waves with the defence changed between them: a radar moves unobserved, the EW stations /// switch on, and a fresh battery appears. The second wave's picture must earn what it knows. fn config_change() -> Scenario { let mut sc = open(); sc.name = "config-change".into(); sc.raids.push(harness::RaidSpec { kinds: vec![(DroneKind::Shahed, 8), (DroneKind::Geran3, 4), (DroneKind::Kh22, 2), (DroneKind::Iskander, 2)], approach: Approach::TwoSectors, aim: Aim::Smart, dist: 600.0, at: 4200, }); sc.ticks = 20 * 60 * 10; sc } /// A recon flight shot down before its report: the strike must fly on the picture it had, and /// the bounded refresh must never hold the raid waiting for a report that will not come. fn recon_lost() -> Scenario { let mut sc = open(); sc.name = "recon-lost".into(); sc.ticks = 20 * 60 * 6; sc } pub fn main() { let seeds = [1u64, 7, 42]; let scenarios: [(&str, fn() -> Scenario); 4] = [("open", open), ("hills", hills), ("config-change", config_change), ("recon-lost", recon_lost)]; let modes = [Mode::Simple, Mode::Current, Mode::Candidate]; let mut rows = Vec::new(); for (name, make) in scenarios { for mode in modes { for &seed in &seeds { let r = run(mode, name, make, seed); rows.push(row(name, mode, &r)); eprintln!("{name} {} seed {seed}: useful {:.2} diversity {:.2} jitter {:.2} kills {} hits {} reasons {} bearing {} refresh {}", mode.name(), r.useful_share, r.diversity, r.jittery_share, r.kills, r.hits, r.intents, r.bearing_reason, r.refresh_applied); } } } println!("[{}]", rows.join(",\n")); } fn run(mode: Mode, name: &str, make: fn() -> Scenario, seed: u64) -> Report { let mut sc = make(); sc.seed = seed; mode.apply(&mut sc); match name { "config-change" => { let mut changed = false; harness::run_with_hook(&sc, &mut |now, sim: &mut Sim| { if !changed && now >= 3600 && !sim.planning() { changed = true; if let Some(radar) = sim.sams.iter_mut().find(|s| s.kind == SamKind::Radar) { radar.pos += DVec3::new(300.0, 0.0, -200.0); } let id = sim.id(); sim.sams.push(Sam::new(id, SamKind::Pantsir, DVec3::new(-200.0, 70.0, 250.0), 0.0)); sim.set_ew(true); } }) } "recon-lost" => { let mut killed = false; harness::run_with_hook(&sc, &mut |now, sim: &mut Sim| { if !killed && now >= 120 { let recon: Vec = sim.drones.iter().filter(|d| sim.is_recon_drone(d.id)).map(|d| d.id).collect(); if !recon.is_empty() { sim.drones.retain(|d| !recon.contains(&d.id)); killed = true; } } }) } _ => harness::run(&sc), } }