use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DebateRound {
pub round: u32,
pub blue_claim: String,
pub red_challenge: String,
pub blue_rebuttal: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Debate {
pub id: Uuid,
pub blue_agent_id: Uuid,
pub red_agent_id: Uuid,
pub initial_claim: String,
pub rounds: Vec<DebateRound>,
pub verdict: Option<bool>,
pub confidence: f64,
}
impl Debate {
pub fn new(blue_id: Uuid, red_id: Uuid, claim: &str) -> Self {
Self {
id: Uuid::new_v4(),
blue_agent_id: blue_id,
red_agent_id: red_id,
initial_claim: claim.to_string(),
rounds: Vec::new(),
verdict: None,
confidence: 0.0,
}
}
pub fn add_round(&mut self, round: DebateRound) {
self.rounds.push(round);
}
pub fn conclude(&mut self, upheld: bool, confidence: f64) {
self.verdict = Some(upheld);
self.confidence = confidence.clamp(0.0, 1.0);
}
pub fn is_concluded(&self) -> bool {
self.verdict.is_some()
}
pub fn round_count(&self) -> usize {
self.rounds.len()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_debate_lifecycle() {
let mut debate = Debate::new(Uuid::new_v4(), Uuid::new_v4(), "The sky is blue");
assert!(!debate.is_concluded());
debate.add_round(DebateRound {
round: 1,
blue_claim: "The sky is blue due to Rayleigh scattering".to_string(),
red_challenge: "But the sky is red at sunset".to_string(),
blue_rebuttal: Some("Rayleigh scattering still applies...".to_string()),
});
assert_eq!(debate.round_count(), 1);
debate.conclude(true, 0.85);
assert!(debate.is_concluded());
assert_eq!(debate.verdict, Some(true));
}
}