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
+127 -18
View File
@@ -519,6 +519,13 @@ impl Sim {
if plan.smart && !plan.heights.is_empty() {
self.known_relief = Some(std::sync::Arc::new(ew::KnownRelief::new(plan.grid, std::mem::take(&mut plan.heights))));
}
// The bounded refresh moment for the unreleased portion (#149): a recon flight is still
// out, so a report may arrive while the drones wait to launch, and the plan's own picks
// may be re-aimed once on it. The deadline is absolute and the launches keep their times
// — no report never pauses the raid.
if plan.smart && !self.smart_legacy && !self.recon.sorties.is_empty() {
self.refresh = Some(ew::Refresh { deadline: self.tick + ew::REFRESH_WINDOW, reports: self.recon.reports });
}
self.wave = Some(WaveStats {
kills: self.kills,
hits: self.hits,
@@ -604,24 +611,33 @@ impl Sim {
/// gets two or three, the fast strikers first, and all together no more than about a quarter of the raid.
/// Only contacts the picture still trusts: a doubtful one (aged, never re-seen) is not worth a missile.
pub(super) fn radar_strikes(&self, kinds: &[(DroneKind, u32)], picture: &[ew::Contact], leads: &[recon::Mark]) -> Vec<Option<(DVec3, u32)>> {
// Exact disclosure contacts and recon marks of radars, best first. The order is the
// observed role, freshness and quality -- never the id: a hidden station has no id,
// and a big observed radar is worth more than a modest one (#135). Both lists are the
// order's own knowledge version, not a later picture (#146).
// Radars the picture trusts, best first. The candidate ranks the one merged hint list on
// the single public scale (#149): a mark matched to a contact is not a second radar. The
// legacy mode keeps the two chains and their old scales. The order is the observed role,
// freshness and quality -- never the id (#135). Both lists are the order's own knowledge
// version, not a later picture (#146).
let now = self.tick;
let mut radars: Vec<(u8, u64, u32, DVec3)> = picture
.iter()
.filter(|c| c.kind == SamKind::Radar && c.confidence(now) >= ew::Confidence::Probable)
.map(|c| {
let seen = match c.confidence(now) {
ew::Confidence::Confirmed => 4,
ew::Confidence::Probable => 2,
ew::Confidence::Doubtful => 0,
};
(seen * 10 + 3, c.tick, c.id, c.at)
})
.chain(leads.iter().copied().filter(|m| m.category == recon::Category::Radar && m.confidence(now) >= ew::Confidence::Probable).map(|m| (m.priority(now), m.observed, m.id, m.area)))
.collect();
let mut radars: Vec<(u8, u64, u32, DVec3)> = if self.smart_legacy {
picture
.iter()
.filter(|c| c.kind == SamKind::Radar && c.confidence(now) >= ew::Confidence::Probable)
.map(|c| {
let seen = match c.confidence(now) {
ew::Confidence::Confirmed => 4,
ew::Confidence::Probable => 2,
ew::Confidence::Doubtful => 0,
};
(seen * 10 + 3, c.tick, c.id, c.at)
})
.chain(leads.iter().copied().filter(|m| m.category == recon::Category::Radar && m.confidence(now) >= ew::Confidence::Probable).map(|m| (m.priority(now), m.observed, m.id, m.area)))
.collect()
} else {
observe::merge(picture, leads, now)
.into_iter()
.filter(|o| o.category == recon::Category::Radar && o.confidence(now) >= ew::Confidence::Probable)
.map(|o| (o.rank(now), o.observed, o.id, o.at))
.collect()
};
radars.sort_by(|a, b| b.0.cmp(&a.0).then(b.1.cmp(&a.1)).then(a.2.cmp(&b.2)));
let radars: Vec<(u32, DVec3)> = radars.into_iter().map(|(_, _, id, at)| (id, at)).collect();
let flat: Vec<DroneKind> = kinds.iter().flat_map(|&(k, n)| std::iter::repeat_n(k, n as usize)).collect();
@@ -660,7 +676,42 @@ impl Sim {
if aim == Aim::ObjectsAndSams {
return if roll < 0.33 { pick(picture, r).map_or((object, None), |(p, id)| (p, Some(id))) } else { (object, None) };
}
// Smart: each kind at what it is good against; what gave itself away first (a jamming
// The candidate picks from the one merged hint list (#149): a matched mark is not a
// second target, and the fit is the small public policy, not a per-kind guess.
if !self.smart_legacy {
let obs = observe::merge(picture, leads, self.tick);
let pick_o = |list: &[&Observation], r: f64| -> Option<(DVec3, u32)> {
let o = list.get((r * list.len() as f64) as usize)?;
Some((o.at, o.id))
};
let jammers: Vec<&Observation> = obs.iter().filter(|o| o.category == recon::Category::Ew && o.channel == recon::Source::Jamming).collect();
if matches!(kind, DroneKind::Lancet | DroneKind::Kh22) && !jammers.is_empty() && roll < 0.6 {
if let Some((at, id)) = pick_o(&jammers, r) {
return (at, Some(id));
}
}
let guns: Vec<&Observation> = obs.iter().filter(|o| o.category == recon::Category::Gun || o.kind.is_some_and(|k| k.armed() && k.range() <= 300.0)).collect();
let long: Vec<&Observation> = obs.iter().filter(|o| o.category == recon::Category::Radar || o.kind.is_some_and(|k| k.range() >= 450.0)).collect();
let all: Vec<&Observation> = obs.iter().collect();
let choice = match kind {
DroneKind::Lancet if roll < 0.75 => pick_o(&guns, r).or_else(|| pick_o(&all, r)),
DroneKind::Kh22 | DroneKind::Zircon if roll < 0.45 => pick_o(&long, r),
DroneKind::Iskander | DroneKind::Kinzhal if roll < 0.3 => pick_o(&long, r),
DroneKind::Shahed | DroneKind::Geran3 if roll < 0.2 => pick_o(&all, r),
_ => None,
};
if let Some((at, id)) = choice {
return (at, Some(id));
}
// Nothing the kind's usual preference picked: an unmerged mark whose observed
// category fits is the next best reason to turn a strike off the object.
let fits: Vec<&Observation> = obs.iter().filter(|o| o.kind.is_none() && observe::fits(kind, o.category)).collect();
if let Some((at, id)) = pick_o(&fits, r) {
return (at, Some(id));
}
return (object, None);
}
// Legacy smart: each kind at what it is good against; what gave itself away first (a jamming
// station, a radar, a system that fired).
let known_ew: Vec<ew::Contact> = picture.iter().copied().filter(|c| c.kind == SamKind::Ew).collect();
if matches!(kind, DroneKind::Lancet | DroneKind::Kh22) && !known_ew.is_empty() && roll < 0.6 {
@@ -746,6 +797,17 @@ impl Sim {
.filter(|d| d.kind == SamKind::Radar && d.id != c.id && d.at.distance(pos) <= sight::LINK)
.map(|d| ew::published_reach(d.kind, kind, height))
.fold(0.0, f64::max);
// A trusted radar mark near the observed place feeds the network too (#149): the
// strongest published radar reach, since the mark does not name the kind.
let net = if self.smart_legacy {
net
} else {
knowledge.marks
.iter()
.filter(|m| m.category == recon::Category::Radar && m.confidence(now) >= ew::Confidence::Probable && m.area.distance(pos) <= sight::LINK)
.map(|_| observe::radar_envelope(kind, height))
.fold(net, f64::max)
};
let (hi, gun) = (hi.min(own.max(net)), gun.min(own));
let far = hi.max(gun);
// Only the cells round it.
@@ -768,6 +830,53 @@ impl Sim {
}
}
}
// The marks the contacts do not already stand for (#149): an area is priced by its public
// category's published envelope, weighted by the confidence the age alone gives. A mark
// matched to a contact is one hint and was priced through the contact above.
if !self.smart_legacy {
for o in knowledge.observations().into_iter().filter(|o| o.kind.is_none() && o.confidence(now) >= ew::Confidence::Probable) {
let scale: f32 = if o.confidence(now) == ew::Confidence::Confirmed { 1.0 } else { 0.5 };
let pos = o.at;
match o.category {
recon::Category::Ew if kind.jammable() => {
let reach = ew::EW_RADIUS + o.radius;
let (ci, cj) = grid.index(pos);
let r = (reach / grid.cell).ceil() as i32;
for i in (ci - r).max(0)..=(ci + r).min(n - 1) {
for j in (cj - r).max(0)..=(cj + r).min(n - 1) {
cost += 1;
if horizontal(grid.centre((i, j), pos.y) - pos).length() < reach {
prices[(i * n + j) as usize] += 12.0 * scale;
}
}
}
}
recon::Category::Launcher | recon::Category::Gun => {
let (lo, hi, gun) = observe::category_envelope(o.category);
let far = hi.max(gun) + o.radius;
let (ci, cj) = grid.index(pos);
let r = (far / grid.cell).ceil() as i32 + 1;
for i in (ci - r).max(0)..=(ci + r).min(n - 1) {
for j in (cj - r).max(0)..=(cj + r).min(n - 1) {
cost += 1;
let ground = land.map(|l| l[(i * n + j) as usize]).filter(|g| g.is_finite());
let p = grid.centre((i, j), ground.map_or(pos.y + height, |g| f64::from(g) + height));
let d = horizontal(p - pos).length();
if d > far {
continue;
}
let missile = (lo..hi).contains(&d);
if !(missile || d < gun) {
continue;
}
prices[(i * n + j) as usize] += (if missile { 30.0 } else { 18.0 }) * scale;
}
}
}
_ => {}
}
}
}
(prices, cost)
}