Smart v2 on top of #146: one public picture, mark prices, bounded refresh, bearing window (#149)
build / mod (push) Failing after 30s
build / mod (push) Failing after 30s
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>
This commit is contained in:
@@ -72,6 +72,9 @@ pub struct Scenario {
|
||||
pub ew: bool,
|
||||
/// Ticks a truck on a job may stand still before it counts as stuck.
|
||||
pub stuck_after: u64,
|
||||
/// The smart enemy runs the legacy picks (#149's comparison runner): separate hint lists,
|
||||
/// the lifetime bearing tally, no mark pricing and no refresh of the unreleased portion.
|
||||
pub legacy: bool,
|
||||
}
|
||||
|
||||
impl Scenario {
|
||||
@@ -87,6 +90,7 @@ impl Scenario {
|
||||
stop_at_end: true,
|
||||
ew: false,
|
||||
stuck_after: 600,
|
||||
legacy: false,
|
||||
}
|
||||
}
|
||||
pub fn unit(&mut self, kind: SamKind, x: f64, z: f64) -> &mut Unit {
|
||||
@@ -138,6 +142,18 @@ pub struct Report {
|
||||
pub intents: String,
|
||||
/// The most aim switches one drone went through.
|
||||
pub switches_max: u16,
|
||||
/// Smart drones seen over the run (#149's comparison).
|
||||
pub smart_seen: u32,
|
||||
/// The share of them whose last aim was a live public hint when last seen (#149).
|
||||
pub useful_share: f64,
|
||||
/// Distinct aim units over the smart drones seen, per drone (#149).
|
||||
pub diversity: f64,
|
||||
/// The share of smart drones switched twice or more (#149's jitter).
|
||||
pub jittery_share: f64,
|
||||
/// The bearing picker's last typed reason (#149).
|
||||
pub bearing_reason: String,
|
||||
/// Aims the bounded refresh re-chose (#149).
|
||||
pub refresh_applied: u32,
|
||||
}
|
||||
|
||||
/// The last intent every smart drone of the run was seen carrying, as `name:count`.
|
||||
@@ -146,7 +162,7 @@ fn intent_counts(seen: &HashMap<u32, &'static str>) -> String {
|
||||
for name in seen.values() {
|
||||
*counts.entry(*name).or_insert(0usize) += 1;
|
||||
}
|
||||
["plan", "sead", "react", "replace"].iter().map(|k| format!("{k}:{}", counts.get(*k).copied().unwrap_or(0))).collect::<Vec<_>>().join(",")
|
||||
["plan", "sead", "react", "replace", "refresh"].iter().map(|k| format!("{k}:{}", counts.get(*k).copied().unwrap_or(0))).collect::<Vec<_>>().join(",")
|
||||
}
|
||||
|
||||
fn finite(v: DVec3) -> bool {
|
||||
@@ -154,7 +170,14 @@ fn finite(v: DVec3) -> bool {
|
||||
}
|
||||
|
||||
pub fn run(sc: &Scenario) -> Report {
|
||||
run_with_hook(sc, &mut |_, _| {})
|
||||
}
|
||||
|
||||
/// The same, with a hook called after every tick (#149's comparison runner): a scenario may
|
||||
/// change the defence between waves or shoot a recon flight down before its report.
|
||||
pub fn run_with_hook(sc: &Scenario, hook: &mut dyn FnMut(u64, &mut Sim)) -> Report {
|
||||
let mut sim = Sim::new(sc.seed);
|
||||
sim.smart_legacy = sc.legacy;
|
||||
sim.damage = false; // explosions would change the land the height function describes
|
||||
for u in &sc.units {
|
||||
let id = sim.id();
|
||||
@@ -183,6 +206,8 @@ pub fn run(sc: &Scenario) -> Report {
|
||||
let mut standing: HashMap<u32, (DVec3, u64)> = HashMap::new();
|
||||
// drone id -> the last structured intent it carried (#127).
|
||||
let mut intents_seen: HashMap<u32, &'static str> = HashMap::new();
|
||||
// drone id -> (last aim unit, whether the picture held it live then, switches) (#149).
|
||||
let mut decisions: HashMap<u32, (u32, bool, u16)> = HashMap::new();
|
||||
let mut out = Out::default();
|
||||
for now in 1..=sc.ticks {
|
||||
// Raids come in order: one is ordered once the previous one has been sent.
|
||||
@@ -205,6 +230,7 @@ pub fn run(sc: &Scenario) -> Report {
|
||||
ground.world.serve(&sc.terrain, sections, now);
|
||||
let dt = t.elapsed();
|
||||
times.push(dt);
|
||||
hook(now, &mut sim);
|
||||
if planning {
|
||||
r.planning += dt;
|
||||
r.planning_ticks += 1;
|
||||
@@ -220,6 +246,8 @@ pub fn run(sc: &Scenario) -> Report {
|
||||
for d in sim.drones.iter().chain(sim.queue.iter().map(|(_, d)| d)) {
|
||||
if d.alive() && d.smart() {
|
||||
intents_seen.insert(d.id, d.intent().name());
|
||||
let unit = d.aim_unit();
|
||||
decisions.insert(d.id, (unit, unit != 0 && sim.known_live(unit), d.aim_switches()));
|
||||
}
|
||||
}
|
||||
// The air section a save would take, sampled when the sky is fullest (writing it every tick
|
||||
@@ -271,6 +299,18 @@ pub fn run(sc: &Scenario) -> Report {
|
||||
r.raids_ended = ended.iter().filter(|o| **o).count();
|
||||
r.all_ended = r.raids_ended == sc.raids.len();
|
||||
r.intents = intent_counts(&intents_seen);
|
||||
r.smart_seen = decisions.len() as u32;
|
||||
if !decisions.is_empty() {
|
||||
let n = decisions.len() as f64;
|
||||
r.useful_share = decisions.values().filter(|(_, live, _)| *live).count() as f64 / n;
|
||||
let mut units: Vec<u32> = decisions.values().map(|(u, _, _)| *u).collect();
|
||||
units.sort_unstable();
|
||||
units.dedup();
|
||||
r.diversity = units.len() as f64 / n;
|
||||
r.jittery_share = decisions.values().filter(|(_, _, s)| *s >= 2).count() as f64 / n;
|
||||
}
|
||||
r.bearing_reason = sim.bearing_report().reason.name().to_string();
|
||||
r.refresh_applied = sim.refresh_applied();
|
||||
r.tick_total = times.iter().sum();
|
||||
times.sort();
|
||||
if !times.is_empty() {
|
||||
|
||||
@@ -0,0 +1,187 @@
|
||||
//! 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),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user