PickleBALLER/src/glicko/rating.rs

35 lines
968 B
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
pub struct GlickoRating {
pub rating: f64, // Display scale (e.g., 1500)
pub rd: f64, // Rating deviation (350 for new)
pub volatility: f64, // Consistency (0.06 default)
}
impl GlickoRating {
pub fn new_player() -> Self {
Self {
rating: 1500.0,
rd: 350.0,
volatility: 0.06,
}
}
pub fn to_glicko2_scale(&self) -> (f64, f64, f64) {
// Convert to internal scale: μ, φ, σ
let mu = (self.rating - 1500.0) / 173.7178;
let phi = self.rd / 173.7178;
(mu, phi, self.volatility)
}
pub fn from_glicko2_scale(mu: f64, phi: f64, sigma: f64) -> Self {
// Convert back to display scale
Self {
rating: mu * 173.7178 + 1500.0,
rd: phi * 173.7178,
volatility: sigma,
}
}
}