skillratings

Calculate a player's skill rating instantly using Elo, DWZ, Glicko and Glicko-2 algorithms known from their usage in chess and other games.

Installation

Add the following to your Cargo.toml file:

toml [dependencies] skillratings = "0.5.0"

Usage

For a detailed guide on how to use this crate, head over to the documentation.

Elo rating system

```rust extern crate skillratings;

use skillratings::{elo::elo, outcomes::Outcomes, rating::EloRating};

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;

let (playeronenew, playertwonew) = elo(playerone, playertwo, outcome, 32.0); assert!((playeronenew.rating - 1016.0).abs() < f64::EPSILON); assert!((playertwonew.rating - 984.0).abs() < f64::EPSILON); ```

Glicko rating system

Instead of the traditional way of calculating the Glicko for only one player only using a list of results, we are calculating the Glicko rating for two players at once, like in the Elo calculation, to make it easier to see instant results.

```rust use skillratings::{glicko::glicko, outcomes::Outcomes, rating::GlickoRating};

let playerone = GlickoRating { rating: 1500.0, deviation: 350.0, }; let playertwo = GlickoRating { rating: 1500.0, deviation: 350.0, };

let outcome = Outcomes::WIN;

let (playeronenew, playertwonew) = glicko(playerone, playertwo, outcome);

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); ```

Glicko-2 rating system

The same as above is true here, we calculate the results instantly for both players.

```rust extern crate skillratings;

use skillratings::{glicko2::glicko2, outcomes::Outcomes, rating::Glicko2Rating};

let playerone = Glicko2Rating { rating: 1500.0, deviation: 350.0, volatility: 0.06 }; let playertwo = Glicko2Rating { rating: 1500.0, deviation: 350.0, volatility: 0.06 };

let outcome = Outcomes::WIN;

let (playeronenew, playertwonew) = glicko2(playerone, playertwo, outcome, 0.5);

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); ```

DWZ rating system

The statements above hold true here as well.

```rust use skillratings::{dwz::dwz, outcomes::Outcomes, rating::DWZRating};

let playerone = DWZRating { rating: 1500.0, index: 42, age: 42, }; let playertwo = DWZRating { rating: 1500.0, index: 12, age: 12, };

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); ```

License

This project is licensed under the MIT License.