elo 0.0.2.alpha
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.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/README.rdoc +124 -0
- data/Rakefile +50 -0
- data/VERSION +1 -0
- data/doc/classes/Elo.html +67 -0
- data/doc/classes/Elo/Configuration.html +184 -0
- data/doc/classes/Elo/EloHelper.html +124 -0
- data/doc/classes/Elo/EloHelper/ClassMethods.html +78 -0
- data/doc/classes/Elo/Game.html +193 -0
- data/doc/classes/Elo/Player.html +254 -0
- data/doc/classes/Elo/Rating.html +141 -0
- data/doc/created.rid +1 -0
- data/doc/files/README_rdoc.html +163 -0
- data/doc/files/lib/elo_rb.html +58 -0
- data/doc/fr_class_index.html +21 -0
- data/doc/fr_file_index.html +21 -0
- data/doc/fr_method_index.html +4469 -0
- data/doc/index.html +15 -0
- data/doc/rdoc-style.css +328 -0
- data/lib/elo.rb +298 -0
- data/spec/elo_spec.rb +7 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +9 -0
- metadata +102 -0
data/.document
ADDED
data/.gitignore
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
= Elo
|
2
|
+
|
3
|
+
From {Wikipedia}[http://en.wikipedia.org/wiki/Elo_rating_system]:
|
4
|
+
|
5
|
+
The Elo rating system is a method for calculating the relative skill levels of
|
6
|
+
players in two-player games such as chess and Go. It is named after its creator
|
7
|
+
Arpad Elo, a Hungarian-born American physics professor.
|
8
|
+
|
9
|
+
The Elo system was invented as an improved chess rating system, but today it is
|
10
|
+
also used in many other games. It is also used as a rating system for multiplayer
|
11
|
+
competition in a number of computer games, and has been adapted to team sports
|
12
|
+
including association football, American college football and basketball, and
|
13
|
+
Major League Baseball.
|
14
|
+
|
15
|
+
== Links
|
16
|
+
|
17
|
+
* {API documentation}[http://iain.github.com/elo/doc]
|
18
|
+
* {Source Code}[http://github.com/iain/elo]
|
19
|
+
|
20
|
+
== Usage
|
21
|
+
|
22
|
+
You need to have at least to players that can play a game (duh).
|
23
|
+
|
24
|
+
bob = Elo::Player.new
|
25
|
+
jane = Elo::Player.new(:rating => 1500)
|
26
|
+
|
27
|
+
Once you have players, you can register games in a variaty of ways.
|
28
|
+
There is more than one way to do it, choose whatever works from your other code:
|
29
|
+
|
30
|
+
game1 = bob.wins_from(jane)
|
31
|
+
game2 = bob.loses_from(jane)
|
32
|
+
game3 = bob.plays_draw(jane)
|
33
|
+
|
34
|
+
game4 = bob.versus(jane)
|
35
|
+
game4.winner = jane
|
36
|
+
|
37
|
+
game5 = bob.versus(jane)
|
38
|
+
game5.loser = jane
|
39
|
+
|
40
|
+
game6 = bob.versus(jane)
|
41
|
+
game6.draw
|
42
|
+
|
43
|
+
game7 = bob.versus(jane)
|
44
|
+
game7.result = 1 # result is in perspective of bob, so bob wins
|
45
|
+
|
46
|
+
You can get all kinds of info from a player:
|
47
|
+
|
48
|
+
bob.rating
|
49
|
+
bob.pro?
|
50
|
+
bob.starter?
|
51
|
+
bob.pro_rating?
|
52
|
+
bob.games_played
|
53
|
+
bob.games
|
54
|
+
|
55
|
+
Or get a list of players:
|
56
|
+
|
57
|
+
Elo::Player.all
|
58
|
+
|
59
|
+
|
60
|
+
== Configuration
|
61
|
+
|
62
|
+
You can configure Elo in many ways. In it's default configuration, it is configured
|
63
|
+
in the same way as the {FIDE}[http://www.fide.com/] (World Chess Foundation).
|
64
|
+
|
65
|
+
Altering settings to your liking is very easy and very flexible. You can even specify
|
66
|
+
your own K-factor rules. Have a look at the Rdoc in the code for a complete reference.
|
67
|
+
|
68
|
+
Here is an example:
|
69
|
+
|
70
|
+
Elo.configure do |config|
|
71
|
+
|
72
|
+
# Every player starts with a rating of 1000
|
73
|
+
config.default_rating = 1000
|
74
|
+
|
75
|
+
# A player is considered a pro, when he/she has more than 2400 points
|
76
|
+
config.pro_rating_boundry = 2400
|
77
|
+
|
78
|
+
# A player is considered a new, when he/she has played less than 30 games
|
79
|
+
config.starter_boundry = 30
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
== About the K-factor
|
84
|
+
|
85
|
+
The Elo rating system knows a variable called the "K-factor". The K-factor is used
|
86
|
+
to reward new talent and stableize the rating once a player is participating longer.
|
87
|
+
|
88
|
+
FIDE (the World Chess Foundation), gives players with less than 30 played games a
|
89
|
+
K-factor of 25. Normal players get a K-factor of 15 and pro's get a K-factor of 10.
|
90
|
+
Once you reach a pro status, you're K-factor never changes, even if your rating drops.
|
91
|
+
|
92
|
+
You need to provide Elo the amount of games played, their rating and their pro-status.
|
93
|
+
|
94
|
+
bob = Elo::Player.new(:games_played => 29, :rating => 2300, :pro => true)
|
95
|
+
|
96
|
+
You can define your own K-factors by adding K-factor rules.
|
97
|
+
This code will change the K-factor to 12, for every player who's name starts with a B,
|
98
|
+
and 16 for everybody else.
|
99
|
+
|
100
|
+
Elo.configure do |config|
|
101
|
+
config.k_factor(12) { name =~ /^b/i }
|
102
|
+
config.default_k_factor = 16
|
103
|
+
config.use_FIDE_settings = false
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
== Installation
|
109
|
+
|
110
|
+
gem install elo
|
111
|
+
|
112
|
+
== Note on Patches/Pull Requests
|
113
|
+
|
114
|
+
* Fork the project.
|
115
|
+
* Make your feature addition or bug fix.
|
116
|
+
* Add tests for it. This is important so I don't break it in a
|
117
|
+
future version unintentionally.
|
118
|
+
* Commit, do not mess with rakefile, version, or history.
|
119
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
120
|
+
* Send me a pull request. Bonus points for topic branches.
|
121
|
+
|
122
|
+
== Copyright
|
123
|
+
|
124
|
+
Copyright (c) 2010 Iain Hecker. Released under the MIT License
|
data/Rakefile
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "elo"
|
8
|
+
gem.summary = %Q{The Elo rating system is a method for calculating the relative skill levels of players in two-player games such as cess and Go.}
|
9
|
+
gem.description = %Q{The Elo rating system is a method for calculating the relative skill levels of players in two-player games such as cess and Go.}
|
10
|
+
gem.email = "iain@iain.nl"
|
11
|
+
gem.homepage = "http://github.com/iain/elo"
|
12
|
+
gem.authors = ["Iain Hecker"]
|
13
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'spec/rake/spectask'
|
22
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
23
|
+
spec.libs << 'lib' << 'spec'
|
24
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
25
|
+
end
|
26
|
+
|
27
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
28
|
+
spec.libs << 'lib' << 'spec'
|
29
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
30
|
+
spec.rcov = true
|
31
|
+
end
|
32
|
+
|
33
|
+
task :spec => :check_dependencies
|
34
|
+
|
35
|
+
task :default => :spec
|
36
|
+
|
37
|
+
begin
|
38
|
+
require 'hanna/rdoctask'
|
39
|
+
rescue LoadError
|
40
|
+
require 'rake/rdoctask'
|
41
|
+
end
|
42
|
+
|
43
|
+
Rake::RDocTask.new do |rdoc|
|
44
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
45
|
+
|
46
|
+
rdoc.rdoc_dir = 'doc'
|
47
|
+
rdoc.title = "elo #{version}"
|
48
|
+
rdoc.rdoc_files.include('README*')
|
49
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
50
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.2.alpha
|
@@ -0,0 +1,67 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
2
|
+
<html lang='en'>
|
3
|
+
<head>
|
4
|
+
<title>: Elo [elo ]</title>
|
5
|
+
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type'>
|
6
|
+
<link href='../rdoc-style.css' media='screen' rel='stylesheet' type='text/css'>
|
7
|
+
<script type='text/javascript'>
|
8
|
+
//<![CDATA[
|
9
|
+
function popupCode(url) {
|
10
|
+
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
11
|
+
}
|
12
|
+
|
13
|
+
function toggleCode(id) {
|
14
|
+
var code = document.getElementById(id)
|
15
|
+
|
16
|
+
code.style.display = code.style.display != 'block' ? 'block' : 'none'
|
17
|
+
return true
|
18
|
+
}
|
19
|
+
|
20
|
+
// Make codeblocks hidden by default
|
21
|
+
document.writeln('<' + 'style type="text/css">.method .source pre { display: none }<\/style>')
|
22
|
+
//]]>
|
23
|
+
</script>
|
24
|
+
</head>
|
25
|
+
<body class='page'>
|
26
|
+
<div class='class' id='wrapper'>
|
27
|
+
<div class='header'>
|
28
|
+
<h1 class='name'>
|
29
|
+
<span class='type'>Module</span>
|
30
|
+
Elo
|
31
|
+
</h1>
|
32
|
+
<ol class='paths'>
|
33
|
+
<li>
|
34
|
+
<a href="../files/lib/elo_rb.html">lib/elo.rb</a>
|
35
|
+
</li>
|
36
|
+
</ol>
|
37
|
+
</div>
|
38
|
+
<div id='content'>
|
39
|
+
<div id='text'>
|
40
|
+
<div id='description'>
|
41
|
+
<p>
|
42
|
+
The configuration of <a href="Elo.html">Elo</a> is done here.
|
43
|
+
</p>
|
44
|
+
<p>
|
45
|
+
See <a href="../files/README_rdoc.html">README.rdoc</a> for general
|
46
|
+
information about <a href="Elo.html">Elo</a>.
|
47
|
+
</p>
|
48
|
+
</div>
|
49
|
+
<div id='section'>
|
50
|
+
<div id='class-list'>
|
51
|
+
<h2>Classes and Modules</h2>
|
52
|
+
Module <a href="Elo/Configuration.html" class="link">Elo::Configuration</a><br />
|
53
|
+
Module <a href="Elo/EloHelper.html" class="link">Elo::EloHelper</a><br />
|
54
|
+
Class <a href="Elo/Game.html" class="link">Elo::Game</a><br />
|
55
|
+
Class <a href="Elo/Player.html" class="link">Elo::Player</a><br />
|
56
|
+
Class <a href="Elo/Rating.html" class="link">Elo::Rating</a><br />
|
57
|
+
</div>
|
58
|
+
</div>
|
59
|
+
</div>
|
60
|
+
</div>
|
61
|
+
<div id='footer-push'></div>
|
62
|
+
</div>
|
63
|
+
<div id='footer'>
|
64
|
+
<a href="http://github.com/mislav/hanna/tree/master"><strong>Hanna</strong> RDoc template</a>
|
65
|
+
</div>
|
66
|
+
</body>
|
67
|
+
</html>
|
@@ -0,0 +1,184 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
2
|
+
<html lang='en'>
|
3
|
+
<head>
|
4
|
+
<title>: Elo::Configuration [elo ]</title>
|
5
|
+
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type'>
|
6
|
+
<link href='../../rdoc-style.css' media='screen' rel='stylesheet' type='text/css'>
|
7
|
+
<script type='text/javascript'>
|
8
|
+
//<![CDATA[
|
9
|
+
function popupCode(url) {
|
10
|
+
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
11
|
+
}
|
12
|
+
|
13
|
+
function toggleCode(id) {
|
14
|
+
var code = document.getElementById(id)
|
15
|
+
|
16
|
+
code.style.display = code.style.display != 'block' ? 'block' : 'none'
|
17
|
+
return true
|
18
|
+
}
|
19
|
+
|
20
|
+
// Make codeblocks hidden by default
|
21
|
+
document.writeln('<' + 'style type="text/css">.method .source pre { display: none }<\/style>')
|
22
|
+
//]]>
|
23
|
+
</script>
|
24
|
+
</head>
|
25
|
+
<body class='page'>
|
26
|
+
<div class='class' id='wrapper'>
|
27
|
+
<div class='header'>
|
28
|
+
<h1 class='name'>
|
29
|
+
<span class='type'>Module</span>
|
30
|
+
Elo::Configuration
|
31
|
+
</h1>
|
32
|
+
<ol class='paths'>
|
33
|
+
<li>
|
34
|
+
<a href="../../files/lib/elo_rb.html">lib/elo.rb</a>
|
35
|
+
</li>
|
36
|
+
</ol>
|
37
|
+
</div>
|
38
|
+
<div id='content'>
|
39
|
+
<div id='text'>
|
40
|
+
<div id='method-list'>
|
41
|
+
<h2>Methods</h2>
|
42
|
+
<h3>public instance</h3>
|
43
|
+
<ol>
|
44
|
+
<li><a href="#M000006">configure</a></li>
|
45
|
+
<li><a href="#M000005">k_factor</a></li>
|
46
|
+
</ol>
|
47
|
+
</div>
|
48
|
+
<div id='section'>
|
49
|
+
<div id='attribute-list'>
|
50
|
+
<h2 class='section-bar'>Attributes</h2>
|
51
|
+
<div class='name-list'>
|
52
|
+
<table>
|
53
|
+
<tr class='top-aligned-row context-row'>
|
54
|
+
<td class='context-item-name'>default_k_factor</td>
|
55
|
+
<td class='context-item-value'>[RW]</td>
|
56
|
+
<td class='context-item-desc'>
|
57
|
+
|
58
|
+
The default k-factor is chosen when no k-factor rules apply. K-factor rules
|
59
|
+
can be added by using the <tt><a
|
60
|
+
href="Configuration.html#M000005">k_factor</a></tt>-method. (default = 15)
|
61
|
+
</td>
|
62
|
+
</tr>
|
63
|
+
<tr class='top-aligned-row context-row'>
|
64
|
+
<td class='context-item-name'>default_rating</td>
|
65
|
+
<td class='context-item-value'>[RW]</td>
|
66
|
+
<td class='context-item-desc'>
|
67
|
+
|
68
|
+
This is the rating every player starts out with. (default = 1000)
|
69
|
+
</td>
|
70
|
+
</tr>
|
71
|
+
<tr class='top-aligned-row context-row'>
|
72
|
+
<td class='context-item-name'>pro_rating_boundry</td>
|
73
|
+
<td class='context-item-value'>[RW]</td>
|
74
|
+
<td class='context-item-desc'>
|
75
|
+
|
76
|
+
This is the lower boundry of the rating you need to be a pro player. This
|
77
|
+
setting is used in the FIDE k-factor rules. (default = 2400)
|
78
|
+
</td>
|
79
|
+
</tr>
|
80
|
+
<tr class='top-aligned-row context-row'>
|
81
|
+
<td class='context-item-name'>starter_boundry</td>
|
82
|
+
<td class='context-item-value'>[RW]</td>
|
83
|
+
<td class='context-item-desc'>
|
84
|
+
|
85
|
+
This is the lower boundry in the amount of games played to be a starting
|
86
|
+
player This setting is used in the FIDE k-factor rules. (default = 30)
|
87
|
+
</td>
|
88
|
+
</tr>
|
89
|
+
<tr class='top-aligned-row context-row'>
|
90
|
+
<td class='context-item-name'>use_FIDE_settings</td>
|
91
|
+
<td class='context-item-value'>[RW]</td>
|
92
|
+
<td class='context-item-desc'>
|
93
|
+
|
94
|
+
Use the settings that FIDE use for determening the K-factor. This is the
|
95
|
+
case when all settings are unaltered. (default = true)
|
96
|
+
|
97
|
+
<p>
|
98
|
+
In short:
|
99
|
+
</p>
|
100
|
+
<ul>
|
101
|
+
<li>K-factor is 25 when a player is a starter (less than 30 games played)
|
102
|
+
|
103
|
+
</li>
|
104
|
+
<li>K-factor is 10 when a player is a pro (rating above 2400, now or in the
|
105
|
+
past)
|
106
|
+
|
107
|
+
</li>
|
108
|
+
<li>K-factor is 15 when a player in other cases
|
109
|
+
|
110
|
+
</li>
|
111
|
+
</ul>
|
112
|
+
<p>
|
113
|
+
If you want to use your own settings, either change the boundry settings,
|
114
|
+
or set this setting to false and add you’re own k-factor rules.
|
115
|
+
K-factor rules can be added by using the <tt><a
|
116
|
+
href="Configuration.html#M000005">k_factor</a></tt>-method.
|
117
|
+
</p>
|
118
|
+
</td>
|
119
|
+
</tr>
|
120
|
+
</table>
|
121
|
+
</div>
|
122
|
+
</div>
|
123
|
+
<div id='methods'>
|
124
|
+
<h2>Public instance methods</h2>
|
125
|
+
<div class='method public-instance' id='method-M000006'>
|
126
|
+
<a name='M000006'></a>
|
127
|
+
<div class='synopsis'>
|
128
|
+
<span class='name'>configure</span>
|
129
|
+
<span class='arguments'>() {|self| ...}</span>
|
130
|
+
</div>
|
131
|
+
<div class='description'>
|
132
|
+
<p>
|
133
|
+
Configure <a href="../Elo.html">Elo</a> in a block style.
|
134
|
+
</p>
|
135
|
+
<pre>Elo.configure do |config|
 config.setting = value
end</pre>
|
136
|
+
</div>
|
137
|
+
<div class='source'>
|
138
|
+
<a class='source-toggle' href='#' onclick="toggleCode('M000006-source'); return false">
|
139
|
+
[show source]
|
140
|
+
</a>
|
141
|
+
<pre id='M000006-source'><span class="ruby-comment cmt"># File lib/elo.rb, line 68</span>
 <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">configure</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
 <span class="ruby-keyword kw">yield</span>(<span class="ruby-keyword kw">self</span>)
 <span class="ruby-keyword kw">end</span></pre>
|
142
|
+
</div>
|
143
|
+
</div>
|
144
|
+
<div class='method public-instance' id='method-M000005'>
|
145
|
+
<a name='M000005'></a>
|
146
|
+
<div class='synopsis'>
|
147
|
+
<span class='name'>k_factor</span>
|
148
|
+
<span class='arguments'>(factor, &rule)</span>
|
149
|
+
</div>
|
150
|
+
<div class='description'>
|
151
|
+
<p>
|
152
|
+
Add a K-factor rule. The first argument is the k-factor value. The block
|
153
|
+
should return a boolean that determines if this K-factor rule applies. The
|
154
|
+
first rule that applies is the one determining the K-factor.
|
155
|
+
</p>
|
156
|
+
<p>
|
157
|
+
The block is instance_eval‘ed into the player, so you can access all
|
158
|
+
it’s properties directly. The K-factor is recalculated every time a
|
159
|
+
match is played.
|
160
|
+
</p>
|
161
|
+
<p>
|
162
|
+
By default, the FIDE settings are used (see: <tt>use_FIDE_settings</tt>).
|
163
|
+
To implement that yourself, you could write:
|
164
|
+
</p>
|
165
|
+
<pre>Elo.configure do |config|
 config.k_factor(10) { pro? or pro_rating? }
 config.k_factor(25) { starter? }
 config.default_k_factor = 15
end</pre>
|
166
|
+
</div>
|
167
|
+
<div class='source'>
|
168
|
+
<a class='source-toggle' href='#' onclick="toggleCode('M000005-source'); return false">
|
169
|
+
[show source]
|
170
|
+
</a>
|
171
|
+
<pre id='M000005-source'><span class="ruby-comment cmt"># File lib/elo.rb, line 30</span>
 <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">k_factor</span>(<span class="ruby-identifier">factor</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">rule</span>)
 <span class="ruby-identifier">k_factors</span> <span class="ruby-operator"><<</span> { <span class="ruby-identifier">:factor</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">factor</span>, <span class="ruby-identifier">:rule</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">rule</span> }
 <span class="ruby-keyword kw">end</span></pre>
|
172
|
+
</div>
|
173
|
+
</div>
|
174
|
+
</div>
|
175
|
+
</div>
|
176
|
+
</div>
|
177
|
+
</div>
|
178
|
+
<div id='footer-push'></div>
|
179
|
+
</div>
|
180
|
+
<div id='footer'>
|
181
|
+
<a href="http://github.com/mislav/hanna/tree/master"><strong>Hanna</strong> RDoc template</a>
|
182
|
+
</div>
|
183
|
+
</body>
|
184
|
+
</html>
|