Refine the network track's class from the optical look (#136)
build / mod (push) Failing after 1m25s
build / mod (push) Failing after 1m25s
- ClassEst::step_optical: the shared estimate's rule for one passive look — an unsure look (over OPTICAL_CLASS_MAX_UNCERTAINTY) names nothing, a sure one names a class, firms an agreeing probable, replaces a contrary guess - Track::refine_class_optical: the minimal common method — class only; the plot, age, source, quality and own fire rights stay untouched - Sim::apply_optical_classes: the explicit adapter, fed by each observation made this tick through OpticalObservation::estimate; a relay of the refined track carries the class as it was and gains nothing from it - the post still holds no track, emits nothing and authorizes no shot; the refined class reaches the existing #133 track UI through the picture - tests: network refinement, unsure look, relay/stale look add no confidence, equal observables refine equal classes, the step rules Co-Authored-By: Kimi Code <noreply@moonshot.ai>
This commit is contained in:
@@ -272,7 +272,8 @@ API мода `render.set-lights` (до 512, плавно интерполиру
|
||||
Обслуживающая техника (тоже пультами или `/airdef deploy <ключ>`): **РЛС дальнего обнаружения** (`radar`,
|
||||
видит на 2,5 км с высокой мачты, хуже прячутся за рельефом), **склад боеприпасов** (`depot`), **ТЗМ** (`tzm`),
|
||||
**станция РЭБ** (`ew`), **прожектор** (`light`), **оптический пост** (`optical`: пассивно уточняет широкий класс
|
||||
контакта по прямой видимости, не излучает и не ведёт огневой трек). Новые комплексы: `irist`, `nasams`, `buk`, `tor`, `p1sun`.
|
||||
контакта по прямой видимости и передаёт уточнение в класс уже известного сетевого трека — без своего трека,
|
||||
свежести и права на пуск; не излучает и не ведёт огневой трек). Новые комплексы: `irist`, `nasams`, `buk`, `tor`, `p1sun`.
|
||||
|
||||
**Согласование огня.** Комплексы делят цели между собой: на обычную цель идёт одна ракета, на баллистическую две; чем ближе цель к своей точке попадания,
|
||||
тем больше перехватчиков разрешено на неё сразу (за ~12 с до удара ещё один, за ~5 с — ещё один). Комплекс, у которого кончились ракеты
|
||||
|
||||
@@ -612,6 +612,10 @@ impl Class {
|
||||
}
|
||||
}
|
||||
|
||||
/// An optical observation this unsure (0 best, 1 worst) names no class for the network (#136):
|
||||
/// the post still shows its own look, but the shared estimate keeps what the radars made of it.
|
||||
pub const OPTICAL_CLASS_MAX_UNCERTAINTY: f64 = 0.5;
|
||||
|
||||
/// What the radars make of a track's class, from the measurements alone (#133): separate from
|
||||
/// the track's confirmation (`Track::ident`, how firmly it is held), its own state with its own
|
||||
/// rules. It travels with the measurement it grew from: a relay passes it as it was, ageing with
|
||||
@@ -650,6 +654,24 @@ impl ClassEst {
|
||||
}
|
||||
}
|
||||
|
||||
/// The estimate stepped by one passive optical observation (#136): an independent look at the
|
||||
/// same contact, never a radar measurement and never a relay. A look too unsure to name a
|
||||
/// class (uncertainty over [`OPTICAL_CLASS_MAX_UNCERTAINTY`]) changes nothing. A sure look
|
||||
/// names a class where none was, firms a probable one that agrees, and replaces a contrary
|
||||
/// hypothesis with the new guess — the same arithmetic as [`Self::step`], fed by the optics
|
||||
/// instead of the beam. It touches the class alone: no plot, no freshness and no fire right
|
||||
/// travels with it, and a relay of the refined track carries the class as it was.
|
||||
pub fn step_optical(self, class: Class, uncertainty: f64) -> ClassEst {
|
||||
if uncertainty > OPTICAL_CLASS_MAX_UNCERTAINTY {
|
||||
return self;
|
||||
}
|
||||
match self {
|
||||
ClassEst::Unknown => ClassEst::Probable(class),
|
||||
ClassEst::Probable(had) | ClassEst::Firm(had) if had == class => ClassEst::Firm(had),
|
||||
_ => ClassEst::Probable(class),
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether a system's roles cover the track's class. The explicit policy for the unknown
|
||||
/// (#133): an unidentified track is not blocked by the class filter — it stays a candidate
|
||||
/// under the general rules, and `why` says so. A system with no roles at all is holding its
|
||||
|
||||
+186
-11
@@ -16,10 +16,11 @@
|
||||
//! mode in this first version. Weather/fog is not in the simulation API yet, so only the game's own
|
||||
//! day/night state and the world geometry are used here.
|
||||
//!
|
||||
//! #133 owns the shared class-estimate contract. This module keeps its own small
|
||||
//! [`OpticalObservation`]/[`OpticalClassEstimate`] types rather than inventing that contract silently: a
|
||||
//! future classifier can consume [`Sim::optical_reports`] or the observation's [`OpticalClassEstimate`]
|
||||
//! without this post pretending to be a [`Track`]. Nothing here reads [`DroneKind`] to classify.
|
||||
//! #133 owns the shared class-estimate contract. The observation stays an independent
|
||||
//! [`OpticalObservation`] — never a [`Track`] — and the explicit adapter [`Sim::apply_optical_classes`]
|
||||
//! feeds its [`OpticalClassEstimate`] into the class of the network's existing tracks through
|
||||
//! [`ClassEst::step_optical`]: class only, no plot, no freshness, no fire right, and a relay of the
|
||||
//! refined track gains nothing from being relayed. Nothing here reads [`DroneKind`] to classify.
|
||||
//!
|
||||
//! The catalog row currently reuses the existing `airdef:radar_truck` and `airdef:radar_panel`
|
||||
//! models, and the deploy item aliases the radar icon, until the optical post's own assets land.
|
||||
@@ -114,9 +115,10 @@ pub struct OpticalObservable {
|
||||
pub range: f64,
|
||||
}
|
||||
|
||||
/// A provisional wide class from observable motion alone. #133 will own the shared classifier;
|
||||
/// this function is the one place that provisional rule lives, and it never looks at `DroneKind`.
|
||||
/// Equal observable data therefore gives an equal answer for different true models.
|
||||
/// A wide class from observable motion alone, the optics' own bands (a descending fast contact
|
||||
/// reads ballistic). It never looks at `DroneKind`: equal observable data therefore gives an
|
||||
/// equal answer for different true models. The shared estimate consumes the result through
|
||||
/// [`ClassEst::step_optical`], not the radar's speed bands.
|
||||
pub fn classify_optical(observable: OpticalObservable) -> Class {
|
||||
let speed = observable.speed;
|
||||
if speed >= 6.5 || (speed >= 3.0 && observable.climb <= -0.35) {
|
||||
@@ -132,8 +134,9 @@ pub fn classify_optical(observable: OpticalObservable) -> Class {
|
||||
}
|
||||
}
|
||||
|
||||
/// The minimum a future class-estimate consumer (#133) needs from one optical observation.
|
||||
/// Deliberately local: the shared contract is not invented here.
|
||||
/// What the shared class estimate (#133) consumes from one optical observation: the wide class
|
||||
/// and how unsure it is. The adapter [`Sim::apply_optical_classes`] reads it through
|
||||
/// [`OpticalObservation::estimate`]; the estimate's own rules live in [`ClassEst::step_optical`].
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub struct OpticalClassEstimate {
|
||||
pub class: Class,
|
||||
@@ -166,7 +169,7 @@ impl OpticalObservation {
|
||||
pub fn age(&self, now: u64) -> u64 {
|
||||
now.saturating_sub(self.tick)
|
||||
}
|
||||
/// The adapter to the future #133 contract.
|
||||
/// The adapter to the shared #133 class estimate.
|
||||
pub fn estimate(&self) -> OpticalClassEstimate {
|
||||
OpticalClassEstimate { class: self.class, uncertainty: self.uncertainty }
|
||||
}
|
||||
@@ -431,7 +434,8 @@ impl Sim {
|
||||
}
|
||||
|
||||
/// One tick of every optical post: age state, then spend the bounded line-of-sight budget.
|
||||
/// It never writes a [`Track`] and never calls the enemy-intel emission channel.
|
||||
/// It never creates a [`Track`] and never calls the enemy-intel emission channel; the class
|
||||
/// adapter afterwards only refines the class of tracks the network already holds.
|
||||
pub(super) fn update_optics(&mut self, ground: &mut Ground) {
|
||||
let now = self.tick;
|
||||
let posts: Vec<usize> = self
|
||||
@@ -556,6 +560,38 @@ impl Sim {
|
||||
sam.state = SamState::Search;
|
||||
sam.optical.target = Some(target);
|
||||
}
|
||||
self.apply_optical_classes();
|
||||
}
|
||||
|
||||
/// The adapter from the passive optics to the shared class estimate (#136 into #133): every
|
||||
/// observation made this tick refines the class of the network's tracks for that contact,
|
||||
/// through the observation's own [`OpticalClassEstimate`]. Class only — the plot, its age,
|
||||
/// source, quality and fire rights are untouched, and a relay of the refined track carries
|
||||
/// the class as it was: the relay itself adds nothing. A contact the network has no track for
|
||||
/// is left to the post's own report; the optics never invent a track.
|
||||
fn apply_optical_classes(&mut self) {
|
||||
let now = self.tick;
|
||||
let looks: Vec<(u32, OpticalClassEstimate)> = self
|
||||
.sams
|
||||
.iter()
|
||||
.filter(|s| s.kind == SamKind::Optical)
|
||||
.filter_map(|s| s.optical.observation())
|
||||
.filter(|o| o.tick == now)
|
||||
.map(|o| (o.target, o.estimate()))
|
||||
.collect();
|
||||
if looks.is_empty() {
|
||||
return;
|
||||
}
|
||||
for sam in &mut self.sams {
|
||||
if sam.kind == SamKind::Optical {
|
||||
continue;
|
||||
}
|
||||
for t in &mut sam.tracks {
|
||||
if let Some(&(_, est)) = looks.iter().find(|(id, _)| *id == t.id) {
|
||||
t.refine_class_optical(est.class, est.uncertainty);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -958,4 +994,143 @@ mod tests {
|
||||
assert!(sam.tracks.is_empty());
|
||||
assert!(sim.intel.contacts().is_empty(), "a passive post entered the enemy's emission picture");
|
||||
}
|
||||
|
||||
/// A relayed network track of the contact: no own measurement, no fire right.
|
||||
fn relayed_track(sim: &mut Sim, sam: usize, id: u32, class: ClassEst) {
|
||||
let d = sim.drones.iter().find(|d| d.id == id).unwrap();
|
||||
sim.sams[sam].tracks.push(Track {
|
||||
id,
|
||||
class,
|
||||
pos: d.pos,
|
||||
vel: d.vel,
|
||||
tick: 0,
|
||||
own_tick: 0,
|
||||
source: u32::MAX,
|
||||
product: battery::Measure::Search,
|
||||
quality: 60,
|
||||
own_product: battery::Measure::Search,
|
||||
own_quality: 0,
|
||||
ttl: 100_000,
|
||||
hits: 1,
|
||||
locked: false,
|
||||
});
|
||||
}
|
||||
|
||||
// The adapter (#136 into #133): a sure optical look refines the class of the network's existing
|
||||
// track — class only, no plot, no freshness, no fire right, and the post still holds no track.
|
||||
#[test]
|
||||
fn an_optical_look_refines_the_network_track_class() {
|
||||
let mut sim = Sim::new(17);
|
||||
let radar = sim.id();
|
||||
sim.sams.push(Sam::new(radar, SamKind::Radar, DVec3::new(0.0, 70.0, 0.0), 0.0));
|
||||
let post = optical_at(&mut sim, 0.0, 0.0, 0.0);
|
||||
let id = flat_drone(&mut sim, DroneKind::Shahed, DVec3::new(0.0, 95.0, -100.0), DVec3::new(0.5, 0.0, -0.6));
|
||||
relayed_track(&mut sim, 0, id, ClassEst::Unknown);
|
||||
let before = sim.sams[0].tracks[0];
|
||||
let mut ground = clear_ground();
|
||||
run(&mut sim, &mut ground, 200);
|
||||
let o = sim.optical_report(post).unwrap().observation.expect("the post never observed");
|
||||
let t = sim.sams[0].tracks[0];
|
||||
assert_eq!(t.class, ClassEst::Probable(o.class), "the optical look never reached the network track");
|
||||
assert_eq!(sim.picture().get(&id).unwrap().class, t.class, "the shared picture did not carry the refined class");
|
||||
assert_eq!(
|
||||
(t.pos, t.vel, t.tick, t.own_tick, t.source, t.product, t.quality, t.own_product, t.own_quality, t.hits, t.locked),
|
||||
(before.pos, before.vel, before.tick, before.own_tick, before.source, before.product, before.quality, before.own_product, before.own_quality, before.hits, before.locked),
|
||||
"the optical look touched more than the class"
|
||||
);
|
||||
assert!(!t.own_authorizes(sim.tick), "optics granted fire authority");
|
||||
assert!(sim.sams.iter().find(|s| s.id == post).unwrap().tracks.is_empty(), "the look became a track");
|
||||
}
|
||||
|
||||
// A look too unsure to name a class leaves the shared estimate as the radars made it.
|
||||
#[test]
|
||||
fn an_unsure_look_leaves_the_class_alone() {
|
||||
let mut sim = Sim::new(18);
|
||||
let radar = sim.id();
|
||||
sim.sams.push(Sam::new(radar, SamKind::Radar, DVec3::new(0.0, 70.0, 0.0), 0.0));
|
||||
let post = optical_at(&mut sim, 0.0, 0.0, 0.0);
|
||||
let id = flat_drone(&mut sim, DroneKind::Shahed, DVec3::new(0.0, 95.0, -290.0), DVec3::new(0.5, 0.0, -0.6));
|
||||
relayed_track(&mut sim, 0, id, ClassEst::Unknown);
|
||||
let mut ground = clear_ground();
|
||||
// The far contact sits beyond the shared helper's geometry: answer its columns and sections too.
|
||||
let mut cols = Vec::new();
|
||||
for x in -24..=24 {
|
||||
for z in -320..=-180 {
|
||||
cols.push((x, z, 70));
|
||||
}
|
||||
}
|
||||
ground.answer(cols, 0);
|
||||
let mut answers = Vec::new();
|
||||
for x in -1..=1 {
|
||||
for y in 3..=7 {
|
||||
for z in -21..=-12 {
|
||||
answers.push(world::SectionAnswer { sec: (x, y, z), fill: world::Fill::Empty });
|
||||
}
|
||||
}
|
||||
}
|
||||
ground.world.answer(answers, 0);
|
||||
run(&mut sim, &mut ground, 200);
|
||||
let o = sim.optical_report(post).unwrap().observation.expect("the post never observed");
|
||||
assert!(o.uncertainty > OPTICAL_CLASS_MAX_UNCERTAINTY, "the look was sure after all: {}", o.uncertainty);
|
||||
assert_eq!(sim.sams[0].tracks[0].class, ClassEst::Unknown, "an unsure look named a class");
|
||||
}
|
||||
|
||||
// A relayed track is not a look: with no observation of its own the post never firms a class,
|
||||
// and a stale observation (the post died) never keeps refining either.
|
||||
#[test]
|
||||
fn a_relay_and_a_stale_look_add_no_confidence() {
|
||||
let mut sim = Sim::new(19);
|
||||
let radar = sim.id();
|
||||
sim.sams.push(Sam::new(radar, SamKind::Radar, DVec3::new(0.0, 70.0, 0.0), 0.0));
|
||||
let post = optical_at(&mut sim, 0.0, 0.0, 0.0);
|
||||
let far = flat_drone(&mut sim, DroneKind::Shahed, DVec3::new(0.0, 95.0, -500.0), DVec3::new(0.5, 0.0, -0.6));
|
||||
relayed_track(&mut sim, 0, far, ClassEst::Probable(Class::Drone));
|
||||
let mut ground = clear_ground();
|
||||
run(&mut sim, &mut ground, 200);
|
||||
assert!(sim.optical_report(post).unwrap().observation.is_none());
|
||||
assert_eq!(sim.sams[0].tracks[0].class, ClassEst::Probable(Class::Drone), "a relay firmed the class");
|
||||
// Now a near contact is really observed once; then the post dies and a fresh radar
|
||||
// measurement resets the class: the dead post's old look must not refine it again.
|
||||
let near = flat_drone(&mut sim, DroneKind::Shahed, DVec3::new(0.0, 95.0, -100.0), DVec3::new(0.5, 0.0, -0.6));
|
||||
relayed_track(&mut sim, 0, near, ClassEst::Unknown);
|
||||
run(&mut sim, &mut ground, 200);
|
||||
let k = sim.sams[0].tracks.iter().position(|t| t.id == near).unwrap();
|
||||
assert_eq!(sim.sams[0].tracks[k].class, ClassEst::Probable(Class::Drone));
|
||||
sim.sams.iter_mut().find(|s| s.id == post).unwrap().health = 0.0;
|
||||
sim.sams[0].tracks[k].class = ClassEst::Unknown;
|
||||
run(&mut sim, &mut ground, 200);
|
||||
assert_eq!(sim.sams[0].tracks[k].class, ClassEst::Unknown, "a stale look kept refining");
|
||||
}
|
||||
|
||||
// The refined class comes from the observables, never the true model: two different kinds
|
||||
// flying alike refine the network's tracks alike.
|
||||
#[test]
|
||||
fn equal_observables_refine_equal_classes() {
|
||||
fn refined(kind: DroneKind) -> ClassEst {
|
||||
let mut sim = Sim::new(20);
|
||||
let radar = sim.id();
|
||||
sim.sams.push(Sam::new(radar, SamKind::Radar, DVec3::new(0.0, 70.0, 0.0), 0.0));
|
||||
optical_at(&mut sim, 0.0, 0.0, 0.0);
|
||||
let id = flat_drone(&mut sim, kind, DVec3::new(0.0, 95.0, -100.0), DVec3::new(0.5, 0.0, -0.6));
|
||||
relayed_track(&mut sim, 0, id, ClassEst::Unknown);
|
||||
let mut ground = clear_ground();
|
||||
run(&mut sim, &mut ground, 200);
|
||||
sim.sams[0].tracks[0].class
|
||||
}
|
||||
assert_eq!(refined(DroneKind::Shahed), refined(DroneKind::Kinzhal));
|
||||
assert_eq!(refined(DroneKind::Shahed), ClassEst::Probable(Class::Drone));
|
||||
}
|
||||
|
||||
// The shared estimate's optical rule itself: the unsure gate, naming, firming, replacing.
|
||||
#[test]
|
||||
fn the_optical_step_rules() {
|
||||
assert_eq!(ClassEst::Unknown.step_optical(Class::Jet, 0.9), ClassEst::Unknown);
|
||||
assert_eq!(ClassEst::Probable(Class::Drone).step_optical(Class::Jet, 0.6), ClassEst::Probable(Class::Drone));
|
||||
assert_eq!(ClassEst::Unknown.step_optical(Class::Jet, 0.2), ClassEst::Probable(Class::Jet));
|
||||
assert_eq!(ClassEst::Probable(Class::Jet).step_optical(Class::Jet, 0.2), ClassEst::Firm(Class::Jet));
|
||||
assert_eq!(ClassEst::Firm(Class::Jet).step_optical(Class::Jet, 0.2), ClassEst::Firm(Class::Jet));
|
||||
assert_eq!(ClassEst::Probable(Class::Drone).step_optical(Class::Jet, 0.2), ClassEst::Probable(Class::Jet));
|
||||
assert_eq!(ClassEst::Firm(Class::Drone).step_optical(Class::Jet, 0.2), ClassEst::Probable(Class::Jet));
|
||||
assert_eq!(ClassEst::Unknown.step_optical(Class::Jet, OPTICAL_CLASS_MAX_UNCERTAINTY), ClassEst::Probable(Class::Jet));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -326,6 +326,12 @@ impl Track {
|
||||
pub fn measured_by(&self) -> Option<u32> {
|
||||
(self.source != 0).then_some(self.source)
|
||||
}
|
||||
/// One passive optical look at this contact (#136): refines the class alone. The plot, its
|
||||
/// age, source, quality and the station's own fire rights are untouched — optics never
|
||||
/// authorize a shot and never make a track fresher.
|
||||
pub fn refine_class_optical(&mut self, class: Class, uncertainty: f64) {
|
||||
self.class = self.class.step_optical(class, uncertainty);
|
||||
}
|
||||
pub fn ident(&self) -> Ident {
|
||||
match self.hits {
|
||||
0 | 1 => Ident::Unknown,
|
||||
|
||||
Reference in New Issue
Block a user