Skillratings allows you to calculate the player's skill instantly, or after tournaments/rating periods with a list of results using a variety of known and lesser known skill rating algorithms.
Currently supported algorithms:
They are mainly known from their usage in chess and online games.
Add the following to your Cargo.toml
file:
toml
[dependencies]
skillratings = "0.13.0"
Below is the most basic use case for each supported algorithm, in a 1-vs-1 format.
Each rating algorithm has many more associated functions, for example getting a rating using a list of outcomes or getting expected scores.
Head over to the documentation for more information.
```rust extern crate skillratings;
use skillratings::{ elo::elo, outcomes::Outcomes, rating::EloRating, config::EloConfig };
let playerone = EloRating { rating: 1000.0 }; let playertwo = EloRating { rating: 1000.0 };
// The outcome is from the perspective of player one. let outcome = Outcomes::WIN;
// The config allows you to change certain adjustable values in the algorithms. let config = EloConfig::new();
let (playeronenew, playertwonew) = elo(&playerone, &playertwo, &outcome, &config); assert!((playeronenew.rating - 1016.0).abs() < f64::EPSILON); assert!((playertwonew.rating - 984.0).abs() < f64::EPSILON); ```
```rust use skillratings::{ config::Glicko2Config, glicko::glicko, outcomes::Outcomes, rating::GlickoRating, };
let playerone = GlickoRating { rating: 1500.0, deviation: 350.0, }; let playertwo = GlickoRating { rating: 1500.0, deviation: 350.0, };
// The outcome is from the perspective of player one. let outcome = Outcomes::WIN;
// The config allows you to change certain adjustable values in the algorithms. let config = GlickoConfig::new();
let (playeronenew, playertwonew) = glicko(&playerone, &playertwo, &outcome, &config);
assert!((playeronenew.rating.round() - 1662.0).abs() < f64::EPSILON); assert!((playeronenew.deviation.round() - 290.0).abs() < f64::EPSILON);
assert!((playertwonew.rating.round() - 1338.0).abs() < f64::EPSILON); assert!((playertwonew.deviation.round() - 290.0).abs() < f64::EPSILON); ```
```rust extern crate skillratings;
use skillratings::{ glicko2::glicko2, outcomes::Outcomes, rating::Glicko2Rating, config::Glicko2Config };
let playerone = Glicko2Rating { rating: 1500.0, deviation: 350.0, volatility: 0.06 }; let playertwo = Glicko2Rating { rating: 1500.0, deviation: 350.0, volatility: 0.06 };
// The outcome is from the perspective of player one. let outcome = Outcomes::WIN;
// The config allows you to change certain adjustable values in the algorithms. let config = Glicko2Config::new();
let (playeronenew, playertwonew) = glicko2(&playerone, &playertwo, &outcome, &config);
assert!((playeronenew.rating.round() - 1662.0).abs() < f64::EPSILON); assert!((playeronenew.deviation.round() - 290.0).abs() < f64::EPSILON);
assert!((playertwonew.rating.round() - 1338.0).abs() < f64::EPSILON); assert!((playertwonew.deviation.round() - 290.0).abs() < f64::EPSILON); ```
Caution regarding usage of TrueSkill: Microsoft permits only Xbox Live games or non-commercial projects to use TrueSkill(TM). If your project is commercial, you should use another rating system included here.
```rust use skillratings::{ trueskill::trueskill, outcomes::Outcomes, rating::TrueSkillRating, config::TrueSkillConfig };
let playerone = TrueSkillRating{ rating: 25.0, uncertainty: 8.333, }; let playertwo = TrueSkillRating { rating: 30.0, uncertainty: 1.2, };
// The config allows you to change certain adjustable values in the algorithms. let config = TrueSkillConfig::new();
// The outcome is from the perspective of player one. let outcome = Outcomes::WIN;
let (p1, p2) = trueskill(&playerone, &playertwo, &outcome, &config);
assert!(((p1.rating * 100.0).round() - 3300.0).abs() < f64::EPSILON); assert!(((p1.uncertainty * 100.0).round() - 597.0).abs() < f64::EPSILON);
assert!(((p2.rating * 100.0).round() - 2983.0).abs() < f64::EPSILON); assert!(((p2.uncertainty * 100.0).round() - 120.0).abs() < f64::EPSILON); ```
(A Bayesian Approximation Method for Online Ranking)
```rust use skillratings::{ rating::WengLinRating, wenglin::wenglin, outcomes::Outcomes, config::WengLinConfig };
let playerone = WengLinRating { rating: 42.0, uncertainty: 1.3, }; let playertwo = WengLinRating { rating: 25.0, uncertainty: 8.333, };
// The config allows you to change certain adjustable values in the algorithms. let config = WengLinConfig::new();
// The outcome is from the perspective of player one. let outcome = Outcomes::WIN;
let (playerone, playertwo) = wenglin(&playerone, &player_two, &outcome, &config);
assert!(((playerone.rating * 100.0).round() - 4203.0).abs() < f64::EPSILON); assert!(((playerone.uncertainty * 100.0).round() - 130.0).abs() < f64::EPSILON); assert!(((playertwo.rating * 100.0).round() - 2391.0).abs() < f64::EPSILON); assert!(((playertwo.uncertainty * 100.0).round() - 803.0).abs() < f64::EPSILON); ```
```rust use skillratings::{dwz::dwz, outcomes::Outcomes, rating::DWZRating};
let playerone = DWZRating { rating: 1500.0, index: 42, // The actual age of the player, if unavailable set this to >25. // The lower the age, the more the rating will fluctuate. age: 42, }; let playertwo = DWZRating { rating: 1500.0, index: 12, age: 12, };
// The outcome is from the perspective of player one. let outcome = Outcomes::WIN;
let (playeronenew, playertwonew) = dwz(&playerone, &playertwo, &outcome);
assert!((playeronenew.rating.round() - 1519.0).abs() < f64::EPSILON); asserteq!(playerone_new.index, 43);
assert!((playertwonew.rating.round() - 1464.0).abs() < f64::EPSILON); asserteq!(playertwo_new.index, 13); ```
```rust use skillratings::{ingo::ingo, outcomes::Outcomes, rating::IngoRating};
let playerone = IngoRating { // Note that a lower rating is more desirable. rating: 130.0, // The actual age of the player, if unavailable set this to >25. // The lower the age, the more the rating will fluctuate. age: 40, }; let playertwo = IngoRating { rating: 160.0, age: 40, };
// The outcome is from the perspective of player one. let outcome = Outcomes::WIN;
let (p1, p2) = ingo(&playerone, &playertwo, &outcome);
assert!((p1.rating.round() - 129.0).abs() < f64::EPSILON); assert!((p2.rating.round() - 161.0).abs() < f64::EPSILON); ```
This project is licensed under the MIT License.