Smart v2 on top of #146: one public picture, mark prices, bounded refresh, bearing window (#149)
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:
2026-11-21 10:57:04 +03:00
parent b796a439df
commit 32748b116c
11 changed files with 1435 additions and 84 deletions
+41 -1
View File
@@ -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() {