elo-ratings 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,9 +13,13 @@ It is bundled under the ext directory of this project
13
13
  = EloRatings
14
14
 
15
15
  The goal of this gem was to provide a simple interface to Bayeselo in ruby.
16
+ Advantage is set to zero (no advan advantage modifier to player 1)
16
17
  There has currently been no attempt to reproduce all functionality provided by Bayeselo.
17
18
 
18
19
 
20
+ Only tested in ruby 1.9.1
21
+ Ruby 1.9.2 throws some form of bus error at end of execution.
22
+
19
23
  == Copyright
20
24
 
21
25
  Copyright (c) 2010 phillc. See LICENSE.txt for
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.0.1
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{elo-ratings}
8
- s.version = "0.0.0"
8
+ s.version = "0.0.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["phillc"]
@@ -79,6 +79,7 @@ Gem::Specification.new do |s|
79
79
  "ext/bayeselo/date.h",
80
80
  "ext/bayeselo/debug.h",
81
81
  "ext/bayeselo/elomain.cpp",
82
+ "ext/bayeselo/eloratings.cpp",
82
83
  "ext/bayeselo/extconf.rb",
83
84
  "ext/bayeselo/list.h",
84
85
  "ext/bayeselo/listi.h",
@@ -93,7 +94,6 @@ Gem::Specification.new do |s|
93
94
  "ext/bayeselo/position.h",
94
95
  "ext/bayeselo/random.cpp",
95
96
  "ext/bayeselo/random.h",
96
- "ext/bayeselo/rb_bayeselo.cpp",
97
97
  "ext/bayeselo/readstr.cpp",
98
98
  "ext/bayeselo/readstr.h",
99
99
  "ext/bayeselo/square.h",
@@ -102,11 +102,11 @@ Gem::Specification.new do |s|
102
102
  "ext/bayeselo/version.cpp",
103
103
  "ext/bayeselo/version.h",
104
104
  "ext/bayeselo/version_number.h",
105
- "lib/bayeselo.rb",
106
- "lib/bayeselo/bayeselo.rb",
107
- "lib/bayeselo/c_bayeselo.rb",
108
- "test/bayeselo/test_bayeselo.rb",
109
- "test/bayeselo/test_c_bayeselo.rb",
105
+ "lib/elo_ratings.rb",
106
+ "lib/elo_ratings/c_bayeselo.rb",
107
+ "lib/elo_ratings/results.rb",
108
+ "test/elo_ratings/test_c_bayeselo.rb",
109
+ "test/elo_ratings/test_results.rb",
110
110
  "test/helper.rb"
111
111
  ]
