Skip to content

Commit

Permalink
Add fifa rating algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
atomflunder committed Nov 6, 2022
1 parent a4854a9 commit e809cdd
Show file tree
Hide file tree
Showing 6 changed files with 497 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

This is a broad overview of the changes that have been made over the lifespan of this library.

## v0.20.0 - 2022-11-06

- Added FIFA rating algorithm (Men)

## v0.19.2 - 2022-10-27

- Change every function that takes a Vec to now take a Slice
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "skillratings"
version = "0.19.2"
version = "0.20.0"
edition = "2021"
description = "Calculate a player's skill rating using algorithms like Elo, Glicko, Glicko-2, TrueSkill and many more."
readme = "README.md"
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Currently supported algorithms:
- [Glicko-2](https://docs.rs/skillratings/latest/skillratings/glicko2/)
- [TrueSkill](https://docs.rs/skillratings/latest/skillratings/trueskill/)
- [Weng-Lin (Bayesian Approximation System)](https://docs.rs/skillratings/latest/skillratings/weng_lin/)
- [FIFA Men's World Ranking](https://docs.rs/skillratings/latest/skillratings/fifa/)
- [Sticko (Stephenson Rating System)](https://docs.rs/skillratings/latest/skillratings/sticko/)
- [Glicko-Boost](https://docs.rs/skillratings/latest/skillratings/glicko_boost/)
- [USCF (US Chess Federation Ratings)](https://docs.rs/skillratings/latest/skillratings/uscf/)
Expand All @@ -38,7 +39,7 @@ Alternatively, you can add the following to your `Cargo.toml` file manually:

```toml
[dependencies]
skillratings = "0.19"
skillratings = "0.20"
```

### Serde support
Expand All @@ -55,7 +56,7 @@ By editing `Cargo.toml` manually:

```toml
[dependencies]
skillratings = {version = "0.19", features = ["serde"]}
skillratings = {version = "0.20", features = ["serde"]}
```

## Usage and Examples
Expand Down
12 changes: 8 additions & 4 deletions src/elo.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! The Elo algorithm, the most widespread rating system and the gold-standard in chess and other games.
//! Used in the official FIDE chess ratings, FIFA World Rankings, and many online video games.
//! Used in the official FIDE chess ratings, many online games, and the basis of even more rating systems.
//!
//! The higher the Elo rating number, the stronger the player.
//! Compared to other rating algorithms, Elo ratings are relatively static, but very transparent and simple to calculate.
Expand Down Expand Up @@ -42,12 +42,11 @@
//! - [Wikipedia Article](https://en.wikipedia.org/wiki/Elo_rating_system)
//! - [Elo Calculator](https://www.omnicalculator.com/sports/elo)
//! - [FIDE Ratings](https://ratings.fide.com/)
//! - [FIFA Ratings](https://www.fifa.com/fifa-world-ranking)

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

use crate::{dwz::DWZRating, ingo::IngoRating, uscf::USCFRating, Outcomes};
use crate::{dwz::DWZRating, fifa::FifaRating, ingo::IngoRating, uscf::USCFRating, Outcomes};

/// The Elo rating of a player.
///
Expand Down Expand Up @@ -107,6 +106,12 @@ impl From<USCFRating> for EloRating {
}
}

impl From<FifaRating> for EloRating {
fn from(f: FifaRating) -> Self {
Self { rating: f.rating }
}
}

#[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
/// Constants used in the Elo calculations.
Expand Down Expand Up @@ -243,7 +248,6 @@ pub fn elo_rating_period(
}

/// Calculates the expected score of two players based on their elo rating.
/// Meant for usage in the elo function, but you can also use it to predict games yourself.
///
/// Takes in two players as [`EloRating`]s and returns the probability of victory for each player as an [`f64`] between 1.0 and 0.0.
/// 1.0 means a certain victory for the player, 0.0 means certain loss.
Expand Down
Loading

0 comments on commit e809cdd

Please sign in to comment.