diff --git a/src/card.rs b/src/card.rs index d152509..5cc5208 100644 --- a/src/card.rs +++ b/src/card.rs @@ -11,7 +11,14 @@ pub struct Card { impl Card { pub fn fight(&self, other: &Card) -> FightResult { - todo!() + let this_fight: (bool, bool) = (self.damage >= other.health, other.damage >= self.health); + + match this_fight { + (true, false) => FightResult::Win, + (false, true) => FightResult::Loss, + (true, true) => FightResult::Tie, + (false, false) => FightResult::Draw, + } } /// Give a play by play of the battle diff --git a/src/main.rs b/src/main.rs index c667fbe..52c2e0f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,7 +10,11 @@ mod shop; mod strings; pub enum FightResult { - // TODO: Add variants for win, loss, tie, and draw + // Add variants for win, loss, tie, and draw + Win, + Loss, + Tie, + Draw, } fn main() { diff --git a/src/shop.rs b/src/shop.rs index 0177cea..f9a4d4a 100644 --- a/src/shop.rs +++ b/src/shop.rs @@ -26,7 +26,23 @@ impl Shop { /// this store wins, FightResult::Loss if this store loses, and a /// FightResult::Tie if both stores win the same number of battles. pub fn fight_store(&self, other: &Shop) -> FightResult { - todo!() + let mut tally = 0; + for card in self.cards.iter() { + for other_card in other.cards.iter() { + let result = card.print_fight(other_card); + match result { + FightResult::Win => tally += 1, + FightResult::Loss => tally -= 1, + _ => (), + } + } + } + match tally { + 0 => FightResult::Tie, + d if d > 0 => FightResult::Win, + d if d < 0 => FightResult::Loss, + _ => unreachable!(), + } } }