112
112
  s.homepage = %q{http://github.com/phillc/elo-ratings}
@@ -115,8 +115,8 @@ Gem::Specification.new do |s|
115
115
  s.rubygems_version = %q{1.3.7}
116
116
  s.summary = %q{Ruby wrapper for bayeselo}
117
117
  s.test_files = [
118
- "test/bayeselo/test_bayeselo.rb",
119
- "test/bayeselo/test_c_bayeselo.rb",
118
+ "test/elo_ratings/test_c_bayeselo.rb",
119
+ "test/elo_ratings/test_results.rb",
120
120
  "test/helper.rb"
121
121
  ]
122
122
 
@@ -62,12 +62,12 @@ float CBayeselo::CountGames(int i) {
62
62
  }
63
63
 
64
64
  extern "C"
65
- void Init_bayeselo()
65
+ void Init_elo_ratings()
66
66
  {
67
- Rice::Module mBayeselo = define_module("Bayeselo");
67
+ Rice::Module mEloRatings = define_module("EloRatings");
68
68
 
69
69
  Data_Type<CBayeselo> c_bayeselo =
70
- define_class_under<CBayeselo>(mBayeselo, "CBayeselo")
70
+ define_class_under<CBayeselo>(mEloRatings, "CBayeselo")
71
71
  .define_constructor(Constructor<CBayeselo>())
72
72
  .define_method("get_players", &CBayeselo::GetPlayers)
73
73
  .define_method("append", &CBayeselo::Append)
@@ -1,6 +1,6 @@
1
1
  require 'mkmf-rice'
2
2
 
3
- extension_name = 'bayeselo'
4
- have_library("stdc++")
5
- dir_config(extension_name)
3
+ extension_name = 'elo_ratings'
4
+ # have_library("stdc++")
5
+ # dir_config(extension_name)
6
6
  create_makefile(extension_name)
@@ -0,0 +1,9 @@
1
+ Dir[File.dirname(__FILE__) + '/elo_ratings/*.rb'].each {|file| require file }
2
+
3
+ require File.dirname(__FILE__) + '/../ext/bayeselo/elo_ratings'
4
+
5
+ module EloRatings
6
+ Draw = 1
7
+ Player1Win = 2
8
+ Player2Win = 0
9
+ end
@@ -0,0 +1,5 @@
1
+ module EloRatings
2
+ class CBayeselo
3
+ # methods provided by rb_bayeselo.cpp
4
+ end
5
+ end
@@ -0,0 +1,41 @@
1
+ module EloRatings
2
+ class Results
3
+ def initialize
4
+ @c_bayeselo = CBayeselo.new
5
+ @players = []
6
+ end
7
+
8
+ def add_game player_1, player_2, result
9
+ @c_bayeselo.append index_for!(player_1), index_for!(player_2), result
10
+ end
11
+
12
+ def count_games_for player
13
+ return 0 if !exists? player
14
+ @c_bayeselo.count_games index_for(player)
15
+ end
16
+
17
+ def elo_for player
18
+ return nil if !exists? player
19
+ @c_bayeselo.get_elo index_for(player)
20
+ end
21
+
22
+ protected
23
+
24
+ def exists? player
25
+ !!index_for(player)
26
+ end
27
+
28
+ def index_for player
29
+ @players.index player
30
+ end
31
+
32
+ def index_for! player
33
+ index = index_for player
34
+ if index.nil?
35
+ index = @players.length
36
+ @players << player
37
+ end
38
+ index
39
+ end
40
+ end
41
+ end
@@ -3,13 +3,13 @@ require 'helper'
3
3
  class TestCBayeselo < Test::Unit::TestCase
4
4
  context "append" do
5
5
  should "add the players" do
6
- cbayeselo = Bayeselo::CBayeselo.new
6
+ cbayeselo = CBayeselo.new
7
7
 
8
- cbayeselo.append 0, 1, CBayeselo::Player2
8
+ cbayeselo.append 0, 1, Player2Win
9
9
  assert_equal 2, cbayeselo.get_players
10
- cbayeselo.append 1, 2, CBayeselo::Player2
10
+ cbayeselo.append 1, 2, Player2Win
11
11
  assert_equal 3, cbayeselo.get_players
12
- cbayeselo.append 3, 4, CBayeselo::Player2
12
+ cbayeselo.append 3, 4, Player2Win
13
13
  assert_equal 5, cbayeselo.get_players
14
14
  assert_equal 1, cbayeselo.count_games(0)
15
15
  assert_equal 2, cbayeselo.count_games(1)
@@ -18,14 +18,14 @@ class TestCBayeselo < Test::Unit::TestCase
18
18
  end
19
19
 
20
20
  should "not be global" do
21
- cbayeselo1 = Bayeselo::CBayeselo.new
22
- cbayeselo2 = Bayeselo::CBayeselo.new
21
+ cbayeselo1 = CBayeselo.new
22
+ cbayeselo2 = CBayeselo.new
23
23
 
24
- cbayeselo1.append 0, 1, CBayeselo::Player2
24
+ cbayeselo1.append 0, 1, Player2Win
25
25
  assert_equal 2, cbayeselo1.get_players
26
- cbayeselo1.append 1, 2, CBayeselo::Player2
26
+ cbayeselo1.append 1, 2, Player2Win
27
27
  assert_equal 3, cbayeselo1.get_players
28
- cbayeselo1.append 3, 4, CBayeselo::Player2
28
+ cbayeselo1.append 3, 4, Player2Win
29
29
  assert_equal 5, cbayeselo1.get_players
30
30
  assert_equal 1, cbayeselo1.count_games(0)
31
31
  assert_equal 2, cbayeselo1.count_games(1)
@@ -54,9 +54,9 @@ class TestCBayeselo < Test::Unit::TestCase
54
54
  # 3 a -5 268 268 1 50% 5 100%
55
55
  # 4 c -5 268 268 1 50% 5 100%
56
56
 
57
- cbayeselo = Bayeselo::CBayeselo.new
58
- cbayeselo.append 0, 1, CBayeselo::Draw
59
- cbayeselo.append 2, 3, CBayeselo::Draw
57
+ cbayeselo = CBayeselo.new
58
+ cbayeselo.append 0, 1, Draw
59
+ cbayeselo.append 2, 3, Draw
60
60
  assert_equal -5, cbayeselo.get_elo(0)
61
61
  assert_equal 5, cbayeselo.get_elo(1)
62
62
  assert_equal -5, cbayeselo.get_elo(2)
@@ -66,11 +66,11 @@ class TestCBayeselo < Test::Unit::TestCase
66
66
 
67
67
  context "count_games" do
68
68
  should "return the number of games a player played" do
69
- cbayeselo = Bayeselo::CBayeselo.new
70
- cbayeselo.append 0, 1, CBayeselo::Player2
71
- cbayeselo.append 2, 3, CBayeselo::Player2
72
- cbayeselo.append 2, 0, CBayeselo::Player2
73
- cbayeselo.append 11, 12, CBayeselo::Player2
69
+ cbayeselo = CBayeselo.new
70
+ cbayeselo.append 0, 1, Player2Win
71
+ cbayeselo.append 2, 3, Player2Win
72
+ cbayeselo.append 2, 0, Player2Win
73
+ cbayeselo.append 11, 12, Player2Win
74
74
  assert_equal 2, cbayeselo.count_games(0)
75
75
  assert_equal 1, cbayeselo.count_games(1)
76
76
  assert_equal 2, cbayeselo.count_games(2)
@@ -0,0 +1,41 @@
1
+ require 'helper'
2
+
3
+ class TestResults < Test::Unit::TestCase
4
+ context "add_game" do
5
+ should "accept the winner and loser and add a game to EloRatings" do
6
+ results = Results.new
7
+ results.add_game "a", 3, Player1Win
8
+ assert_equal 1, results.count_games_for("a")
9
+ assert_equal 1, results.count_games_for(3)
10
+ end
11
+
12
+ should "record games for the same player" do
13
+ results = Results.new
14
+ results.add_game "a", "f", Player1Win
15
+ results.add_game "e", "a", Player1Win
16
+ results.add_game "k", "a", Player2Win
17
+ results.add_game "a", 1, Player2Win
18
+ assert_equal 4, results.count_games_for("a")
19
+ end
20
+ end
21
+
22
+ context "count_games_for" do
23
+ should "return zero for a player that hasn't been added to a game yet" do
24
+ results = Results.new
25
+ assert_equal 0, results.count_games_for("a")
26
+ end
27
+ end
28
+
29
+ context "elo_for" do
30
+ should "have exact opposite elo for two players" do
31
+ results = Results.new
32
+ results.add_game "a", "b", Player1Win
33
+ assert_equal results.elo_for("b"), results.elo_for("a") * -1
34
+ end
35
+
36
+ should "return nil for for a player that hasn't been recorded yet" do
37
+ results = Results.new
38
+ assert_equal nil, results.elo_for("a")
39
+ end
40
+ end
41
+ end
@@ -12,7 +12,8 @@ require 'shoulda'
12
12
 
13
13
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
14
  $LOAD_PATH.unshift(File.dirname(__FILE__))
15
- require 'bayeselo'
15
+ require 'elo_ratings'
16
16
 
17
17
  class Test::Unit::TestCase
18
+ include EloRatings
18
19
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elo-ratings
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 29
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 0
8
- - 0
9
- version: 0.0.0
9
+ - 1
10
+ version: 0.0.1
10
11
  platform: ruby
11
12
  authors:
12
13
  - phillc
@@ -24,6 +25,7 @@ dependencies:
24
25
  requirements:
25
26
  - - ">="
26
27
  - !ruby/object:Gem::Version
28
+ hash: 3
27
29
  segments:
28
30
  - 0
29
31
  version: "0"
@@ -37,6 +39,7 @@ dependencies:
37
39
  requirements:
38
40
  - - ~>
39
41
  - !ruby/object:Gem::Version
42
+ hash: 23
40
43
  segments:
41
44
  - 1
42
45
  - 0
@@ -52,6 +55,7 @@ dependencies:
52
55
  requirements:
53
56
  - - ~>
54
57
  - !ruby/object:Gem::Version
58
+ hash: 7
55
59
  segments:
56
60
  - 1
57
61
  - 5
@@ -67,6 +71,7 @@ dependencies:
67
71
  requirements:
68
72
  - - ">="
69
73
  - !ruby/object:Gem::Version
74
+ hash: 3
70
75
  segments:
71
76
  - 0
72
77
  version: "0"
@@ -80,6 +85,7 @@ dependencies:
80
85
  requirements:
81
86
  - - ">="
82
87
  - !ruby/object:Gem::Version
88
+ hash: 3
83
89
  segments:
84
90
  - 0
85
91
  version: "0"
@@ -158,6 +164,7 @@ files:
158
164
  - ext/bayeselo/date.h
159
165
  - ext/bayeselo/debug.h
160
166
  - ext/bayeselo/elomain.cpp
167
+ - ext/bayeselo/eloratings.cpp
161
168
  - ext/bayeselo/extconf.rb
162
169
  - ext/bayeselo/list.h
163
170
  - ext/bayeselo/listi.h
@@ -172,7 +179,6 @@ files:
172
179
  - ext/bayeselo/position.h
173
180
  - ext/bayeselo/random.cpp
174
181
  - ext/bayeselo/random.h
175
- - ext/bayeselo/rb_bayeselo.cpp
176
182
  - ext/bayeselo/readstr.cpp
177
183
  - ext/bayeselo/readstr.h
178
184
  - ext/bayeselo/square.h
@@ -181,11 +187,11 @@ files:
181
187
  - ext/bayeselo/version.cpp
182
188
  - ext/bayeselo/version.h
183
189
  - ext/bayeselo/version_number.h
184
- - lib/bayeselo.rb
185
- - lib/bayeselo/bayeselo.rb
186
- - lib/bayeselo/c_bayeselo.rb
187
- - test/bayeselo/test_bayeselo.rb
188
- - test/bayeselo/test_c_bayeselo.rb
190
+ - lib/elo_ratings.rb
191
+ - lib/elo_ratings/c_bayeselo.rb
192
+ - lib/elo_ratings/results.rb
193
+ - test/elo_ratings/test_c_bayeselo.rb
194
+ - test/elo_ratings/test_results.rb
189
195
  - test/helper.rb
190
196
  has_rdoc: true
191
197
  homepage: http://github.com/phillc/elo-ratings
@@ -201,7 +207,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
201
207
  requirements:
202
208
  - - ">="
203
209
  - !ruby/object:Gem::Version
204
- hash: 87263453
210
+ hash: 3
205
211
  segments:
206
212
  - 0
207
213
  version: "0"
@@ -210,6 +216,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
210
216
  requirements:
211
217
  - - ">="
212
218
  - !ruby/object:Gem::Version
219
+ hash: 3
213
220
  segments:
214
221
  - 0
215
222
  version: "0"
@@ -221,6 +228,6 @@ signing_key:
221
228
  specification_version: 3
222
229
  summary: Ruby wrapper for bayeselo
223
230
  test_files:
224
- - test/bayeselo/test_bayeselo.rb
225
- - test/bayeselo/test_c_bayeselo.rb
231
+ - test/elo_ratings/test_c_bayeselo.rb
232
+ - test/elo_ratings/test_results.rb
226
233
  - test/helper.rb
@@ -1,6 +0,0 @@
1
- Dir[File.dirname(__FILE__) + '/bayeselo/*.rb'].each {|file| require file }
2
-
3
- require File.dirname(__FILE__) + '/../ext/bayeselo/bayeselo'
4
-
5
- module Bayeselo
6
- end
@@ -1,11 +0,0 @@
1
- class Bayeselo
2
- def initialize
3
- @c_bayeselo = CBayeselo.new
4
- @players = []
5
- end
6
-
7
- def add_game players={}
8
- players[:winner]
9
- players[:loser]
10
- end
11
- end
@@ -1,7 +0,0 @@
1
- class CBayeselo
2
- Draw = 1
3
- Player1 = 2
4
- Player2 = 0
5
-
6
- # methods provided by rb_bayeselo.cpp
7
- end
@@ -1,33 +0,0 @@
1
- require 'helper'
2
-
3
- class TestBayeselo < Test::Unit::TestCase
4
- context "add_game" do
5
- should "accept the winner and loser and add a game to bayeselo" do
6
- bayeselo = Bayeselo.new
7
- bayeselo.add_game :winner => "a", :loser => "b"
8
- assert_equal 1, bayeselo.count_games("a")
9
- assert_equal 1, bayeselo.count_games("b")
10
- end
11
-
12
- should "record games for the same player" do
13
- bayeselo = Bayeselo.new
14
- bayeselo.add_game :winner => "a", :loser => "f"
15
- bayeselo.add_game :winner => "e", :loser => "a"
16
- bayeselo.add_game :winner => "a", :loser => "k"
17
- assert_equal 3, bayeselo.count_games("a")
18
- end
19
- end
20
-
21
- context "get_elo" do
22
- should "have exact opposite elo for two players" do
23
- bayeselo = Bayeselo.new
24
- bayeselo.add_game :winner => "a", :loser => "b"
25
- assert_equal bayeselo.get_elo("b"), -bayeselo.get_elo("a")
26
- end
27
-
28
- should "return nil for for a player that hasn't been recorded yet" do
29
- bayeselo = Bayeselo.new
30
- assert_equal nil, bayeselo.get_elo("a")
31
- end
32
- end
33
- end