elo 0.0.3.alpha → 0.1.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.
- data/README.rdoc +6 -4
- data/VERSION +1 -1
- data/elo.gemspec +3 -3
- data/lib/elo/game.rb +14 -4
- data/lib/elo/player.rb +12 -8
- data/spec/elo_spec.rb +7 -5
- metadata +7 -10
data/README.rdoc
CHANGED
@@ -43,18 +43,20 @@ There is more than one way to do it, choose whatever works from your other code:
|
|
43
43
|
game7 = bob.versus(jane)
|
44
44
|
game7.result = 1 # result is in perspective of bob, so bob wins
|
45
45
|
|
46
|
+
game8 = bob.versus(jane, :result => 0) # jane wins
|
47
|
+
|
46
48
|
You can get all kinds of info from a player:
|
47
49
|
|
48
|
-
bob.rating # =>
|
50
|
+
bob.rating # => 1080
|
49
51
|
bob.pro? # => false
|
50
52
|
bob.starter? # => true
|
51
|
-
bob.games_played # =>
|
52
|
-
bob.games # => [ game1, game2, ...
|
53
|
+
bob.games_played # => 8
|
54
|
+
bob.games # => [ game1, game2, ... game8 ]
|
53
55
|
|
54
56
|
Or get a list of players:
|
55
57
|
|
56
58
|
Elo::Player.all # => [ bob, jane ]
|
57
|
-
Elo::Game.all # => [ game1, game2, ...
|
59
|
+
Elo::Game.all # => [ game1, game2, ... game8 ]
|
58
60
|
|
59
61
|
|
60
62
|
== Configuration
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/elo.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{elo}
|
8
|
-
s.version = "0.0
|
8
|
+
s.version = "0.1.0"
|
9
9
|
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new("
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Iain Hecker"]
|
12
|
-
s.date = %q{2010-03-
|
12
|
+
s.date = %q{2010-03-18}
|
13
13
|
s.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.}
|
14
14
|
s.email = %q{iain@iain.nl}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/elo/game.rb
CHANGED
@@ -23,13 +23,19 @@ module Elo
|
|
23
23
|
# objects to update their scores.
|
24
24
|
def process_result(result)
|
25
25
|
@result = result
|
26
|
-
|
27
|
-
two.send(:played, self)
|
28
|
-
save
|
29
|
-
self
|
26
|
+
calculate
|
30
27
|
end
|
31
28
|
alias result= process_result
|
32
29
|
|
30
|
+
def calculate
|
31
|
+
if result
|
32
|
+
one.send(:played, self)
|
33
|
+
two.send(:played, self)
|
34
|
+
save
|
35
|
+
end
|
36
|
+
self
|
37
|
+
end
|
38
|
+
|
33
39
|
# Player +:one+ has won!
|
34
40
|
# This is a shortcut method for setting the score to 1
|
35
41
|
def win
|
@@ -69,6 +75,10 @@ module Elo
|
|
69
75
|
@ratings ||= { one => rating_one, two => rating_two }
|
70
76
|
end
|
71
77
|
|
78
|
+
def inspect
|
79
|
+
"game"
|
80
|
+
end
|
81
|
+
|
72
82
|
private
|
73
83
|
|
74
84
|
# Create an Elo::Rating object for player one
|
data/lib/elo/player.rb
CHANGED
@@ -68,26 +68,30 @@ module Elo
|
|
68
68
|
|
69
69
|
# Start a game with another player. At this point, no
|
70
70
|
# result is known and nothing really happens.
|
71
|
-
def versus(other_player)
|
72
|
-
Game.new(:one => self, :two => other_player)
|
71
|
+
def versus(other_player, options = {})
|
72
|
+
Game.new(options.merge(:one => self, :two => other_player)).calculate
|
73
73
|
end
|
74
74
|
|
75
75
|
# Start a game with another player and set the score
|
76
76
|
# immediately.
|
77
|
-
def wins_from(other_player)
|
78
|
-
versus(other_player).win
|
77
|
+
def wins_from(other_player, options = {})
|
78
|
+
versus(other_player, options).win
|
79
79
|
end
|
80
80
|
|
81
81
|
# Start a game with another player and set the score
|
82
82
|
# immediately.
|
83
|
-
def plays_draw(other_player)
|
84
|
-
versus(other_player).draw
|
83
|
+
def plays_draw(other_player, options = {})
|
84
|
+
versus(other_player, options).draw
|
85
85
|
end
|
86
86
|
|
87
87
|
# Start a game with another player and set the score
|
88
88
|
# immediately.
|
89
|
-
def loses_from(other_player)
|
90
|
-
versus(other_player).lose
|
89
|
+
def loses_from(other_player, options = {})
|
90
|
+
versus(other_player, options).lose
|
91
|
+
end
|
92
|
+
|
93
|
+
def inspect
|
94
|
+
"player"
|
91
95
|
end
|
92
96
|
|
93
97
|
private
|
data/spec/elo_spec.rb
CHANGED
@@ -27,15 +27,17 @@ describe "Elo" do
|
|
27
27
|
game7 = bob.versus(jane)
|
28
28
|
game7.result = 1
|
29
29
|
|
30
|
-
bob.
|
31
|
-
|
30
|
+
game8 = bob.versus(jane, :result => 0)
|
31
|
+
|
32
|
+
bob.rating.should == 1080
|
33
|
+
jane.rating.should == 1412
|
32
34
|
bob.should_not be_pro
|
33
35
|
bob.should be_starter
|
34
|
-
bob.games_played.should ==
|
35
|
-
bob.games.should == [ game1, game2, game3, game4, game5, game6, game7 ]
|
36
|
+
bob.games_played.should == 8
|
37
|
+
bob.games.should == [ game1, game2, game3, game4, game5, game6, game7, game8 ]
|
36
38
|
|
37
39
|
Elo::Player.all.should == [ bob, jane ]
|
38
|
-
Elo::Game.all.should == [ game1, game2, game3, game4, game5, game6, game7 ]
|
40
|
+
Elo::Game.all.should == [ game1, game2, game3, game4, game5, game6, game7, game8 ]
|
39
41
|
|
40
42
|
end
|
41
43
|
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
4
|
+
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
+
- 1
|
7
8
|
- 0
|
8
|
-
|
9
|
-
- alpha
|
10
|
-
version: 0.0.3.alpha
|
9
|
+
version: 0.1.0
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Iain Hecker
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2010-03-
|
17
|
+
date: 2010-03-18 00:00:00 +01:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
@@ -89,13 +88,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
89
88
|
version: "0"
|
90
89
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
90
|
requirements:
|
92
|
-
- - "
|
91
|
+
- - ">="
|
93
92
|
- !ruby/object:Gem::Version
|
94
93
|
segments:
|
95
|
-
-
|
96
|
-
|
97
|
-
- 1
|
98
|
-
version: 1.3.1
|
94
|
+
- 0
|
95
|
+
version: "0"
|
99
96
|
requirements: []
|
100
97
|
|
101
98
|
rubyforge_project:
|