From c67559efbd39a67c0f9667dea9cbf3d3e3d8b6dd Mon Sep 17 00:00:00 2001 From: Michael Gall Date: Tue, 10 Apr 2012 21:57:22 +1000 Subject: [PATCH] Fixing problem with rating change not being equal --- lib/elo/rating.rb | 2 +- spec/elo_spec.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/elo/rating.rb b/lib/elo/rating.rb index 0b954b4..daa18a4 100644 --- a/lib/elo/rating.rb +++ b/lib/elo/rating.rb @@ -50,7 +50,7 @@ def expected # For more information visit # {Wikipedia}[http://en.wikipedia.org/wiki/Elo_rating_system#Mathematical_details] def change - k_factor.to_f * ( result.to_f - expected ) + (k_factor.to_f * ( result.to_i - expected )).to_i end diff --git a/spec/elo_spec.rb b/spec/elo_spec.rb index 2101fd9..267b70c 100644 --- a/spec/elo_spec.rb +++ b/spec/elo_spec.rb @@ -41,6 +41,16 @@ end + #from Wikipedia: The winner of a contest between two players gains a certain number of points in his rating and the losing player loses the same amount. + it "rating change should be the same" do + bob = Elo::Player.new :rating => 1000 + jane = Elo::Player.new :rating => 1000 + + game1 = bob.wins_from(jane) + + (1000 - jane.rating).should == (bob.rating - 1000) + end + describe "Configuration" do it "default_rating" do