Skip to content

Commit

Permalink
factor out white advantage
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasf committed Nov 5, 2024
1 parent 775dbdf commit 527904d
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions research/src/bin/replay_vanilla_glicko2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use liglicko2_research::{
#[global_allocator]
static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;

const WHITE_ADVANTAGE: f64 = 12.0 / 173.7178;

#[derive(Debug, Default)]
struct PlayerState {
rating: Glicko2Rating,
Expand All @@ -19,10 +21,11 @@ struct PlayerState {

impl PlayerState {
fn live_rating(&self) -> Glicko2Rating {
let unbounded = glicko2::new_rating(self.rating, &self.pending, 0.2).unwrap_or_else(|err| {
println!("{}: {:?}", err, self);
Glicko2Rating::unrated()
});
let unbounded =
glicko2::new_rating(self.rating, &self.pending, 0.2).unwrap_or_else(|err| {
println!("{}: {:?}", err, self);
Glicko2Rating::unrated()
});

Glicko2Rating {
value: unbounded.value,
Expand All @@ -41,7 +44,8 @@ fn expectation_value(white: Glicko2Rating, black: Glicko2Rating) -> Score {
Score(
1.0 / (1.0
+ f64::exp(
-g(f64::hypot(white.deviation, black.deviation)) * (white.value - black.value),
-g(f64::hypot(white.deviation, black.deviation))
* (white.value - black.value),
)),
)
}
Expand Down Expand Up @@ -101,7 +105,7 @@ fn main() -> Result<(), Box<dyn StdError>> {
states
.get(black)
.map_or_else(Glicko2Rating::unrated, |state| state.live_rating()),
-12.0 / 173.7178,
-WHITE_ADVANTAGE,
),
),
if let Some(actual) = encounter.result.white_score() {
Expand All @@ -117,13 +121,13 @@ fn main() -> Result<(), Box<dyn StdError>> {
states
.get(white)
.map_or_else(Glicko2Rating::unrated, |state| state.rating),
12.0 / 173.7178,
WHITE_ADVANTAGE,
);
let black_rating = with_offset(
states
.get(black)
.map_or_else(Glicko2Rating::unrated, |state| state.rating),
-12.0 / 173.7178,
-WHITE_ADVANTAGE,
);

states
Expand Down

0 comments on commit 527904d

Please sign in to comment.