1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//! # ELO rating
//!
//! This module contains all of the standard methods that would be used to calculate elo.
//! The module provied the constants WIN, LOSE and DRAW.
/// The EloRating type is i32 since a rating can be negative.
pub type EloRating = i32;
/// The score for a won game
pub const WIN: f32 = 1_f32;
/// The score for a drawn game
pub const DRAW: f32 = 0.5;
/// The score for a lost game
pub const LOSS: f32 = 0_f32;
/// Calculates the expected outcome of a match between two players.
/// This will always be a number between 0 and 1.
/// The closer to 1 the more favored the match is for player a.
///
/// # Example
///
/// Chance of a person winning
///
/// ```
/// use skill_rating::elo;
///
/// let john = 1700;
/// let paul = 1800;
///
/// // Calculate johns chance to win against paul
/// let chance = elo::expected_score(john, paul) * 100_f32;
/// ```
/// Calculates the updated elo ratings of both players after a match.
/// The k_a and k_b are the K factors used to determine the updated rating,
/// If you just want a default behaviou set these to 32, or use game_icc() instead.
///
/// # Example
///
/// Updates the rankings of John and Paul, after Paul won over John.
///
/// ```
/// use skill_rating::elo;
///
/// let john = 1700;
/// let paul = 1800;
///
/// let (john, paul) = elo::game(paul, john, elo::WIN, 32, 32);
/// ```
/// Calculates the updated elo of a player, after a series of games.
/// This might be used to calculate the rating of a player after a tournement.
///
/// # Example
///
/// Update the rating of John after competing in a chess tournement.
///
/// ```
/// use skill_rating::elo;
///
/// let john = 1700;
///
/// // An array containing the results of johns games in the tournement
/// let games = [(1600, elo::WIN), (1800, elo::DRAW), (2000, elo::LOSS)];
///
/// let john = elo::series(john, &games, 32);
/// ```