Skip to content

Commit

Permalink
try restricted version of rating regulator
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasf committed Nov 2, 2024
1 parent 7f6d08f commit 69616a9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
3 changes: 2 additions & 1 deletion research/src/bin/replay_encounters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ fn write_report<W: Write>(
(Speed::Bullet, "penguingim1"),
(Speed::Blitz, "lance5500"),
(Speed::Blitz, "somethingpretentious"),
(Speed::Blitz, "tbest"),
(Speed::Classical, "igormezentsev"),
] {
if let Some(rating) = players
Expand All @@ -428,7 +429,7 @@ fn write_report<W: Write>(
Speed::UltraBullet,
Speed::Bullet,
Speed::Blitz,
Speed::Bullet,
Speed::Rapid,
Speed::Classical,
Speed::Correspondence,
] {
Expand Down
24 changes: 20 additions & 4 deletions src/rating_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ pub struct RatingSystemBuilder {
max_convergence_iterations: u32,

max_rating_delta: RatingDifference,

regulator_factor: f64,
}

impl RatingSystemBuilder {
Expand Down Expand Up @@ -161,6 +163,8 @@ impl RatingSystemBuilder {
max_convergence_iterations: self.max_convergence_iterations,

max_rating_delta: self.max_rating_delta,

regulator_factor: self.regulator_factor,
}
}
}
Expand Down Expand Up @@ -192,6 +196,8 @@ pub struct RatingSystem {
max_convergence_iterations: u32,

max_rating_delta: RatingDifference,

regulator_factor: f64,
}

impl Default for RatingSystem {
Expand Down Expand Up @@ -227,6 +233,8 @@ impl RatingSystem {
max_convergence_iterations: 1000,

max_rating_delta: RatingDifference(700.0),

regulator_factor: 1.02, // XXX
}
}

Expand Down Expand Up @@ -444,16 +452,24 @@ impl RatingSystem {

// Step 8
Ok(self.clamp_rating(&Rating {
rating: us.rating
+ mu_prime_diff
.to_external()
.clamp(-self.max_rating_delta, self.max_rating_delta),
rating: self.regulate(us.rating, mu_prime_diff.to_external()),
deviation: phi_prime.to_external(),
volatility: sigma_prime,
at: now,
}))
}

fn regulate(&self, rating: RatingScalar, delta: RatingDifference) -> RatingScalar {
let factor =
if delta > RatingDifference(0.0) && rating < self.default_rating + self.max_deviation {
self.regulator_factor
} else {
1.0
};

rating + (factor * delta).clamp(-self.max_rating_delta, self.max_rating_delta)
}

fn clamp_rating(&self, rating: &Rating) -> Rating {
Rating {
rating: rating.rating.clamp(self.min_rating, self.max_rating),
Expand Down

0 comments on commit 69616a9

Please sign in to comment.