### Weng-Lin Quickstart Example Source: https://docs.rs/skillratings/0.28.2/skillratings/weng_lin/index.html A basic example demonstrating how to initialize player ratings, define match outcomes, configure the Weng-Lin algorithm, and calculate updated ratings. ```APIDOC ## Rust Quickstart Example ### Description This example shows the fundamental usage of the Weng-Lin module for updating player ratings after a match. ### Method Illustrative code, not a direct API call. ### Endpoint N/A (Local computation) ### Parameters N/A (Illustrative code) ### Request Example ```rust use skillratings::{ weng_lin::{weng_lin, WengLinConfig, WengLinRating}, Outcomes, }; // Initialise a new player rating with default values. let player_one = WengLinRating::new(); // Initialise another player rating with custom values. let (some_rating, some_uncertainty) = (41.2, 2.12); let player_two = WengLinRating { rating: some_rating, uncertainty: some_uncertainty, }; // Define the outcome from player one's perspective. let outcome = Outcomes::WIN; // Configure Weng-Lin parameters, customizing beta. let config = WengLinConfig { beta: 25.0 / 12.0, ..Default::default() }; // Calculate the new ratings for both players. let (new_player_one, new_player_two) = weng_lin(&player_one, &player_two, &outcome, &config); ``` ### Response #### Success Response (200) Returns updated `WengLinRating` for both players. #### Response Example ```rust // The result of the weng_lin function is a tuple of the updated ratings: // let (new_player_one, new_player_two): (WengLinRating, WengLinRating) ``` ``` -------------------------------- ### TrueSkill Module Quickstart Source: https://docs.rs/skillratings/0.28.2/skillratings/trueskill/index.html A basic example demonstrating how to initialize player ratings, define match outcomes, configure TrueSkill parameters, and calculate new ratings. ```APIDOC ## Module trueskill ### Description The TrueSkill rating algorithm, developed by Microsoft for Halo 3. Used in various Xbox Live games, it's designed for online games with multiple teams and players. TrueSkill uses a normal distribution (skill rating μ and uncertainty σ) to represent player skill, similar to Glicko and Glicko-2, and is efficient at assessing skill levels quickly. **Caution:** TrueSkill is patented. For commercial projects, consider alternative algorithms like the Weng-Lin algorithm. ### Quickstart Example This example shows the basic usage of the TrueSkill module. ```rust use skillratings::{ trueskill::{trueskill, TrueSkillConfig, TrueSkillRating}, Outcomes, }; // Initialise a new player rating with default values (rating: 25, uncertainty: 8.33). let player_one = TrueSkillRating::new(); // Initialize with custom values (e.g., from a database). let (some_rating, some_uncertainty) = (34.2, 2.3); let player_two = TrueSkillRating { rating: some_rating, uncertainty: some_uncertainty, }; // Define the outcome of the match from player one's perspective. let outcome = Outcomes::WIN; // Configure TrueSkill parameters. Here, draw probability is set to 0.05 (5%). // Adjust this value based on the game's draw frequency. let config = TrueSkillConfig { draw_probability: 0.05, ..Default::default() }; // Calculate the new ratings for both players. let (new_player_one, new_player_two) = trueskill(&player_one, &player_two, &outcome, &config); ``` ### Key Components * **TrueSkillRating**: Represents a player's skill level with a rating (μ) and uncertainty (σ). * **TrueSkillConfig**: Allows customization of TrueSkill calculation parameters, such as `draw_probability`. * **trueskill function**: Computes the updated ratings based on match results and configuration. * **Outcomes enum**: Represents the possible results of a match (e.g., WIN, LOSS, DRAW). ``` -------------------------------- ### DWZ Module - Quickstart Example Source: https://docs.rs/skillratings/0.28.2/skillratings/dwz/index.html A basic example demonstrating how to initialize DWZ ratings for two players and calculate the outcome of a match using the `dwz` function. ```APIDOC ## DWZ Module - Quickstart Example This is the most basic example on how to use the DWZ Module. Please take a look at the functions below to see more advanced use cases. ```rust use skillratings::{ dwz::{dwz, DWZRating}, Outcomes, }; // Initialise a new player rating. // We need to set the actual age for the player, // if you are unsure what to set here, choose something that is greater than 25. let player_one = DWZRating::new(19); // Or you can initialise it with your own values of course. // Imagine these numbers being pulled from a database. // The default rating is 1000, and the index denotes the amount of tournaments played. let (some_rating, some_index, some_age) = (1325.0, 51, 27); let player_two = DWZRating { rating: some_rating, index: some_index, age: some_age, }; // The outcome of the match is from the perspective of player one. let outcome = Outcomes::WIN; // The dwz function will calculate the new ratings for both players and return them. let (new_player_one, new_player_two) = dwz(&player_one, &player_two, &outcome); ``` ``` -------------------------------- ### Sticko Algorithm Quickstart Source: https://docs.rs/skillratings/0.28.2/skillratings/sticko/index.html A basic example demonstrating how to initialize player ratings, define match outcomes, configure Sticko parameters, and calculate new ratings. ```APIDOC ## Sticko Algorithm Quickstart This is the most basic example on how to use the Sticko Module. Please take a look at the functions below to see more advanced use cases. ```rust use skillratings::{ sticko::{sticko, StickoConfig, StickoRating}, Outcomes, }; // Initialise a new player rating with a rating of 1500 and a deviation of 350. let player_one = StickoRating::new(); // Or you can initialise it with your own values of course. // Imagine these numbers being pulled from a database. let (some_rating, some_deviation) = (1325.0, 230.0); let player_two = StickoRating { rating: some_rating, deviation: some_deviation, }; // The outcome of the match is from the perspective of player one. let outcome = Outcomes::WIN; // The config allows you to specify certain values in the Sticko calculation. // For more information on how to customise the config, please check out the StickoConfig struct. let config = StickoConfig { // The gamma value describes the advantage of player_one. // 30.0 is roughly accurate for playing White in Chess. // If player_two was to play White, change this to -30.0. // By default it is set to 0.0. gamma: 30.0, // We leave the other settings at their default values. ..Default::default() }; // The sticko function will calculate the new ratings for both players and return them. let (new_player_one, new_player_two) = sticko(&player_one, &player_two, &outcome, &config); ``` ``` -------------------------------- ### Install skillratings via Cargo Source: https://docs.rs/skillratings Commands to add the crate to a Rust project. ```bash cargo add skillratings ``` ```toml [dependencies] skillratings = "0.28" ``` -------------------------------- ### WengLin Rating System Implementation Source: https://docs.rs/skillratings/0.28.2/skillratings/trait.RatingPeriodSystem.html Example implementation of RatingPeriodSystem for the WengLin rating system. It uses WengLinRating for ratings and WengLinConfig for configuration. ```rust type RATING = WengLinRating; type CONFIG = WengLinConfig; ``` -------------------------------- ### TrueSkill Rating System Implementation Source: https://docs.rs/skillratings/0.28.2/skillratings/trait.RatingPeriodSystem.html Example implementation of RatingPeriodSystem for the TrueSkill rating system. It uses TrueSkillRating for ratings and TrueSkillConfig for configuration. ```rust type RATING = TrueSkillRating; type CONFIG = TrueSkillConfig; ``` -------------------------------- ### Initialize and Use TrueSkill Rating Source: https://docs.rs/skillratings/0.28.2/skillratings/trueskill/index.html Demonstrates basic initialization of player ratings, custom configuration, and calculating new ratings after a match outcome. Use this for a quick start with the TrueSkill algorithm. ```rust use skillratings::{ trueskill::{trueskill, TrueSkillConfig, TrueSkillRating}, Outcomes, }; // Initialise a new player rating with a rating of 25, and an uncertainty of 25/3 ≈ 8.33. let player_one = TrueSkillRating::new(); // Or you can initialise it with your own values of course. // Imagine these numbers being pulled from a database. let (some_rating, some_uncertainty) = (34.2, 2.3); let player_two = TrueSkillRating { rating: some_rating, uncertainty: some_uncertainty, }; // The outcome of the match is from the perspective of player one. let outcome = Outcomes::WIN; // The config allows you to specify certain values in the TrueSkill calculation. // We set the draw probability to 0.05 (5%) instead of the default 0.1 (10%). // This means that in our game, draws will be very rare to occur. // Change this value to reflect the outcomes of your game. // For example in chess, it might be a good idea to increase this value. // For more information on how to customise the config, // please check out the TrueSkillConfig struct. let config = TrueSkillConfig { draw_probability: 0.05, ..Default::default() }; // The trueskill function will calculate the new ratings for both players and return them. let (new_player_one, new_player_two) = trueskill(&player_one, &player_two, &outcome, &config); ``` -------------------------------- ### Sticko Rating System Implementation Source: https://docs.rs/skillratings/0.28.2/skillratings/trait.RatingPeriodSystem.html Example implementation of RatingPeriodSystem for the Sticko rating system. It uses StickoRating for ratings and StickoConfig for configuration. ```rust type RATING = StickoRating; type CONFIG = StickoConfig; ``` -------------------------------- ### DWZ Rating System Implementation Source: https://docs.rs/skillratings/0.28.2/skillratings/trait.RatingPeriodSystem.html Example implementation of RatingPeriodSystem for the DWZ rating system. It uses DWZRating for ratings and requires no specific configuration. ```rust type RATING = DWZRating; type CONFIG = (); ``` -------------------------------- ### Ingo Rating System Implementation Source: https://docs.rs/skillratings/0.28.2/skillratings/trait.RatingPeriodSystem.html Example implementation of RatingPeriodSystem for the Ingo rating system. It uses IngoRating for ratings and requires no specific configuration. ```rust type RATING = IngoRating; type CONFIG = (); ``` -------------------------------- ### Elo Rating System Implementation Source: https://docs.rs/skillratings/0.28.2/skillratings/trait.RatingPeriodSystem.html Example implementation of RatingPeriodSystem for the Elo rating system. It uses EloRating for ratings and EloConfig for configuration. ```rust type RATING = EloRating; type CONFIG = EloConfig; ``` -------------------------------- ### skillratings::dwz::get_first_dwz Source: https://docs.rs/skillratings/0.28.2/skillratings/dwz/fn.get_first_dwz.html Gets a proper first DWZRating. In the case that you do not have enough opponents to rate a player against, consider using DWZRating::from() if you have an EloRating or DWZRating::new() if not. Takes in the player’s age and their results as a Slice of tuples containing the opponent and the outcome. If the actual player’s age is unavailable or unknown, choose something >25. ```APIDOC ## GET skillratings::dwz::get_first_dwz ### Description Gets a proper first `DWZRating`. In the case that you do not have enough opponents to rate a player against, consider using `DWZRating::from()` if you have an `EloRating` or `DWZRating::new()` if not. Takes in the player’s age and their results as a Slice of tuples containing the opponent and the outcome. If the actual player’s age is unavailable or unknown, choose something `>25`. ### Method GET ### Endpoint /skillratings/dwz/get_first_dwz ### Parameters #### Query Parameters - **player_age** (usize) - Required - The player's age. - **results** (array of tuples) - Required - A slice of tuples containing the opponent's `DWZRating` and the `Outcomes` of the game. ### Response #### Success Response (200) - **DWZRating** - The calculated `DWZRating` for the player. #### Error Response - **GetFirstDWZError::NotEnoughGames** - Returned if the player has played less than 5 games. - **GetFirstDWZError::InvalidWinRate** - Returned if the player has a winrate of either 0% or 100%. ### Request Example ```json { "player_age": 26, "results": [ {"opponent": {"rating": 1300.0, "index": 23, "age": 17}, "outcome": "WIN"}, {"opponent": {"rating": 1540.0, "index": 2, "age": 29}, "outcome": "DRAW"}, {"opponent": {"rating": 1200.0, "index": 10, "age": 7}, "outcome": "LOSS"}, {"opponent": {"rating": 1290.0, "index": 76, "age": 55}, "outcome": "WIN"}, {"opponent": {"rating": 1400.0, "index": 103, "age": 11}, "outcome": "WIN"} ] } ``` ### Response Example ```json { "rating": 1491.0, "index": 1, "age": 26 } ``` ``` -------------------------------- ### Glicko2 Rating System Implementation Source: https://docs.rs/skillratings/0.28.2/skillratings/trait.RatingPeriodSystem.html Example implementation of RatingPeriodSystem for the Glicko2 rating system. It uses Glicko2Rating for ratings and Glicko2Config for configuration. ```rust type RATING = Glicko2Rating; type CONFIG = Glicko2Config; ``` -------------------------------- ### Calculate Multi-Team TrueSkill Ratings Source: https://docs.rs/skillratings/0.28.2/skillratings/trueskill/fn.trueskill_multi_team.html Example demonstrating how to define teams, assign ranks, apply player weights, and calculate new ratings using trueskill_multi_team. ```rust use skillratings::{ trueskill::{trueskill_multi_team, TrueSkillConfig, TrueSkillRating}, MultiTeamOutcome, }; let team_one = vec![ TrueSkillRating::new(), TrueSkillRating { rating: 30.0, uncertainty: 1.2, }, TrueSkillRating { rating: 21.0, uncertainty: 6.5, }, ]; let team_two = vec![ TrueSkillRating::default(), TrueSkillRating { rating: 41.0, uncertainty: 1.4, }, TrueSkillRating { rating: 19.2, uncertainty: 4.3, }, ]; let team_three = vec![ TrueSkillRating::default(), TrueSkillRating { rating: 29.4, uncertainty: 1.6, }, TrueSkillRating { rating: 17.2, uncertainty: 2.1, }, ]; let teams_and_ranks = vec![ (&team_one[..], MultiTeamOutcome::new(2)), // Team 1 takes the second place. (&team_two[..], MultiTeamOutcome::new(1)), // Team 2 takes the first place. (&team_three[..], MultiTeamOutcome::new(3)), // Team 3 takes the third place. ]; let weights: &[&[f64]] = &[ &[1.0, 1.0, 0.5], // Player 3 left halfway through the match &[1.0, 0.9, 1.0], // Player 2 left close to the end &[1.0, 1.0, 1.0], ]; let new_teams = trueskill_multi_team(&teams_and_ranks, &TrueSkillConfig::new(), Some(&weights)).unwrap(); assert_eq!(new_teams.len(), 3); let new_one = &new_teams[0]; let new_two = &new_teams[1]; let new_three = &new_teams[2]; assert!((new_one[0].rating - 28.180_576_928_436_55).abs() < f64::EPSILON); assert!((new_one[1].rating - 30.066_263_874_493_455).abs() < f64::EPSILON); assert!((new_one[2].rating - 21.967_593_771_099_708).abs() < f64::EPSILON); assert!((new_two[0].rating - 27.657_276_377_119_9).abs() < f64::EPSILON); assert!((new_two[1].rating - 41.067_731_453_349_65).abs() < f64::EPSILON); assert!((new_two[2].rating - 19.907_710_735_630_584).abs() < f64::EPSILON); assert!((new_three[0].rating - 19.162_146_694_443_58).abs() < f64::EPSILON); assert!((new_three[1].rating - 29.184_231_167_296_68).abs() < f64::EPSILON); assert!((new_three[2].rating - 16.828_726_305_722_817).abs() < f64::EPSILON); ``` -------------------------------- ### Calculate TrueSkill ratings for 3v3 Source: https://docs.rs/skillratings Example of calculating new ratings for two teams in a team-based match using the TrueSkill algorithm. ```rust use skillratings::{ trueskill::{trueskill_two_teams, TrueSkillConfig, TrueSkillRating}, Outcomes, }; // We initialise Team One as a Vec of multiple TrueSkillRatings. // The default values for the rating are: 25, 25/3 ≈ 8.33. let team_one = vec![ TrueSkillRating { rating: 33.3, uncertainty: 3.3, }, TrueSkillRating { rating: 25.1, uncertainty: 1.2, }, TrueSkillRating { rating: 43.2, uncertainty: 2.0, }, ]; // Team Two will be made up of 3 new players, for simplicity. // Note that teams do not necessarily have to be the same size. let team_two = vec![ TrueSkillRating::new(), TrueSkillRating::new(), TrueSkillRating::new(), ]; // The outcome of the match is from the perspective of team one. let outcome = Outcomes::LOSS; // The config allows you to specify certain values in the TrueSkill calculation. let config = TrueSkillConfig::new(); // The trueskill_two_teams function will calculate the new ratings for both teams and return them. let (new_team_one, new_team_two) = trueskill_two_teams(&team_one, &team_two, &outcome, &config); // The rating of the first player on team one decreased by around ~1.2 points. assert_eq!(new_team_one[0].rating.round(), 32.0); ``` -------------------------------- ### Glicko Rating System Implementation Source: https://docs.rs/skillratings/0.28.2/skillratings/trait.RatingPeriodSystem.html Example implementation of RatingPeriodSystem for the Glicko rating system. It uses GlickoRating for ratings and GlickoConfig for configuration. ```rust type RATING = GlickoRating; type CONFIG = GlickoConfig; ``` -------------------------------- ### USCF Rating System Implementation Source: https://docs.rs/skillratings/0.28.2/skillratings/trait.RatingPeriodSystem.html Example implementation of RatingPeriodSystem for the USCF rating system. It uses USCFRating for ratings and USCFConfig for configuration. ```rust type RATING = USCFRating; type CONFIG = USCFConfig; ``` -------------------------------- ### Calculate Glicko-2 ratings for 1v1 Source: https://docs.rs/skillratings Example of calculating new ratings for two players in a 1v1 match using the Glicko-2 algorithm. ```rust use skillratings::{ glicko2::{glicko2, Glicko2Config, Glicko2Rating}, Outcomes, }; // Initialise a new player rating. // The default values are: 1500, 350, and 0.06. let player_one = Glicko2Rating::new(); // Or you can initialise it with your own values of course. // Imagine these numbers being pulled from a database. let (some_rating, some_deviation, some_volatility) = (1325.0, 230.0, 0.05932); let player_two = Glicko2Rating { rating: some_rating, deviation: some_deviation, volatility: some_volatility, }; // The outcome of the match is from the perspective of player one. let outcome = Outcomes::WIN; // The config allows you to specify certain values in the Glicko-2 calculation. let config = Glicko2Config::new(); // The glicko2 function will calculate the new ratings for both players and return them. let (new_player_one, new_player_two) = glicko2(&player_one, &player_two, &outcome, &config); // The first players rating increased by ~112 points. assert_eq!(new_player_one.rating.round(), 1612.0); ``` -------------------------------- ### Fifa Rating System Implementation Source: https://docs.rs/skillratings/0.28.2/skillratings/trait.RatingPeriodSystem.html Example implementation of RatingPeriodSystem for the Fifa rating system. It uses FifaRating for ratings and FifaConfig for configuration. ```rust type RATING = FifaRating; type CONFIG = FifaConfig; ``` -------------------------------- ### EGF Rating System Implementation Source: https://docs.rs/skillratings/0.28.2/skillratings/trait.RatingPeriodSystem.html Example implementation of RatingPeriodSystem for the EGF rating system. It uses EGFRating for ratings and EGFConfig for configuration. ```rust type RATING = EGFRating; type CONFIG = EGFConfig; ``` -------------------------------- ### GlickoBoost Rating System Implementation Source: https://docs.rs/skillratings/0.28.2/skillratings/trait.RatingPeriodSystem.html Example implementation of RatingPeriodSystem for the GlickoBoost rating system. It uses GlickoBoostRating for ratings and GlickoBoostConfig for configuration. ```rust type RATING = GlickoBoostRating; type CONFIG = GlickoBoostConfig; ``` -------------------------------- ### StickoConfig::new() Source: https://docs.rs/skillratings/0.28.2/skillratings/sticko/struct.StickoConfig.html Initializes a new StickoConfig with default values. ```APIDOC ## impl StickoConfig ### pub const fn new() -> Self Initialise a new `StickoConfig` with a h value of `10.0`, a beta value of `0.0`, a lambda value of `2.0` and a gamma value of `0.0`. ``` -------------------------------- ### Get Rank Function Source: https://docs.rs/skillratings/0.28.2/skillratings/trueskill/fn.get_rank.html Calculates the conservatively estimated rank of a player using their rating and deviation. The recommended scale used for Xbox Live is 0 (lowest, starting value) to 50 (highest). ```APIDOC ## GET /get_rank ### Description Gets the conservatively estimated rank of a player using their rating and deviation. This is a conservative estimate of player skill, the system is 99% sure the player’s skill is higher than displayed. Takes in a player as a `TrueSkillRating` and returns the rank as an `f64`. The recommended scale used for Xbox Live is 0 (lowest, starting value) to 50 (highest). ### Method GET ### Endpoint /get_rank ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **player** (TrueSkillRating) - Required - The player's TrueSkillRating object. ### Request Example ```json { "player": { "rating": 43.1, "uncertainty": 1.92 } } ``` ### Response #### Success Response (200) - **rank** (f64) - The conservatively estimated rank of the player. #### Response Example ```json { "rank": 37.0 } ``` ``` -------------------------------- ### Get Player Rank with TrueSkillRating Source: https://docs.rs/skillratings/0.28.2/skillratings/trueskill/fn.get_rank.html Use this function to get a conservative estimate of a player's skill rank. The system is 99% sure the player’s skill is higher than the displayed rank. Takes a `TrueSkillRating` and returns the rank as an `f64`. The recommended scale is 0 (lowest) to 50 (highest). ```rust use skillratings::trueskill::{get_rank, TrueSkillRating}; let new_player = TrueSkillRating::new(); let older_player = TrueSkillRating { rating: 43.1, uncertainty: 1.92, }; let new_rank = get_rank(&new_player); let older_rank = get_rank(&older_player); assert!((new_rank.round() - 0.0).abs() < f64::EPSILON); assert!((older_rank.round() - 37.0).abs() < f64::EPSILON); ``` -------------------------------- ### Initialize and Use Glicko2 Rating System Source: https://docs.rs/skillratings/0.28.2/skillratings/glicko2/index.html Demonstrates basic initialization of Glicko2 ratings for two players and calculating the outcome of a match using a custom configuration. The `tau` value in `Glicko2Config` can be adjusted to influence volatility changes. ```rust use skillratings::{ glicko2::{glicko2, Glicko2Config, Glicko2Rating}, Outcomes, }; // Initialise a new player rating with a rating of 1500, a deviation of 350 and a volatility of 0.06. let player_one = Glicko2Rating::new(); // Or you can initialise it with your own values of course. // Imagine these numbers being pulled from a database. let (some_rating, some_deviation, some_volatility) = (1325.0, 230.0, 0.05932); let player_two = Glicko2Rating { rating: some_rating, deviation: some_deviation, volatility: some_volatility, }; // The outcome of the match is from the perspective of player one. let outcome = Outcomes::WIN; // The config allows you to specify certain values in the Glicko-2 calculation. // Here we set the Tau value to 0.9, instead of the default 0.5. // This will increase the change in volatility over time. // According to Mark Glickman, values between 0.3 and 1.2 are reasonable. // For more information on how to customise the config, // please check out the Glicko2Config struct. let config = Glicko2Config { tau: 0.9, ..Default::default() }; // The glicko2 function will calculate the new ratings for both players and return them. let (new_player_one, new_player_two) = glicko2(&player_one, &player_two, &outcome, &config); ``` -------------------------------- ### Initialize and Calculate Glicko Ratings Source: https://docs.rs/skillratings/0.28.2/skillratings/glicko/index.html Demonstrates basic usage of the Glicko module, including initializing player ratings, defining match outcomes, configuring Glicko parameters, and calculating new ratings. Use this for a quick integration of the Glicko algorithm. ```rust use skillratings::{ glicko::{glicko, GlickoConfig, GlickoRating}, Outcomes, }; // Initialise a new player rating with a rating of 1500 and a deviation of 350. let player_one = GlickoRating::new(); // Or you can initialise it with your own values of course. // Imagine these numbers being pulled from a database. let (some_rating, some_deviation) = (1325.0, 230.0); let player_two = GlickoRating { rating: some_rating, deviation: some_deviation, }; // The outcome of the match is from the perspective of player one. let outcome = Outcomes::WIN; // The config allows you to specify certain values in the Glicko calculation. // Here we set the c value to 23.75, instead of the default 63.2. // This will decrease the amount by which rating deviation increases per rating period. let config = GlickoConfig { c: 23.75 }; // The glicko function will calculate the new ratings for both players and return them. let (new_player_one, new_player_two) = glicko(&player_one, &player_two, &outcome, &config); ``` -------------------------------- ### Get Type ID Source: https://docs.rs/skillratings/0.28.2/skillratings/dwz/struct.DWZ.html Retrieves the `TypeId` of the current instance. This is a standard trait implementation. ```rust fn type_id(&self) -> TypeId ``` -------------------------------- ### Get Glicko2Rating Value Source: https://docs.rs/skillratings/0.28.2/skillratings/glicko2/struct.Glicko2Rating.html Returns the numerical rating value of the Glicko2Rating. This is the primary skill score. ```rust fn rating(&self) -> f64 ``` -------------------------------- ### Get Glicko2Rating Uncertainty Source: https://docs.rs/skillratings/0.28.2/skillratings/glicko2/struct.Glicko2Rating.html Returns the uncertainty associated with the Glicko2Rating. If the algorithm does not provide an uncertainty value, this returns None. ```rust fn uncertainty(&self) -> Option ``` -------------------------------- ### Initialize and Use Weng-Lin Rating Source: https://docs.rs/skillratings/0.28.2/skillratings/weng_lin/index.html Demonstrates initializing player ratings, defining match outcomes, configuring Weng-Lin parameters like beta, and calculating new ratings after a game. The beta value influences the impact of rating differences on win probability. ```rust use skillratings::{ weng_lin::{weng_lin, WengLinConfig, WengLinRating}, Outcomes, }; // Initialise a new player rating with a rating of 25, and an uncertainty of 25/3 ≈ 8.33. let player_one = WengLinRating::new(); // Or you can initialise it with your own values of course. // Imagine these numbers being pulled from a database. let (some_rating, some_uncertainty) = (41.2, 2.12); let player_two = WengLinRating { rating: some_rating, uncertainty: some_uncertainty, }; // The outcome of the match is from the perspective of player one. let outcome = Outcomes::WIN; // The config allows you to specify certain values in the Weng-Lin calculation. // Here we change the beta value from the default of 25 / 6 ≈ 4.167. // The beta value measures the difference you need in rating points // to achieve a ~67% win-rate over another player. // Lower this value if your game is heavily reliant on pure skill, // or increase it if randomness plays a big factor in the outcome of the game. // For more information on how to customise the config, // please check out the WengLinConfig struct. let config = WengLinConfig { beta: 25.0 / 12.0, ..Default::default() }; // The weng_lin function will calculate the new ratings for both players and return them. let (new_player_one, new_player_two) = weng_lin(&player_one, &player_two, &outcome, &config); ``` -------------------------------- ### Get MultiTeamOutcome Rank Source: https://docs.rs/skillratings/0.28.2/skillratings/struct.MultiTeamOutcome.html Retrieves the rank associated with this `MultiTeamOutcome` instance. The rank indicates the team's placement in the match. ```rust pub const fn rank(self) -> usize ``` -------------------------------- ### Initialize and Calculate Ingo Ratings Source: https://docs.rs/skillratings/0.28.2/skillratings/ingo/index.html Demonstrates how to initialize IngoRating structures and calculate new ratings after a match outcome. ```rust use skillratings::{ ingo::{ingo, IngoRating}, Outcomes, }; // Initialise a new player rating. // We need to set the actual age for the player, // if you are unsure what to set here, choose something that is greater than 25. let player_one = IngoRating::new(19); // Or you can initialise it with your own values of course. // Imagine these numbers being pulled from a database. // The default rating is 230. Unlike with other algorithms, with Ingo a lower rating is more desirable. let (some_rating, some_age) = (150.4, 23); let player_two = IngoRating { rating: some_rating, age: some_age, }; // The outcome of the match is from the perspective of player one. let outcome = Outcomes::WIN; // The ingo function will calculate the new ratings for both players and return them. let (new_player_one, new_player_two) = ingo(&player_one, &player_two, &outcome); ``` -------------------------------- ### GlickoBoostConfig::new() Source: https://docs.rs/skillratings/0.28.2/skillratings/glicko_boost/struct.GlickoBoostConfig.html Initializes a new GlickoBoostConfig with default values. ```APIDOC ## Constructor: GlickoBoostConfig::new() ### Description Initialise a new `GlickoBoostConfig` with a eta value of 30.0, a k value of 1.96, b values of 0.20139 and 17.5, and alpha values of 5.83733, -1.75374e-04, -7.080124e-05, 0.001733792, 0.00026706. ### Method `pub const fn new() -> Self` ### Returns A new `GlickoBoostConfig` instance with default values. ### Example Usage (Conceptual) ```rust let config = GlickoBoostConfig::new(); ``` ``` -------------------------------- ### IngoRating::new Source: https://docs.rs/skillratings/0.28.2/skillratings/ingo/struct.IngoRating.html Initializes a new IngoRating with a default rating of 230.0 and a specified age. ```APIDOC ### impl IngoRating #### pub const fn new(age: usize) -> Self Initialise a new `IngoRating` with a rating of 230.0 and the given age. The age is the actual age of the player, if unsure or unavailable set this to `>25`. ``` -------------------------------- ### Enable Serde support Source: https://docs.rs/skillratings Configuration to enable Serde feature for serialization and deserialization. ```bash cargo add skillratings --features serde ``` ```toml [dependencies] skillratings = {version = "0.28", features = ["serde"]} ``` -------------------------------- ### Initialize TrueSkillConfig Source: https://docs.rs/skillratings/0.28.2/skillratings/trueskill/struct.TrueSkillConfig.html Creates a new TrueSkillConfig with default values for draw probability (0.1), beta (approx. 4.167), and dynamics factor (approx. 0.0833). ```rust pub fn new() -> Self ``` -------------------------------- ### Initialize Rating System Source: https://docs.rs/skillratings/0.28.2/skillratings/trait.RatingPeriodSystem.html Implement this method to initialize a rating system with its specific configuration. If no configuration is needed, an empty tuple `()` can be used. ```rust fn new(config: Self::CONFIG) -> Self; ``` -------------------------------- ### Sticko Rating System Methods Source: https://docs.rs/skillratings/0.28.2/skillratings/sticko/struct.Sticko.html Methods for initializing the Sticko system, calculating ratings, and determining expected scores. ```APIDOC ## Sticko Rating System ### Description The Sticko struct allows for the calculation of ratings and expected scores using the StickoRating system. ### Methods - **new(config: StickoConfig)**: Initializes the rating system with the provided configuration. - **rate(player: &StickoRating, results: &[(StickoRating, Outcomes)])**: Calculates ratings for a player based on a list of opponents and outcomes. - **expected_score(player: &StickoRating, opponents: &[StickoRating])**: Calculates the expected win probability (0.0 to 1.0) for a player against a list of opponents. - **rate(player_one: &StickoRating, player_two: &StickoRating, outcome: &Outcomes)**: Calculates new ratings for two players based on a head-to-head outcome. - **expected_score(player_one: &StickoRating, player_two: &StickoRating)**: Calculates the expected win probability for two players in a head-to-head match. ``` -------------------------------- ### Calculate Weng-Lin ratings for multiple teams Source: https://docs.rs/skillratings/0.28.2/skillratings/weng_lin/fn.weng_lin_multi_team.html Demonstrates how to initialize team ratings and calculate new ratings based on their relative ranks. ```rust use skillratings::{ weng_lin::{weng_lin_multi_team, WengLinConfig, WengLinRating}, MultiTeamOutcome, }; let team_one = vec![ WengLinRating::new(), WengLinRating { rating: 30.0, uncertainty: 1.2, }, WengLinRating { rating: 21.0, uncertainty: 6.5, }, ]; let team_two = vec![ WengLinRating::default(), WengLinRating { rating: 41.0, uncertainty: 1.4, }, WengLinRating { rating: 19.2, uncertainty: 4.3, }, ]; let team_three = vec![ WengLinRating::default(), WengLinRating { rating: 29.4, uncertainty: 1.6, }, WengLinRating { rating: 17.2, uncertainty: 2.1, }, ]; let teams_and_ranks = vec![ (&team_one[..], MultiTeamOutcome::new(2)), // Team 1 takes the second place. (&team_two[..], MultiTeamOutcome::new(1)), // Team 2 takes the first place. (&team_three[..], MultiTeamOutcome::new(3)), // Team 3 takes the third place. ]; let new_teams = weng_lin_multi_team(&teams_and_ranks, &WengLinConfig::new()); assert_eq!(new_teams.len(), 3); let new_one = &new_teams[0]; let new_two = &new_teams[1]; let new_three = &new_teams[2]; assert!(((new_one[0].rating * 100.0).round() - 2538.0).abs() < f64::EPSILON); assert!(((new_one[1].rating * 100.0).round() - 3001.0).abs() < f64::EPSILON); assert!(((new_one[2].rating * 100.0).round() - 2123.0).abs() < f64::EPSILON); assert!(((new_two[0].rating * 100.0).round() - 2796.0).abs() < f64::EPSILON); assert!(((new_two[1].rating * 100.0).round() - 4108.0).abs() < f64::EPSILON); assert!(((new_two[2].rating * 100.0).round() - 1999.0).abs() < f64::EPSILON); assert!(((new_three[0].rating * 100.0).round() - 2166.0).abs() < f64::EPSILON); assert!(((new_three[1].rating * 100.0).round() - 2928.0).abs() < f64::EPSILON); assert!(((new_three[2].rating * 100.0).round() - 1699.0).abs() < f64::EPSILON); ``` -------------------------------- ### CloneToUninit Implementation (Nightly) Source: https://docs.rs/skillratings/0.28.2/skillratings/enum.Outcomes.html An experimental nightly-only API for performing copy-assignment to uninitialized memory. ```rust unsafe fn clone_to_uninit(&self, dest: *mut u8) ``` -------------------------------- ### Get Minimum of Two MultiTeamOutcome Source: https://docs.rs/skillratings/0.28.2/skillratings/struct.MultiTeamOutcome.html Compares two `MultiTeamOutcome` instances and returns the minimum of the two. This is useful when determining the worst outcome among several. ```rust fn min(self, other: Self) -> Self ``` -------------------------------- ### Switching Rating Systems with Glicko-2 Source: https://docs.rs/skillratings Demonstrates how to use the RatingSystem trait with Glicko-2 for 1v1 matches. Ensure the correct Config is provided when switching systems. For more accurate calculations, consider using rating system modules directly. ```rust use skillratings::{ glicko2::{Glicko2, Glicko2Config}, Outcomes, Rating, RatingSystem, }; // Initialise a new player rating with a rating value and uncertainty value. // Not every rating system has an uncertainty value, so it may be discarded. // Some rating systems might consider other values too (volatility, age, matches played etc.). // If that is the case, we will use the default values for those. let player_one = Rating::new(Some(1200.0), Some(120.0)); // Some rating systems might use widely different scales for measuring a player's skill. // So if you always want the default values for every rating system, use None instead. let player_two = Rating::new(None, None); // The config needs to be specific to the rating system. // When you swap rating systems, make sure to update the config. let config = Glicko2Config::new(); // For 1v1 matches we are using the `RatingSystem` trait with the provided config. // If no config is available for the rating system, pass in empty brackets. // You may also need to use a type annotation here for the compiler. let rating_system: Glicko2 = RatingSystem::new(config); // The outcome of the match is from the perspective of player one. let outcome = Outcomes::WIN; // Calculate the expected score of the match. let expected_score = rating_system.expected_score(&player_one, &player_two); // Calculate the new ratings. let (new_one, new_two) = rating_system.rate(&player_one, &player_two, &outcome); // After that, access new ratings and uncertainties with the functions below. assert_eq!(new_one.rating().round(), 1241.0); // Note that because not every rating system has an uncertainty value, // the uncertainty function returns an Option. assert_eq!(new_one.uncertainty().unwrap().round(), 118.0); ``` -------------------------------- ### Get Maximum of Two MultiTeamOutcome Source: https://docs.rs/skillratings/0.28.2/skillratings/struct.MultiTeamOutcome.html Compares two `MultiTeamOutcome` instances and returns the maximum of the two. This is useful when determining the best outcome among several. ```rust fn max(self, other: Self) -> Self ``` -------------------------------- ### Function: get_first_dwz Source: https://docs.rs/skillratings/0.28.2/skillratings/dwz/index.html Determines and returns a proper initial DWZ rating for a new player. ```APIDOC ## Function: get_first_dwz Gets a proper first `DWZRating`. ``` -------------------------------- ### Rating Trait Source: https://docs.rs/skillratings/0.28.2/skillratings/trait.Rating.html Defines the core interface for skill rating systems, including methods to get the rating value, its uncertainty, and to create a new rating. ```APIDOC ## Trait Rating ### Description Measure of player’s skill. 📌 _**Important note:**_ Please keep in mind that some rating systems use widely different scales for measuring ratings. Please check out the documentation for each rating system for more information, or use `None` to always use default values. Some rating systems might consider other values too (volatility, age, matches played etc.). If that is the case, we will use the default values for those. ### Required Methods #### fn rating(&self) -> f64 A single value for player’s skill #### fn uncertainty(&self) -> Option A value for the uncertainty of a players rating. If the algorithm does not include an uncertainty value, this will return `None`. #### fn new(rating: Option, uncertainty: Option) -> Self Initialise a `Rating` with provided score and uncertainty, if `None` use default. If the algorithm does not include an uncertainty value it will get dismissed. ### Dyn Compatibility This trait is **not** dyn compatible. _In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe._ ``` -------------------------------- ### TrueSkillConfig Struct Source: https://docs.rs/skillratings/0.28.2/skillratings/trueskill/struct.TrueSkillConfig.html Configuration parameters for the TrueSkill algorithm. ```APIDOC ## TrueSkillConfig ### Description Constants used in the TrueSkill calculations to adjust rating updates based on game-specific characteristics. ### Fields - **draw_probability** (f64) - The probability of draws occurring in a match. Default: 0.1. - **beta** (f64) - The skill-class width, representing the rating difference needed for an 80% win probability. Default: ~4.167. - **dynamics_factor** (f64) - The additive dynamics factor determining volatility of player positions. Default: ~0.0833. ### Methods #### new() Initializes a new `TrueSkillConfig` with default values (draw_probability: 0.1, beta: ~4.167, dynamics_factor: ~0.0833). ``` -------------------------------- ### Initialize DWZ Rating System Source: https://docs.rs/skillratings/0.28.2/skillratings/dwz/struct.DWZ.html Initializes the DWZ rating system. This function does not require any configuration. ```rust fn new(_config: Self::CONFIG) -> Self ``` -------------------------------- ### Initialize New Glicko2Config Source: https://docs.rs/skillratings/0.28.2/skillratings/glicko2/struct.Glicko2Config.html Creates a new Glicko2Config with default values for tau (0.5) and convergence tolerance (0.000001). ```rust pub const fn new() -> Self ```