elo_rating_system 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '0909a55bfa03184b3749b7541ab13e04ec8fb18046e91f3ca4195dc0d754df52'
4
+ data.tar.gz: e1e94e1e98ab97a7dfbd97711d3936a061d9118c24d8b27d3d2dc53ab2e67900
5
+ SHA512:
6
+ metadata.gz: a45de5f13d7ca44c825e1ad33740a3b6959e305d12539a5c275892b29ef08807aa501c67644358ad432d8a583212cb5c5aee427565ba445f0ef044077db47f21
7
+ data.tar.gz: ddb80c8f9a831471682ccea378da95bbb08c9c50e24e2f991047fab22c2020a85b9d6a297701487656b92c20fb3a1f2197e5eb7c0b5c2fce8157ee7843dfd309
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1 @@
1
+ 2.5.0
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.0
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
@@ -0,0 +1,32 @@
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
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Sashite
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,52 @@
1
+ # Elo rating system
2
+
3
+ [![Inline docs](https://inch-ci.org/github/sashite/elo_rating_system.svg?branch=master)][inchpages]
4
+
5
+ Very simple Ruby implementation of the Elo rating system, a method for calculating the relative skill levels of players in zero-sum games such as chess.
6
+
7
+ It contains two functions: `expected(player_a, player_b)`, to calculate the expected score of `player_a` in a match against `player_b`; and `elo(old, exp, score, k_factor = 32)`, to calculate the new score for each player.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'elo_rating_system'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install elo_rating_system
24
+
25
+ ## Example
26
+
27
+ In a five-round tournament, player A, with a rating of `1613`, plays against opponents with the following ratings: `1609`, `1477`, `1388`, `1586`, `1720`.
28
+
29
+ The expected score is therefore:
30
+
31
+ ```ruby
32
+ exp = EloRatingSystem.expected(1613, 1609)
33
+ exp += EloRatingSystem.expected(1613, 1477)
34
+ exp += EloRatingSystem.expected(1613, 1388)
35
+ exp += EloRatingSystem.expected(1613, 1586)
36
+ exp += EloRatingSystem.expected(1613, 1720)
37
+
38
+ exp.round(3) # => 2.867
39
+ ```
40
+
41
+ Player A lost match #1, draw match #2, wins match #3 and #4, and loses match #5.
42
+ Therefore the player's actual score is `(0 + 0.5 + 1 + 1 + 0) = 2.5`.
43
+
44
+ We can now use this to calculate the new Elo rating for player A:
45
+
46
+ ```ruby
47
+ EloRatingSystem.elo(1613, 2.867, 2.5).round # => 1601
48
+ ```
49
+
50
+ ## Contributing
51
+
52
+ Bug reports and pull requests are welcome on GitHub at https://github.com/sashite/elo_rating_system.
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.verbose = true
8
+ t.warning = true
9
+ t.pattern = File.join('fix', '**', '*_fix.rb')
10
+ end
11
+
12
+ task default: %i[test]
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,15 @@
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__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,25 @@
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
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Elo rating system
4
+ #
5
+ # @see https://en.wikipedia.org/wiki/Elo_rating_system
6
+ module EloRatingSystem
7
+ def self.expected(player_a, player_b)
8
+ # @note Calculate expected score of A in a match against B.
9
+ #
10
+ # @param player_a [Integer] Elo rating for player a.
11
+ # @param player_b [Integer] Elo rating for player b.
12
+ 1 / (1 + 10**((player_b - player_a.to_f) / 400))
13
+ end
14
+
15
+ def self.elo(old, exp, score, k_factor = 32)
16
+ # @note Calculate the new Elo rating for a player.
17
+ #
18
+ # @param old [Integer] The previous Elo rating.
19
+ # @param exp [Float] The expected score for this match.
20
+ # @param score [Float] The actual score for this match.
21
+ # @param k_factor [Integer] The k-factor for Elo (default: 32).
22
+ old + k_factor * (score - exp)
23
+ end
24
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: elo_rating_system
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Cyril Kato
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-08-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
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
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".ruby-version"
66
+ - ".travis.yml"
67
+ - Gemfile
68
+ - Gemfile.lock
69
+ - LICENSE.md
70
+ - README.md
71
+ - Rakefile
72
+ - VERSION.semver
73
+ - bin/console
74
+ - bin/setup
75
+ - elo_rating_system.gemspec
76
+ - lib/elo_rating_system.rb
77
+ homepage: https://github.com/sashite/elo_rating_system
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.7.3
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Elo rating system
101
+ test_files: []