32748b116c
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>
269 lines
12 KiB
Rust
269 lines
12 KiB
Rust
//! The planner's one public observation (#149): a disclosure `Contact` and a recon `Mark` are
|
|
//! two channels hinting at the same game objects, on two different scales. This module projects
|
|
//! both into a single [`Observation`] — an area, a channel, an age, a confidence and the public
|
|
//! game features — and matches them by those public features alone: a mark whose area holds a
|
|
//! contact's fix and whose observed category agrees is the same hint, not a second target.
|
|
//!
|
|
//! A match is a belief, never a fact: it is made only on an exact public category agreement and
|
|
//! area overlap, it is flagged (`matched`), and it invents nothing — the contact keeps the kind
|
|
//! and place it was observed with, the mark only adds what it publicly saw (a refined radar role,
|
|
//! a fresher look). A coarse `Unknown` mark or a contradicting category is *not* matched: it stays
|
|
//! a separate hint. The observer's truth map and the units' real ids play no part here.
|
|
use super::*;
|
|
|
|
/// A contact fix this far inside a mark's area (on top of its radius) reads as the same public
|
|
/// hint. The fix is exact, the area is coarse: the slack is the cell jitter a report carries.
|
|
const MATCH_SLACK: f64 = 8.0;
|
|
|
|
/// One public hint about one game object, from either channel (#149). There is no health,
|
|
/// magazine, link, hidden switch or true place in it: `kind` is `Some` only for a disclosure
|
|
/// contact, whose type was identified at the observation; a mark carries its coarse category.
|
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
|
pub struct Observation {
|
|
/// The hint's public id: a contact's id, or a mark's synthetic one. Never a matched unit's truth.
|
|
pub id: u32,
|
|
/// The best public place: a contact's fix, or a mark's area centre.
|
|
pub at: DVec3,
|
|
/// 0 for an exact fix; the area's radius for a mark.
|
|
pub radius: f64,
|
|
/// The channel that showed it last: flyby, emission, jamming or launch.
|
|
pub channel: recon::Source,
|
|
/// The tick of the observation this hint rests on.
|
|
pub observed: u64,
|
|
pub category: recon::Category,
|
|
/// A radar's role, once a refined look told it.
|
|
pub role: Option<battery::RadarRole>,
|
|
/// The type identified at a disclosure observation; `None` for a recon mark.
|
|
pub kind: Option<SamKind>,
|
|
pub quality: recon::Quality,
|
|
/// A second public hint agreed by area and category. A belief for the diagnostic, not a fact.
|
|
pub matched: bool,
|
|
}
|
|
|
|
impl Observation {
|
|
pub fn age(&self, now: u64) -> u64 {
|
|
now.saturating_sub(self.observed)
|
|
}
|
|
pub fn confidence(&self, now: u64) -> Confidence {
|
|
ew::confidence_for_age(self.age(now))
|
|
}
|
|
/// An exact disclosure fix, rather than a coarse area.
|
|
pub fn exact(&self) -> bool {
|
|
self.radius == 0.0
|
|
}
|
|
pub fn live(&self, now: u64) -> bool {
|
|
self.age(now) < ew::CONTACT_TTL
|
|
}
|
|
/// The one ranking scale both channels share (#149): the mark's priority parts (freshness,
|
|
/// quality, observed role) plus a small premium for being a fix rather than an area.
|
|
pub fn rank(&self, now: u64) -> u8 {
|
|
let (f, q, r) = recon::priority_parts(self.confidence(now), self.quality, self.category, self.role);
|
|
f * 4 + q * 3 + r + u8::from(self.exact()) * 3
|
|
}
|
|
}
|
|
|
|
/// The disclosure channel in the one scale the marks already use.
|
|
pub(super) fn channel_of(seen: ew::Seen) -> recon::Source {
|
|
match seen {
|
|
ew::Seen::Launch => recon::Source::Launch,
|
|
ew::Seen::Emission => recon::Source::Emission,
|
|
ew::Seen::Jamming => recon::Source::Jamming,
|
|
}
|
|
}
|
|
|
|
/// Projects contacts and marks into one list of public hints, best first. A mark is matched to a
|
|
/// contact only by public features (area overlap and an exact category agreement); a matched mark
|
|
/// is consumed — the object is one hint, priced and assigned once. Unmatched marks stand as areas.
|
|
pub(super) fn merge(contacts: &[ew::Contact], marks: &[recon::Mark], now: u64) -> Vec<Observation> {
|
|
let mut out: Vec<Observation> = contacts
|
|
.iter()
|
|
.filter(|c| c.live(now))
|
|
.map(|c| Observation {
|
|
id: c.id,
|
|
at: c.at,
|
|
radius: 0.0,
|
|
channel: channel_of(c.seen),
|
|
observed: c.tick,
|
|
category: recon::Category::of(c.kind),
|
|
role: None,
|
|
kind: Some(c.kind),
|
|
quality: recon::Quality::Refined,
|
|
matched: false,
|
|
})
|
|
.collect();
|
|
let mut areas = Vec::new();
|
|
for m in marks.iter().filter(|m| m.live(now)) {
|
|
let hit = out.iter_mut().find(|o| {
|
|
o.kind.is_some()
|
|
&& m.category != recon::Category::Unknown
|
|
&& m.category == o.category
|
|
&& (m.role.is_none() || o.category == recon::Category::Radar)
|
|
&& horizontal(o.at - m.area).length() <= m.radius + MATCH_SLACK
|
|
});
|
|
match hit {
|
|
Some(o) => {
|
|
// The match is public evidence, not truth: the fresher look and the refined role
|
|
// are what the mark itself saw; the contact's kind and fix are never rewritten.
|
|
o.matched = true;
|
|
if m.observed > o.observed {
|
|
o.observed = m.observed;
|
|
o.channel = m.source;
|
|
}
|
|
if o.category == recon::Category::Radar && m.role.is_some() {
|
|
o.role = m.role;
|
|
}
|
|
}
|
|
None => areas.push(Observation {
|
|
id: m.id,
|
|
at: m.area,
|
|
radius: m.radius,
|
|
channel: m.source,
|
|
observed: m.observed,
|
|
category: m.category,
|
|
role: m.role,
|
|
kind: None,
|
|
quality: m.quality,
|
|
matched: false,
|
|
}),
|
|
}
|
|
}
|
|
out.extend(areas);
|
|
out.sort_by(|a, b| b.rank(now).cmp(&a.rank(now)).then(b.observed.cmp(&a.observed)).then(a.id.cmp(&b.id)));
|
|
out
|
|
}
|
|
|
|
/// The small game policy (#149): which observed categories a kind is worth turning onto. One
|
|
/// place for the fit both the plan's picks and the adaptive assignments read — no hidden state,
|
|
/// only the public category and the kind's published role.
|
|
pub(super) fn fits(kind: DroneKind, category: recon::Category) -> bool {
|
|
use recon::Category as C;
|
|
match kind {
|
|
DroneKind::Lancet => matches!(category, C::Gun | C::Launcher | C::Ew),
|
|
DroneKind::Kh22 | DroneKind::Zircon => matches!(category, C::Radar | C::Launcher | C::Ew),
|
|
DroneKind::Iskander | DroneKind::Kinzhal => matches!(category, C::Radar | C::Launcher),
|
|
DroneKind::Shahed | DroneKind::Geran3 => matches!(category, C::Radar | C::Launcher | C::Gun | C::Ew),
|
|
_ => false,
|
|
}
|
|
}
|
|
|
|
/// The public worst-case envelope of a category: the furthest missile reach and gun range any
|
|
/// published kind of that category has, for this drone at this height. What a mark's area may
|
|
/// hold is priced by the catalog, never by a hidden unit's actual load (#149).
|
|
pub(super) fn category_envelope(category: recon::Category) -> (f64, f64, f64) {
|
|
let mut lo = f64::INFINITY;
|
|
let mut hi = 0.0f64;
|
|
let mut gun = 0.0f64;
|
|
for k in SamKind::ALL {
|
|
if recon::Category::of(k) != category {
|
|
continue;
|
|
}
|
|
let sp = k.spec();
|
|
if let Some(m) = &sp.missile {
|
|
lo = lo.min(m.min);
|
|
hi = hi.max(m.max);
|
|
}
|
|
if let Some(g) = &sp.gun {
|
|
gun = gun.max(g.range);
|
|
}
|
|
}
|
|
(lo.min(hi), hi, gun)
|
|
}
|
|
|
|
/// The published reach of the strongest radar kind, for a mark that only says "a radar is here".
|
|
pub(super) fn radar_envelope(drone: DroneKind, height: f64) -> f64 {
|
|
SamKind::ALL
|
|
.into_iter()
|
|
.filter(|k| recon::Category::of(*k) == recon::Category::Radar)
|
|
.map(|k| ew::published_reach(k, drone, height))
|
|
.fold(0.0, f64::max)
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
fn contact(id: u32, kind: SamKind, at: DVec3, tick: u64) -> ew::Contact {
|
|
ew::Contact { id, kind, at, tick, seen: ew::Seen::Emission, emission: Some(tick), destroyed: None, launches: 0 }
|
|
}
|
|
|
|
fn mark(id: u32, at: DVec3, category: recon::Category, observed: u64) -> recon::Mark {
|
|
recon::Mark {
|
|
id,
|
|
area: at,
|
|
radius: recon::COARSE_AREA,
|
|
category,
|
|
role: None,
|
|
source: recon::Source::Flyby,
|
|
observed,
|
|
reported: observed,
|
|
quality: recon::Quality::Coarse,
|
|
looks: 1,
|
|
}
|
|
}
|
|
|
|
// #149: one object, two channels, one hint. A mark whose area holds the contact's fix and
|
|
// whose category agrees is matched and consumed — not a second target. The match reads only
|
|
// public features: two marks of different hidden truths but the same public area/category
|
|
// both fold into the one contact.
|
|
#[test]
|
|
fn a_matching_mark_is_one_hint_not_two() {
|
|
let at = DVec3::new(100.0, 70.0, 0.0);
|
|
let c = contact(16, SamKind::Radar, at, 100);
|
|
let m1 = mark(recon::ID_BASE + 1, at + DVec3::new(20.0, 0.0, 0.0), recon::Category::Radar, 120);
|
|
let m2 = mark(recon::ID_BASE + 2, at + DVec3::new(-30.0, 0.0, 10.0), recon::Category::Radar, 130);
|
|
let obs = merge(&[c], &[m1, m2], 200);
|
|
assert_eq!(obs.len(), 1, "the same public object stayed two hints");
|
|
assert!(obs[0].matched && obs[0].exact() && obs[0].kind == Some(SamKind::Radar));
|
|
assert_eq!(obs[0].observed, 130, "the fresher public look was not taken");
|
|
assert_eq!(obs[0].id, 16, "the hint kept the mark's synthetic id over the contact's");
|
|
}
|
|
|
|
// #149: an unconfirmed match is not a fact. A coarse Unknown mark, a contradicting category,
|
|
// or an area that does not hold the fix stays a separate hint — nothing is merged on a guess.
|
|
#[test]
|
|
fn an_unconfirmed_match_stays_separate() {
|
|
let at = DVec3::new(100.0, 70.0, 0.0);
|
|
let c = contact(16, SamKind::Radar, at, 100);
|
|
let unknown = mark(recon::ID_BASE + 1, at, recon::Category::Unknown, 120);
|
|
let wrong = mark(recon::ID_BASE + 2, at, recon::Category::Launcher, 120);
|
|
let far = mark(recon::ID_BASE + 3, at + DVec3::new(400.0, 0.0, 0.0), recon::Category::Radar, 120);
|
|
let obs = merge(&[c], &[unknown, wrong, far], 200);
|
|
assert_eq!(obs.len(), 4, "a weak match was treated as a fact");
|
|
assert!(obs.iter().filter(|o| o.kind.is_some()).all(|o| !o.matched));
|
|
// A refined role is public only for a radar; a launcher mark never lends one.
|
|
let mut radar = mark(recon::ID_BASE + 4, at, recon::Category::Radar, 140);
|
|
radar.quality = recon::Quality::Refined;
|
|
radar.role = Some(battery::RadarRole::Engagement);
|
|
let obs = merge(&[c], &[radar], 200);
|
|
assert_eq!(obs.len(), 1);
|
|
assert_eq!(obs[0].role, Some(battery::RadarRole::Engagement));
|
|
}
|
|
|
|
// #149: one scale. A fresh confirmed fix outranks an old doubtful area; a refined big-role
|
|
// mark outranks a coarse modest one of the same age; the order never reads an id or a truth.
|
|
#[test]
|
|
fn the_rank_is_one_public_scale() {
|
|
let fresh = contact(16, SamKind::Radar, DVec3::ZERO, 190);
|
|
let old = mark(recon::ID_BASE + 1, DVec3::X * 500.0, recon::Category::Launcher, 0);
|
|
let obs = merge(&[fresh], &[old], 200);
|
|
assert_eq!(obs[0].id, 16, "a fresh fix did not lead an old area");
|
|
let mut big = mark(recon::ID_BASE + 2, DVec3::X * 900.0, recon::Category::Radar, 190);
|
|
big.quality = recon::Quality::Refined;
|
|
big.role = Some(battery::RadarRole::Engagement);
|
|
let modest = mark(recon::ID_BASE + 3, DVec3::X * 1300.0, recon::Category::Radar, 190);
|
|
let obs = merge(&[], &[modest, big], 200);
|
|
assert_eq!(obs[0].id, big.id, "the bigger observed role did not lead");
|
|
assert!(obs[0].rank(200) > obs[1].rank(200));
|
|
}
|
|
|
|
// #149: the policy fit is the public category, the same for the plan and the adaptive picks.
|
|
#[test]
|
|
fn the_fit_is_the_public_category() {
|
|
assert!(fits(DroneKind::Lancet, recon::Category::Gun));
|
|
assert!(!fits(DroneKind::Lancet, recon::Category::Radar));
|
|
assert!(fits(DroneKind::Kh22, recon::Category::Radar));
|
|
assert!(!fits(DroneKind::Iskander, recon::Category::Gun));
|
|
assert!(!fits(DroneKind::Gerbera, recon::Category::Launcher));
|
|
}
|
|
}
|