From b94b3d681c6e653008bcd53a04381084e7f1cd63 Mon Sep 17 00:00:00 2001 From: Dominik Wilkowski Date: Fri, 26 Apr 2024 13:52:49 +1000 Subject: [PATCH] added score method --- src/lib.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index e63540e..9515ed8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -82,7 +82,7 @@ pub enum History { } /// The score of the game for all bots -pub type Score = Vec<(String, u64)>; +pub type Score = Vec<(String, i64)>; /// The Coup game engine pub struct Coup { @@ -263,6 +263,25 @@ impl Coup { self.bots.iter().filter(|bot| bot.get_name() == target).count() == 0 } + fn _get_score(&mut self, winners: Vec) { + let winner_count = winners.len() as i64; + let loser_count = self.playing_bots.len() as i64 - winner_count; + let loser_score = -1 / (self.playing_bots.len() as i64 - 1); + let winner_score = -((loser_score * loser_count) / winner_count); + + self.score = self + .score + .iter() + .map(|(name, score)| { + if winners.contains(name) { + (name.clone(), score + winner_score) + } else { + (name.clone(), score + loser_score) + } + }) + .collect::(); + } + fn game_loop(&mut self) { while self.playing_bots.len() > 1 { self.moves += 1;