use crate::earth_colony_protocol::PlanetaryBody;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct SimConsciousnessVector {
pub level: f64,
pub meta_awareness: f64,
pub coherence: f64,
pub care_activation: f64,
pub harmonic_alignment: f64,
pub epistemic_confidence: f64,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct MycelixConsciousnessMapping {
pub identity: f64,
pub reputation: f64,
pub community: f64,
pub engagement: f64,
pub combined: f64,
}
impl SimConsciousnessVector {
pub fn to_mycelix_profile(&self) -> MycelixConsciousnessMapping {
let identity =
(self.level * 0.4 + self.meta_awareness * 0.3 + self.epistemic_confidence * 0.3)
.clamp(0.0, 1.0);
let reputation = self.coherence.clamp(0.0, 1.0);
let community = self.care_activation.clamp(0.0, 1.0);
let engagement = self.harmonic_alignment.clamp(0.0, 1.0);
let combined = identity * 0.25 + reputation * 0.25 + community * 0.30 + engagement * 0.20;
MycelixConsciousnessMapping {
identity,
reputation,
community,
engagement,
combined,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum LatencyClass {
RealTime,
NearRealTime,
HighLatency,
ExtremeLatency,
}
impl LatencyClass {
pub fn from_body(body: PlanetaryBody) -> Self {
match body {
PlanetaryBody::Earth | PlanetaryBody::Moon | PlanetaryBody::OrbitalHabitat => {
Self::RealTime
}
PlanetaryBody::Mars | PlanetaryBody::Ceres => Self::NearRealTime,
PlanetaryBody::Europa => Self::HighLatency,
PlanetaryBody::Titan => Self::ExtremeLatency,
}
}
pub fn governance_penalty(&self) -> f64 {
match self {
Self::RealTime => 0.0,
Self::NearRealTime => 0.15, Self::HighLatency => 0.35, Self::ExtremeLatency => 0.50, }
}
pub fn vote_weight_multiplier(&self) -> f64 {
1.0 - self.governance_penalty() * 0.5
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InterplanetaryVote {
pub voter_body: PlanetaryBody,
pub voter_tier: u8,
pub vote: VoteChoice,
pub cast_tick: u32,
pub arrival_tick: u32,
pub time_sensitive: bool,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum VoteChoice {
Yes,
No,
Abstain,
}
pub fn cobb_douglas_to_tend_hours(sector_output: &[f64; 8], population: usize) -> TendEquivalence {
let pop = population.max(1) as f64;
let hours_per_unit = 10.0;
TendEquivalence {
tech_support_hours: sector_output[0] * hours_per_unit / pop,
food_services_hours: sector_output[1] * hours_per_unit / pop,
care_work_hours: sector_output[2] * hours_per_unit / pop,
governance_hours: sector_output[3] * hours_per_unit / pop,
research_hours: sector_output[4] * hours_per_unit / pop,
education_hours: sector_output[5] * hours_per_unit / pop,
creative_hours: sector_output[6] * hours_per_unit / pop,
logistics_hours: sector_output[7] * hours_per_unit / pop,
total_per_capita: sector_output.iter().sum::<f64>() * hours_per_unit / pop,
}
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct TendEquivalence {
pub tech_support_hours: f64,
pub food_services_hours: f64,
pub care_work_hours: f64,
pub governance_hours: f64,
pub research_hours: f64,
pub education_hours: f64,
pub creative_hours: f64,
pub logistics_hours: f64,
pub total_per_capita: f64,
}
impl TendEquivalence {
pub fn within_tend_limits(&self) -> bool {
self.total_per_capita <= 40.0
}
pub fn recommended_vitality_tier(&self) -> &'static str {
if self.total_per_capita > 30.0 {
"Emergency"
} else if self.total_per_capita > 20.0 {
"High"
} else if self.total_per_capita > 10.0 {
"Elevated"
} else {
"Normal"
}
}
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct ValidatedGovernanceParams {
pub veto_override_threshold: f64,
pub max_emergency_sessions: u32,
pub guardian_capture_year: Option<f64>,
pub min_self_governance_population: u32,
pub min_viable_phi: f64,
pub healthy_amendment_rate: f64,
pub seeds_tested: u32,
pub mean_cvs: f64,
pub all_survived: bool,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_consciousness_mapping_preserves_range() {
let sim = SimConsciousnessVector {
level: 0.8,
meta_awareness: 0.6,
coherence: 0.7,
care_activation: 0.9,
harmonic_alignment: 0.5,
epistemic_confidence: 0.4,
};
let mycelix = sim.to_mycelix_profile();
assert!(mycelix.identity >= 0.0 && mycelix.identity <= 1.0);
assert!(mycelix.combined >= 0.0 && mycelix.combined <= 1.0);
assert!(mycelix.community > 0.8);
}
#[test]
fn test_latency_classes() {
assert_eq!(
LatencyClass::from_body(PlanetaryBody::Moon),
LatencyClass::RealTime
);
assert_eq!(
LatencyClass::from_body(PlanetaryBody::Mars),
LatencyClass::NearRealTime
);
assert_eq!(
LatencyClass::from_body(PlanetaryBody::Europa),
LatencyClass::HighLatency
);
assert_eq!(
LatencyClass::from_body(PlanetaryBody::Titan),
LatencyClass::ExtremeLatency
);
}
#[test]
fn test_tend_bridge() {
let output = [10.0, 15.0, 8.0, 5.0, 12.0, 10.0, 3.0, 7.0];
let tend = cobb_douglas_to_tend_hours(&output, 100);
assert!(tend.total_per_capita > 0.0);
assert!(tend.food_services_hours > tend.logistics_hours);
}
#[test]
fn test_governance_penalty_ordering() {
assert!(
LatencyClass::RealTime.governance_penalty()
< LatencyClass::NearRealTime.governance_penalty()
);
assert!(
LatencyClass::NearRealTime.governance_penalty()
< LatencyClass::HighLatency.governance_penalty()
);
assert!(
LatencyClass::HighLatency.governance_penalty()
< LatencyClass::ExtremeLatency.governance_penalty()
);
}
}