update() now handled case correctly when a player hasn't participated in a session

* when a player has no results, deviation is slightly increased properly now
This commit is contained in:
swaits committed 2011-12-19 15:10:38 -08:00
1 parent 723952b178
commit b240814147
2 files changed
+16 -15

No files matched your search

+13 -12
View File
@@ -1,4 +1,4 @@
#!/usr/bin/env ruby
#!/usr/bin/env ruby -w
#
#
@@ -136,22 +136,23 @@ class Glicko2
add_result(opponent,Glicko2::DRAW)
end
# util func
def Glicko2.g(deviation)
1.0 / (Math.sqrt(1.0 + 3.0 * deviation ** 2.0 / (Math::PI ** 2.0)))
end
# util func
def Glicko2.E(rating, rating_opponent, deviation_opponent)
1.0 / (1.0 + Math.exp(-Glicko2.g(deviation_opponent)*(rating - rating_opponent)));
end
# Update rating based on current results list, and clear results.
def update
# util func
def Glicko2.g(deviation)
1.0 / (Math.sqrt(1.0 + 3.0 * deviation ** 2.0 / (Math::PI ** 2.0)))
end
# util func
def Glicko2.E(rating, rating_opponent, deviation_opponent)
1.0 / (1.0 + Math.exp(-Glicko2.g(deviation_opponent)*(rating - rating_opponent)));
end
# bail if no opponents set
if @results.empty?
return nil
@g2deviation = Math.sqrt(@g2deviation**2.0 + @g2volatility**2.0)
return
end
# compute variance
+3 -3
View File
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
#!/usr/bin/env ruby -w
require 'glicko2'
require_relative 'glicko2'
require 'test/unit'
class TestGlicko2 < Test::Unit::TestCase
@@ -26,7 +26,7 @@ class TestGlicko2 < Test::Unit::TestCase
a.update()
assert_in_delta(1464.05,a.rating,0.01)
assert_in_delta(151.516,a.deviation,0.01)
assert_in_delta(151.875,a.deviation,0.01)
end