Skip to content

Commit

Permalink
added score method
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikwilkowski committed Apr 26, 2024
1 parent d8d573c commit b94b3d6
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -263,6 +263,25 @@ impl Coup {
self.bots.iter().filter(|bot| bot.get_name() == target).count() == 0
}

fn _get_score(&mut self, winners: Vec<String>) {
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::<Score>();
}

fn game_loop(&mut self) {
while self.playing_bots.len() > 1 {
self.moves += 1;
Expand Down

0 comments on commit b94b3d6

Please sign in to comment.