elo_rating_system 1.0.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE.md +1 -1
- data/README.md +148 -25
- data/lib/elo_rating_system.rb +180 -14
- metadata +20 -69
- data/.gitignore +0 -11
- data/.rspec +0 -3
- data/.ruby-version +0 -1
- data/.travis.yml +0 -5
- data/Gemfile +0 -5
- data/Gemfile.lock +0 -32
- data/Rakefile +0 -12
- data/VERSION.semver +0 -1
- data/bin/console +0 -15
- data/bin/setup +0 -8
- data/elo_rating_system.gemspec +0 -25
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a72869470138683daefb58ff0a50aa79b699aa3c6404f7dee24ea78d6b3de32b
|
|
4
|
+
data.tar.gz: b2405e2afa7b6674f89cb4f45b9c2066caac9bedfc7b527c91417cafd8abea79
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 445725a78830ca205ace8e5624ca753d16e66f78fdd63672defde951aadbfabe91d1816edbdd7fe83baadd49f9c3b2a506c1a6b4377b7ff9d7c110efcab72ab7
|
|
7
|
+
data.tar.gz: 3ac0958be391a4c91fa9c2f7ac391aa9561c8fa5e550f5d4a5d8d95160a3323e5a83a5af5fce74c7ffe63e11fd4b98b521d295347ae1edeaea6e4d2478c77ca5
|
data/LICENSE.md
CHANGED
data/README.md
CHANGED
|
@@ -1,52 +1,175 @@
|
|
|
1
|
-
#
|
|
1
|
+
# EloRatingSystem
|
|
2
2
|
|
|
3
|
-
[](https://github.com/sashite/elo_rating_system.rb/tags)
|
|
4
|
+
[](https://rubydoc.info/github/sashite/elo_rating_system.rb/main)
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+
[](https://github.com/sashite/elo_rating_system.rb/raw/main/LICENSE.md)
|
|
4
8
|
|
|
5
|
-
|
|
9
|
+
A lightweight, thread-safe Ruby implementation of the [Elo rating system](https://en.wikipedia.org/wiki/Elo_rating_system), a method for calculating the relative skill levels of players in two-player games such as chess.
|
|
6
10
|
|
|
7
|
-
It
|
|
11
|
+
It has two functions: `expected_score`, the score a player is expected to make against an opponent, and `rate`, the rating of a player after one or several games.
|
|
8
12
|
|
|
9
13
|
## Installation
|
|
10
14
|
|
|
11
|
-
|
|
15
|
+
```ruby
|
|
16
|
+
gem "elo_rating_system", "~> 2.0"
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Ruby 3.3 or later is required.
|
|
20
|
+
|
|
21
|
+
Version 2 replaces `expected` and `elo` with `expected_score` and `rate`. See [Upgrading from 1.x](#upgrading-from-1x).
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
### Expected score
|
|
26
|
+
|
|
27
|
+
`EloRatingSystem.expected_score` takes the rating of a player and the rating of an opponent. It returns the score the player is expected to make, between `0.0` and `1.0`:
|
|
12
28
|
|
|
13
29
|
```ruby
|
|
14
|
-
|
|
30
|
+
EloRatingSystem.expected_score(1613, 1609)
|
|
31
|
+
# => 0.5057562084111449
|
|
32
|
+
|
|
33
|
+
EloRatingSystem.expected_score(1613, 1720)
|
|
34
|
+
# => 0.3507050528890364
|
|
35
|
+
|
|
36
|
+
EloRatingSystem.expected_score(1500, 1500)
|
|
37
|
+
# => 0.5
|
|
15
38
|
```
|
|
16
39
|
|
|
17
|
-
|
|
40
|
+
A score is `1` for a win, `0.5` for a draw and `0` for a loss, so the expected score is the probability of winning plus half the probability of drawing. The expected scores of two players against each other add up to `1`.
|
|
41
|
+
|
|
42
|
+
### New rating
|
|
18
43
|
|
|
19
|
-
|
|
44
|
+
`EloRatingSystem.rate` takes the rating of a player and the games of a rating period. Each game is a pair: the rating of the opponent, then the score of the player. It returns the new rating:
|
|
20
45
|
|
|
21
|
-
|
|
46
|
+
```ruby
|
|
47
|
+
EloRatingSystem.rate(1613, [[1609, 0]])
|
|
48
|
+
# => 1596.8158013308434 (a loss against a player rated 1609)
|
|
49
|
+
```
|
|
22
50
|
|
|
23
|
-
|
|
51
|
+
The result is not rounded. Round it where your application needs to, for display or for storage:
|
|
52
|
+
|
|
53
|
+
```ruby
|
|
54
|
+
EloRatingSystem.rate(1613, [[1609, 0]]).round
|
|
55
|
+
# => 1597
|
|
56
|
+
```
|
|
24
57
|
|
|
25
|
-
|
|
58
|
+
### Rating periods
|
|
26
59
|
|
|
27
|
-
|
|
60
|
+
A rating period can be a single game, a tournament, or any set of games you decide to rate at once. All its games are rated from the rating the player had before the period.
|
|
28
61
|
|
|
29
|
-
|
|
62
|
+
In a five-round tournament, a player rated `1613` loses to a player rated `1609`, draws with a player rated `1477`, defeats players rated `1388` and `1586`, and loses to a player rated `1720`:
|
|
30
63
|
|
|
31
64
|
```ruby
|
|
32
|
-
|
|
33
|
-
exp += EloRatingSystem.expected(1613, 1477)
|
|
34
|
-
exp += EloRatingSystem.expected(1613, 1388)
|
|
35
|
-
exp += EloRatingSystem.expected(1613, 1586)
|
|
36
|
-
exp += EloRatingSystem.expected(1613, 1720)
|
|
65
|
+
tournament = [[1609, 0], [1477, 0.5], [1388, 1], [1586, 1], [1720, 0]]
|
|
37
66
|
|
|
38
|
-
|
|
67
|
+
EloRatingSystem.rate(1613, tournament)
|
|
68
|
+
# => 1601.2698768627572
|
|
39
69
|
```
|
|
40
70
|
|
|
41
|
-
|
|
42
|
-
Therefore the player's actual score is `(0 + 0.5 + 1 + 1 + 0) = 2.5`.
|
|
71
|
+
The player scored `2.5` points where `2.867` were expected, and loses `32 × (2.867 − 2.5)` points.
|
|
43
72
|
|
|
44
|
-
|
|
73
|
+
A rating period without any game leaves the rating where it is:
|
|
45
74
|
|
|
46
75
|
```ruby
|
|
47
|
-
EloRatingSystem.
|
|
76
|
+
EloRatingSystem.rate(1613, [])
|
|
77
|
+
# => 1613.0
|
|
48
78
|
```
|
|
49
79
|
|
|
50
|
-
|
|
80
|
+
### K-factor
|
|
81
|
+
|
|
82
|
+
The K-factor is the number of points a rating moves when a score differs from its expectation by one. It defaults to `32` (`EloRatingSystem::DEFAULT_K_FACTOR`), and the `k_factor` keyword sets another one:
|
|
83
|
+
|
|
84
|
+
```ruby
|
|
85
|
+
EloRatingSystem.rate(2400, [[2500, 1]], k_factor: 10)
|
|
86
|
+
# => 2406.4006499980287
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Which K-factor to use, and for which players, is a decision of the organization that publishes the ratings. A higher one makes ratings follow recent results faster.
|
|
90
|
+
|
|
91
|
+
### Scores
|
|
92
|
+
|
|
93
|
+
A score is any number from `0` to `1`. Besides a loss, a draw and a win, this makes room for graded outcomes, as long as the two scores of a game add up to `1`:
|
|
94
|
+
|
|
95
|
+
```ruby
|
|
96
|
+
EloRatingSystem.rate(1500, [[1500, 0.75]])
|
|
97
|
+
# => 1508.0
|
|
98
|
+
|
|
99
|
+
EloRatingSystem.rate(1500, [[1500, 0.25]])
|
|
100
|
+
# => 1492.0
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
When both players are rated with the same K-factor, one gains what the other loses.
|
|
104
|
+
|
|
105
|
+
## Formulas
|
|
106
|
+
|
|
107
|
+
A player rated `R` who meets an opponent rated `Ro` is expected to score:
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
E = 1 / (1 + 10^((Ro − R) / 400))
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
After the games of a rating period, the rating becomes:
|
|
114
|
+
|
|
115
|
+
```
|
|
116
|
+
R′ = R + K × (S − E)
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
where `S` is the sum of the scores of the player, `E` the sum of their expected scores and `K` the K-factor.
|
|
120
|
+
|
|
121
|
+
The test suite compares the library with values that it did not produce: the results of these formulas carried out with 50 significant digits, and the example of the [Wikipedia article](https://en.wikipedia.org/wiki/Elo_rating_system).
|
|
122
|
+
|
|
123
|
+
## Arguments
|
|
124
|
+
|
|
125
|
+
Ratings, scores and K-factors are Integers or Floats. Every argument is checked, so that an invalid value never reaches a rating:
|
|
126
|
+
|
|
127
|
+
| Error | Message | Cause |
|
|
128
|
+
|-------|---------|-------|
|
|
129
|
+
| `TypeError` | `Rating must be an Integer or a Float` | A rating of another class, such as a String or `nil` |
|
|
130
|
+
| `ArgumentError` | `Rating must be finite` | A rating that is NaN or infinite |
|
|
131
|
+
| `TypeError` | `Score must be an Integer or a Float` | A score of another class |
|
|
132
|
+
| `ArgumentError` | `Score must be between 0 and 1` | A score out of range, or NaN |
|
|
133
|
+
| `TypeError` | `K-factor must be an Integer or a Float` | A K-factor of another class |
|
|
134
|
+
| `ArgumentError` | `K-factor must be finite and not negative` | A negative, NaN or infinite K-factor |
|
|
135
|
+
| `TypeError` | `Game results must be an Array` | Game results of another class |
|
|
136
|
+
| `TypeError` | `Game result must be an Array of an opponent rating and a score` | A game result that is not a pair |
|
|
137
|
+
|
|
138
|
+
Numbers of other classes, such as Rationals, are not converted.
|
|
139
|
+
|
|
140
|
+
Every result is a Float, and follows the rules of Float arithmetic: for ratings far apart, the expected score reaches `0.0` or `1.0`.
|
|
141
|
+
|
|
142
|
+
The library has no dependencies, keeps no state, and is safe to call from any thread.
|
|
143
|
+
|
|
144
|
+
## Upgrading from 1.x
|
|
145
|
+
|
|
146
|
+
| 1.x | 2.0 |
|
|
147
|
+
|-----|-----|
|
|
148
|
+
| `EloRatingSystem.expected(1613, 1609)` | `EloRatingSystem.expected_score(1613, 1609)` |
|
|
149
|
+
| `EloRatingSystem.elo(1613, expected, score)` | `EloRatingSystem.rate(1613, game_results)` |
|
|
150
|
+
| `EloRatingSystem.elo(1613, expected, score, 24)` | `EloRatingSystem.rate(1613, game_results, k_factor: 24)` |
|
|
151
|
+
|
|
152
|
+
`expected_score` returns what `expected` returned.
|
|
153
|
+
|
|
154
|
+
`elo` took the sum of the expected scores and the sum of the scores, which the caller had to compute. `rate` takes the games themselves and computes both sums:
|
|
155
|
+
|
|
156
|
+
```ruby
|
|
157
|
+
# 1.x
|
|
158
|
+
expected = [1609, 1477, 1388, 1586, 1720].sum { |opponent_rating| EloRatingSystem.expected(1613, opponent_rating) }
|
|
159
|
+
EloRatingSystem.elo(1613, expected, 2.5)
|
|
160
|
+
|
|
161
|
+
# 2.0
|
|
162
|
+
EloRatingSystem.rate(1613, [[1609, 0], [1477, 0.5], [1388, 1], [1586, 1], [1720, 0]])
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Version 2 also checks its arguments: 1.x computed with whatever it was given, and returned NaN for a NaN.
|
|
166
|
+
|
|
167
|
+
## License
|
|
168
|
+
|
|
169
|
+
The code is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
170
|
+
|
|
171
|
+
## About Sashité
|
|
172
|
+
|
|
173
|
+
This [gem](https://rubygems.org/gems/elo_rating_system) is maintained by [Sashité](https://sashite.com/).
|
|
51
174
|
|
|
52
|
-
|
|
175
|
+
With some [lines of code](https://github.com/sashite/), let's share the beauty of Chinese, Japanese and Western cultures through the game of chess!
|
data/lib/elo_rating_system.rb
CHANGED
|
@@ -1,24 +1,190 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# Elo rating system
|
|
3
|
+
# The Elo rating system for two-player games.
|
|
4
|
+
#
|
|
5
|
+
# {EloRatingSystem.expected_score} returns the score a player is expected to
|
|
6
|
+
# make against an opponent, and {EloRatingSystem.rate} returns the rating of
|
|
7
|
+
# a player after one or several games:
|
|
8
|
+
#
|
|
9
|
+
# EloRatingSystem.expected_score(1613, 1609)
|
|
10
|
+
# # => 0.5057562084111449
|
|
11
|
+
#
|
|
12
|
+
# EloRatingSystem.rate(1613, [[1609, 0]])
|
|
13
|
+
# # => 1596.8158013308434
|
|
14
|
+
#
|
|
15
|
+
# The library has no dependencies and keeps no state. It is safe to call from
|
|
16
|
+
# any thread.
|
|
17
|
+
#
|
|
18
|
+
# == Formulas
|
|
19
|
+
#
|
|
20
|
+
# A player rated +R+ who meets an opponent rated +Ro+ is expected to score:
|
|
21
|
+
#
|
|
22
|
+
# E = 1 / (1 + 10^((Ro - R) / 400))
|
|
23
|
+
#
|
|
24
|
+
# A score is +1+ for a win, +0.5+ for a draw and +0+ for a loss, so that the
|
|
25
|
+
# expected score is the probability of winning plus half the probability of
|
|
26
|
+
# drawing. After the games of a rating period, the rating becomes:
|
|
27
|
+
#
|
|
28
|
+
# R' = R + K * (S - E)
|
|
29
|
+
#
|
|
30
|
+
# where +S+ is the sum of the scores of the player, +E+ the sum of their
|
|
31
|
+
# expected scores and +K+ the K-factor: the number of points a rating moves
|
|
32
|
+
# when a score differs from its expectation by one.
|
|
33
|
+
#
|
|
34
|
+
# == Arguments
|
|
35
|
+
#
|
|
36
|
+
# Ratings, scores and K-factors are Integers or Floats, and every result is a
|
|
37
|
+
# Float. Other numbers, such as Rationals, are not converted. Every argument
|
|
38
|
+
# is checked: NaN, an infinite value, a score out of range or a negative
|
|
39
|
+
# K-factor raises an error, so that an invalid value never reaches a rating.
|
|
4
40
|
#
|
|
5
41
|
# @see https://en.wikipedia.org/wiki/Elo_rating_system
|
|
6
42
|
module EloRatingSystem
|
|
7
|
-
|
|
8
|
-
|
|
43
|
+
# The K-factor {rate} uses when none is given.
|
|
44
|
+
DEFAULT_K_FACTOR = 32
|
|
45
|
+
|
|
46
|
+
# The rating difference that multiplies the odds of a player by {BASE}: a
|
|
47
|
+
# player rated 400 points above an opponent is expected to score ten times
|
|
48
|
+
# as much as the opponent.
|
|
49
|
+
SCALE = 400.0
|
|
50
|
+
|
|
51
|
+
# See {SCALE}.
|
|
52
|
+
BASE = 10.0
|
|
53
|
+
|
|
54
|
+
# The values a rating can take: every finite number.
|
|
55
|
+
RATINGS = -::Float::MAX..::Float::MAX
|
|
56
|
+
|
|
57
|
+
# The values a score can take, from a loss to a win.
|
|
58
|
+
SCORES = 0.0..1.0
|
|
59
|
+
|
|
60
|
+
# The values a K-factor can take: every finite number that is not negative.
|
|
61
|
+
K_FACTORS = 0.0..::Float::MAX
|
|
62
|
+
|
|
63
|
+
# Error message raised when a rating is neither an Integer nor a Float.
|
|
64
|
+
RATING_TYPE_ERROR = "Rating must be an Integer or a Float"
|
|
65
|
+
|
|
66
|
+
# Error message raised when a rating is NaN or infinite.
|
|
67
|
+
RATING_RANGE_ERROR = "Rating must be finite"
|
|
68
|
+
|
|
69
|
+
# Error message raised when a score is neither an Integer nor a Float.
|
|
70
|
+
SCORE_TYPE_ERROR = "Score must be an Integer or a Float"
|
|
71
|
+
|
|
72
|
+
# Error message raised when a score is not between a loss and a win.
|
|
73
|
+
SCORE_RANGE_ERROR = "Score must be between 0 and 1"
|
|
74
|
+
|
|
75
|
+
# Error message raised when a K-factor is neither an Integer nor a Float.
|
|
76
|
+
K_FACTOR_TYPE_ERROR = "K-factor must be an Integer or a Float"
|
|
77
|
+
|
|
78
|
+
# Error message raised when a K-factor is negative, NaN or infinite.
|
|
79
|
+
K_FACTOR_RANGE_ERROR = "K-factor must be finite and not negative"
|
|
80
|
+
|
|
81
|
+
# Error message raised when the game results are not an Array.
|
|
82
|
+
GAME_RESULTS_TYPE_ERROR = "Game results must be an Array"
|
|
83
|
+
|
|
84
|
+
# Error message raised when a game result is not a pair.
|
|
85
|
+
GAME_RESULT_TYPE_ERROR = "Game result must be an Array of an opponent rating and a score"
|
|
86
|
+
|
|
87
|
+
private_constant :SCALE, :BASE, :RATINGS, :SCORES, :K_FACTORS,
|
|
88
|
+
:RATING_TYPE_ERROR, :RATING_RANGE_ERROR,
|
|
89
|
+
:SCORE_TYPE_ERROR, :SCORE_RANGE_ERROR,
|
|
90
|
+
:K_FACTOR_TYPE_ERROR, :K_FACTOR_RANGE_ERROR,
|
|
91
|
+
:GAME_RESULTS_TYPE_ERROR, :GAME_RESULT_TYPE_ERROR
|
|
92
|
+
|
|
93
|
+
class << self
|
|
94
|
+
# Returns the score a player rated +rating+ is expected to make against
|
|
95
|
+
# an opponent rated +opponent_rating+.
|
|
9
96
|
#
|
|
10
|
-
#
|
|
11
|
-
#
|
|
12
|
-
|
|
13
|
-
|
|
97
|
+
# The expected scores of two players against each other add up to 1.
|
|
98
|
+
#
|
|
99
|
+
# @param rating [Integer, Float] the rating of the player
|
|
100
|
+
# @param opponent_rating [Integer, Float] the rating of the opponent
|
|
101
|
+
#
|
|
102
|
+
# @return [Float] the expected score, between 0.0 and 1.0
|
|
103
|
+
#
|
|
104
|
+
# @raise [TypeError] if a rating is neither an Integer nor a Float
|
|
105
|
+
# @raise [ArgumentError] if a rating is NaN or infinite
|
|
106
|
+
#
|
|
107
|
+
# @example Players of equal strength
|
|
108
|
+
# EloRatingSystem.expected_score(1500, 1500)
|
|
109
|
+
# # => 0.5
|
|
110
|
+
#
|
|
111
|
+
# @example A player rated 400 points above their opponent
|
|
112
|
+
# EloRatingSystem.expected_score(1900, 1500)
|
|
113
|
+
# # => 0.9090909090909091
|
|
114
|
+
def expected_score(rating, opponent_rating)
|
|
115
|
+
expectation(to_rating(rating), to_rating(opponent_rating))
|
|
116
|
+
end
|
|
14
117
|
|
|
15
|
-
|
|
16
|
-
#
|
|
118
|
+
# Returns the rating of a player after a rating period, given the games
|
|
119
|
+
# they played in it.
|
|
120
|
+
#
|
|
121
|
+
# All the games of a rating period are rated at once, from the rating the
|
|
122
|
+
# player had before the period. A rating period can be a tournament, or a
|
|
123
|
+
# single game.
|
|
124
|
+
#
|
|
125
|
+
# @param rating [Integer, Float] the rating of the player before the
|
|
126
|
+
# rating period
|
|
127
|
+
# @param game_results [Array<Array<Integer, Float>>] the games of the
|
|
128
|
+
# rating period: for each one, the rating of the opponent and the score
|
|
129
|
+
# of the player, from 0 (loss) to 1 (win)
|
|
130
|
+
# @param k_factor [Integer, Float] the K-factor
|
|
131
|
+
#
|
|
132
|
+
# @return [Float] the new rating, which is not rounded
|
|
133
|
+
#
|
|
134
|
+
# @raise [TypeError] if +game_results+ is not an Array of pairs, or if a
|
|
135
|
+
# rating, a score or the K-factor is neither an Integer nor a Float
|
|
136
|
+
# @raise [ArgumentError] if a rating or the K-factor is NaN or infinite,
|
|
137
|
+
# if a score is not between 0 and 1, or if the K-factor is negative
|
|
17
138
|
#
|
|
18
|
-
# @
|
|
19
|
-
#
|
|
20
|
-
#
|
|
21
|
-
#
|
|
22
|
-
|
|
139
|
+
# @example A tournament of five games
|
|
140
|
+
# EloRatingSystem.rate(1613, [[1609, 0], [1477, 0.5], [1388, 1], [1586, 1], [1720, 0]])
|
|
141
|
+
# # => 1601.2698768627572
|
|
142
|
+
#
|
|
143
|
+
# @example A single game, with another K-factor
|
|
144
|
+
# EloRatingSystem.rate(2400, [[2500, 1]], k_factor: 10)
|
|
145
|
+
# # => 2406.4006499980287
|
|
146
|
+
#
|
|
147
|
+
# @example A rating period without any game
|
|
148
|
+
# EloRatingSystem.rate(1613, [])
|
|
149
|
+
# # => 1613.0
|
|
150
|
+
def rate(rating, game_results, k_factor: DEFAULT_K_FACTOR)
|
|
151
|
+
raise ::TypeError, GAME_RESULTS_TYPE_ERROR unless game_results.is_a?(::Array)
|
|
152
|
+
|
|
153
|
+
rating = to_rating(rating)
|
|
154
|
+
k_factor = float(k_factor, K_FACTORS, K_FACTOR_TYPE_ERROR, K_FACTOR_RANGE_ERROR)
|
|
155
|
+
|
|
156
|
+
rating + (k_factor * game_results.sum(0.0) { |game_result| surplus(rating, game_result) })
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
private
|
|
160
|
+
|
|
161
|
+
# The score of a game, less the score that was expected.
|
|
162
|
+
def surplus(rating, game_result)
|
|
163
|
+
raise ::TypeError, GAME_RESULT_TYPE_ERROR unless game_result.is_a?(::Array) && game_result.size == 2
|
|
164
|
+
|
|
165
|
+
opponent_rating, score = game_result
|
|
166
|
+
|
|
167
|
+
float(score, SCORES, SCORE_TYPE_ERROR, SCORE_RANGE_ERROR) - expectation(rating, to_rating(opponent_rating))
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
# E = 1 / (1 + 10^((Ro - R) / 400))
|
|
171
|
+
def expectation(rating, opponent_rating)
|
|
172
|
+
1.0 / (1.0 + (BASE**((opponent_rating - rating) / SCALE)))
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
# A rating as a Float, once checked.
|
|
176
|
+
def to_rating(value)
|
|
177
|
+
float(value, RATINGS, RATING_TYPE_ERROR, RATING_RANGE_ERROR)
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
# A number as a Float, once checked against the values it can take. The
|
|
181
|
+
# range is tested before the conversion: an Integer too large for a Float
|
|
182
|
+
# is out of every range.
|
|
183
|
+
def float(value, range, type_error, range_error)
|
|
184
|
+
raise ::TypeError, type_error unless value.is_a?(::Integer) || value.is_a?(::Float)
|
|
185
|
+
raise ::ArgumentError, range_error unless range.cover?(value)
|
|
186
|
+
|
|
187
|
+
value.to_f
|
|
188
|
+
end
|
|
23
189
|
end
|
|
24
190
|
end
|
metadata
CHANGED
|
@@ -1,84 +1,36 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: elo_rating_system
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Cyril Kato
|
|
8
|
-
autorequire:
|
|
9
|
-
bindir:
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
12
|
-
dependencies:
|
|
13
|
-
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
- - "~>"
|
|
18
|
-
- !ruby/object:Gem::Version
|
|
19
|
-
version: '1.16'
|
|
20
|
-
type: :development
|
|
21
|
-
prerelease: false
|
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
-
requirements:
|
|
24
|
-
- - "~>"
|
|
25
|
-
- !ruby/object:Gem::Version
|
|
26
|
-
version: '1.16'
|
|
27
|
-
- !ruby/object:Gem::Dependency
|
|
28
|
-
name: fix
|
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
|
30
|
-
requirements:
|
|
31
|
-
- - "~>"
|
|
32
|
-
- !ruby/object:Gem::Version
|
|
33
|
-
version: '0.17'
|
|
34
|
-
type: :development
|
|
35
|
-
prerelease: false
|
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
-
requirements:
|
|
38
|
-
- - "~>"
|
|
39
|
-
- !ruby/object:Gem::Version
|
|
40
|
-
version: '0.17'
|
|
41
|
-
- !ruby/object:Gem::Dependency
|
|
42
|
-
name: rake
|
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
|
44
|
-
requirements:
|
|
45
|
-
- - "~>"
|
|
46
|
-
- !ruby/object:Gem::Version
|
|
47
|
-
version: '12.3'
|
|
48
|
-
type: :development
|
|
49
|
-
prerelease: false
|
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
-
requirements:
|
|
52
|
-
- - "~>"
|
|
53
|
-
- !ruby/object:Gem::Version
|
|
54
|
-
version: '12.3'
|
|
55
|
-
description: A method for calculating the relative skill levels of players in zero-sum
|
|
56
|
-
games such as chess.
|
|
57
|
-
email:
|
|
58
|
-
- contact@cyril.email
|
|
11
|
+
date: 2026-12-04 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: A lightweight, thread-safe Ruby implementation of the Elo rating system,
|
|
14
|
+
a method for calculating the relative skill levels of players in two-player games
|
|
15
|
+
such as chess.
|
|
16
|
+
email: contact@cyril.email
|
|
59
17
|
executables: []
|
|
60
18
|
extensions: []
|
|
61
19
|
extra_rdoc_files: []
|
|
62
20
|
files:
|
|
63
|
-
- ".gitignore"
|
|
64
|
-
- ".rspec"
|
|
65
|
-
- ".ruby-version"
|
|
66
|
-
- ".travis.yml"
|
|
67
|
-
- Gemfile
|
|
68
|
-
- Gemfile.lock
|
|
69
21
|
- LICENSE.md
|
|
70
22
|
- README.md
|
|
71
|
-
- Rakefile
|
|
72
|
-
- VERSION.semver
|
|
73
|
-
- bin/console
|
|
74
|
-
- bin/setup
|
|
75
|
-
- elo_rating_system.gemspec
|
|
76
23
|
- lib/elo_rating_system.rb
|
|
77
|
-
homepage: https://github.com/sashite/elo_rating_system
|
|
24
|
+
homepage: https://github.com/sashite/elo_rating_system.rb
|
|
78
25
|
licenses:
|
|
79
26
|
- MIT
|
|
80
|
-
metadata:
|
|
81
|
-
|
|
27
|
+
metadata:
|
|
28
|
+
rubygems_mfa_required: 'true'
|
|
29
|
+
source_code_uri: https://github.com/sashite/elo_rating_system.rb
|
|
30
|
+
documentation_uri: https://rubydoc.info/github/sashite/elo_rating_system.rb/main
|
|
31
|
+
bug_tracker_uri: https://github.com/sashite/elo_rating_system.rb/issues
|
|
32
|
+
changelog_uri: https://github.com/sashite/elo_rating_system.rb/blob/main/CHANGELOG.md
|
|
33
|
+
post_install_message:
|
|
82
34
|
rdoc_options: []
|
|
83
35
|
require_paths:
|
|
84
36
|
- lib
|
|
@@ -86,16 +38,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
86
38
|
requirements:
|
|
87
39
|
- - ">="
|
|
88
40
|
- !ruby/object:Gem::Version
|
|
89
|
-
version:
|
|
41
|
+
version: 3.3.0
|
|
90
42
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
43
|
requirements:
|
|
92
44
|
- - ">="
|
|
93
45
|
- !ruby/object:Gem::Version
|
|
94
46
|
version: '0'
|
|
95
47
|
requirements: []
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
signing_key:
|
|
48
|
+
rubygems_version: 3.5.22
|
|
49
|
+
signing_key:
|
|
99
50
|
specification_version: 4
|
|
100
51
|
summary: Elo rating system
|
|
101
52
|
test_files: []
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.ruby-version
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
2.5.0
|
data/.travis.yml
DELETED
data/Gemfile
DELETED
data/Gemfile.lock
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
PATH
|
|
2
|
-
remote: .
|
|
3
|
-
specs:
|
|
4
|
-
elo_rating_system (1.0.0)
|
|
5
|
-
|
|
6
|
-
GEM
|
|
7
|
-
remote: https://rubygems.org/
|
|
8
|
-
specs:
|
|
9
|
-
aw (0.1.1)
|
|
10
|
-
defi (1.1.3)
|
|
11
|
-
fix (0.17.1)
|
|
12
|
-
aw (~> 0.1.1)
|
|
13
|
-
defi (~> 1.1.3)
|
|
14
|
-
spectus (~> 3.0.6)
|
|
15
|
-
matchi (1.0.2)
|
|
16
|
-
rake (12.3.1)
|
|
17
|
-
spectus (3.0.6)
|
|
18
|
-
aw (~> 0.1.1)
|
|
19
|
-
defi (~> 1.1.1)
|
|
20
|
-
matchi (~> 1.0.2)
|
|
21
|
-
|
|
22
|
-
PLATFORMS
|
|
23
|
-
ruby
|
|
24
|
-
|
|
25
|
-
DEPENDENCIES
|
|
26
|
-
bundler (~> 1.16)
|
|
27
|
-
elo_rating_system!
|
|
28
|
-
fix (~> 0.17)
|
|
29
|
-
rake (~> 12.3)
|
|
30
|
-
|
|
31
|
-
BUNDLED WITH
|
|
32
|
-
1.16.1
|
data/Rakefile
DELETED
data/VERSION.semver
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
1.0.0
|
data/bin/console
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
# frozen_string_literal: true
|
|
3
|
-
|
|
4
|
-
require 'bundler/setup'
|
|
5
|
-
require 'elo_rating_system'
|
|
6
|
-
|
|
7
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
|
8
|
-
# with your gem easier. You can also use a different console, if you like.
|
|
9
|
-
|
|
10
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
11
|
-
# require "pry"
|
|
12
|
-
# Pry.start
|
|
13
|
-
|
|
14
|
-
require 'irb'
|
|
15
|
-
IRB.start(__FILE__)
|
data/bin/setup
DELETED
data/elo_rating_system.gemspec
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
Gem::Specification.new do |spec|
|
|
4
|
-
spec.name = 'elo_rating_system'
|
|
5
|
-
spec.version = File.read('VERSION.semver').chomp
|
|
6
|
-
spec.authors = ['Cyril Kato']
|
|
7
|
-
spec.email = ['contact@cyril.email']
|
|
8
|
-
|
|
9
|
-
spec.summary = 'Elo rating system'
|
|
10
|
-
spec.description = 'A method for calculating the relative skill levels ' \
|
|
11
|
-
'of players in zero-sum games such as chess.'
|
|
12
|
-
spec.homepage = 'https://github.com/sashite/elo_rating_system'
|
|
13
|
-
spec.license = 'MIT'
|
|
14
|
-
|
|
15
|
-
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
16
|
-
f.match(%r{^(fix)/})
|
|
17
|
-
end
|
|
18
|
-
spec.bindir = 'exe'
|
|
19
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
20
|
-
spec.require_paths = ['lib']
|
|
21
|
-
|
|
22
|
-
spec.add_development_dependency 'bundler', '~> 1.16'
|
|
23
|
-
spec.add_development_dependency 'fix', '~> 0.17'
|
|
24
|
-
spec.add_development_dependency 'rake', '~> 12.3'
|
|
25
|
-
end
|