Skip to main content

canwu_knowledge/
lib.rs

1//! Actor-relative information kept separate from world ground truth.
2
3use canwu_core::{ArmyId, EventId, PersonId, TerritoryId};
4use canwu_time::SimTime;
5use serde::{Deserialize, Serialize};
6use std::collections::BTreeMap;
7
8#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
9#[serde(tag = "type", rename_all = "snake_case")]
10pub enum KnowledgeSource {
11    DirectObservation,
12    CommandResponsibility,
13    Report { source_event: EventId },
14    ScenarioRecord,
15}
16
17#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
18pub struct EstimateRange {
19    pub minimum: u32,
20    pub maximum: u32,
21}
22
23#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
24pub struct ArmyKnowledge {
25    pub army: ArmyId,
26    pub known_name: Option<String>,
27    pub known_location: Option<TerritoryId>,
28    pub estimated_strength: EstimateRange,
29    pub observed_at: SimTime,
30    pub learned_at: SimTime,
31    pub confidence_per_mille: u16,
32    pub source: KnowledgeSource,
33}
34
35#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
36pub struct ActorKnowledge {
37    pub actor: PersonId,
38    pub armies: BTreeMap<ArmyId, ArmyKnowledge>,
39}
40
41#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
42pub struct KnowledgeSnapshot {
43    pub actors: BTreeMap<PersonId, ActorKnowledge>,
44}
45
46impl KnowledgeSnapshot {
47    #[must_use]
48    pub fn for_actor(&self, actor: PersonId) -> Option<&ActorKnowledge> {
49        self.actors.get(&actor)
50    }
51}