// use uuid::Uuid; use rand::prelude::*; use cryp::Cryp; // impl Attribute { // pub fn as_str(&self) -> &'static str { // match self { // Dmg => "dmg", // Def => "def", // } // } // } #[derive(Debug)] pub struct Battle { a: Cryp, b: Cryp, } impl Battle { pub fn new(a: &Cryp, b: &Cryp) -> Battle { return Battle { a: a.clone(), b: b.clone(), }; } pub fn cryps(&self) -> Vec<&Cryp> { vec![&self.a, &self.b] } pub fn next(&mut self) -> &mut Battle { let a_turn = self.a.turn(); let b_turn = self.b.turn(); self.a.assign_dmg(&self.b, &a_turn, &b_turn); self.b.assign_dmg(&self.a, &b_turn, &a_turn); self } pub fn finished(&self) -> bool { self.cryps().iter().any(|c| c.is_ko()) } pub fn winner(&self) -> Option<&Cryp> { if self.cryps().iter().all(|c| c.is_ko()) { return None } match self.cryps().iter().find(|c| !c.is_ko()) { Some(w) => Some(w), None => panic!("no winner found {:?}", self), } } }