Files
airdef/airdef-mod/examples/smart_bench.rs
T
chexit 32748b116c
build / mod (push) Failing after 30s
Smart v2 on top of #146: one public picture, mark prices, bounded refresh, bearing window (#149)
Re-applied the genuinely new #149 features onto kimi-work, REUSING the already-integrated
#146 infrastructure (KnowledgeSnapshot { tick, contacts, marks }, knowledge_now(),
Plan.knowledge, RouteJob.known, versioned price_grid_known and restore). No #146 scaffolding
is duplicated: one snapshot per order, prices over known.tick, versioned restore are kept
exactly as they were. The only additive change to KnowledgeSnapshot is observations().

New #149 layer:
- observe::Observation + observe::merge: Contact and Mark become one public hint, matched by
  public features only (area overlap + exact category); coarse Unknown/contradicting marks stay
  separate, the contact's kind/fix are never rewritten, recon.truth and real ids are not used.
  One Observation::rank scale replaces the two ranks in radar_strikes, choose_target and the
  adaptive picks (kimi-work's slice signatures kept).
- price_grid_known prices marks: a trusted launcher/gun/jammer mark prices its published
  category envelope weighted by confidence (Confirmed x1, Probable x0.5); a radar mark feeds
  the network belief; a mark matched to a contact is priced once through the contact; a
  doubtful mark prices nothing.
- Bounded refresh of the unreleased portion: ew::Refresh with absolute deadline
  REFRESH_WINDOW=600; step_refresh re-aims queued Plan/Sead drones once on a report (typed
  Intent::Refresh, SEAD priority) within SWITCH_CAP and assignment budgets; no report never
  delays a launch.
- Bearing window: Intel.outcomes bounded VecDeque (48 entries, 12000-tick window); best_bearing
  adapts exploration share by typed BearingReason (few/stale/conditions-changed/exploiting);
  conditions are a fingerprint of the public picture, never hidden state. bearing_report() and
  bearing/refresh_*/observations fields in EnemyPictureReport. Legacy fixed share kept.
- examples/smart_bench runner (simple/current/candidate, seeds 1/7/42, open/hills/config-change/
  recon-lost, JSON+lines); Sim::smart_legacy reproduces current Smart; harness::run_with_hook.
  Light modes and bounded jobs unchanged; policy reads no health/charges/hidden switches/positions.

Tests: smart_tests + observe::tests (metamorphic hidden-layout, public dedup, marks in prices,
one version per order in both modes, bounded refresh fires-once/never-pauses, bearing window and
reasons, durable window + Intent::Refresh). The relief-version regression fixture's wall is
widened in z so it crosses any east-west route after the candidate's assignment-order change.
cargo test passes: airdef-core 326 lib + 8 scenarios; airdef-mod 113 lib + core_boundary + 5 scenarios.

Co-Authored-By: Kimi Code <noreply@moonshot.ai>
2026-11-21 10:57:04 +03:00

188 lines
6.7 KiB
Rust

//! 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::<Vec<_>>(),
'\\' => "\\\\".chars().collect::<Vec<_>>(),
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<u32> = 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),
}
}