use crate::glicko2::{algorithm, constants, rating::Rating};
pub fn compete(winner: &mut Rating, loser: &mut Rating, drawn: bool) {
if drawn {
algorithm::rate(winner, &mut [(Outcome::Draw, loser)]);
algorithm::rate(loser, &mut [(Outcome::Draw, winner)]);
} else {
algorithm::rate(winner, &mut [(Outcome::Win, loser)]);
algorithm::rate(loser, &mut [(Outcome::Loss, winner)]);
};
}
pub fn odds(rating1: &mut Rating, rating2: &mut Rating) -> f64 {
rating1.scale_down();
rating2.scale_down();
let expected_score =
algorithm::expect_score(rating1, rating2, algorithm::reduce_impact(rating1, rating2));
rating1.scale_up();
rating2.scale_up();
expected_score
}
pub fn quality(rating1: &mut Rating, rating2: &mut Rating) -> f64 {
let expected_score_1 = odds(rating1, rating2);
let expected_score_2 = odds(rating2, rating1);
let advantage = expected_score_1 - expected_score_2; 1.0 - advantage.abs()
}
#[derive(Debug)]
pub enum Outcome {
Win,
Draw,
Loss,
}
impl Outcome {
pub const fn val(&self) -> f64 {
match self {
Outcome::Win => constants::WIN,
Outcome::Draw => constants::DRAW,
Outcome::Loss => constants::LOSS,
}
}
}