use super::player::EloPlayer;
pub struct Match<'a> {
player_one: &'a mut EloPlayer,
player_two: &'a mut EloPlayer,
pub result: f32
}
impl Match<'_> {
pub fn new<'a>(player_one: &'a mut EloPlayer, player_two: &'a mut EloPlayer, result: f32) -> Match<'a> {
Match { player_one, player_two, result }
}
pub fn update_ratings(&mut self) {
let p2_res = match self.result {
x if x == 1.0 => { 0.0 }
x if x == 0.5 => { 0.5 }
x if x == 0.0 => { 1.0 }
_ => { panic!("Unexpected value for game result: {}", self.result) }
};
let temp_elo_1 = self.player_one.elo.0;
let temp_elo_2 = self.player_two.elo.0;
self.player_one.update_rating(temp_elo_2, self.result);
self.player_two.update_rating(temp_elo_1, p2_res);
}
}