class EloManager
Attributes
k_factor[RW]
Public Class Methods
new()
click to toggle source
# File lib/multiplayer_elo/elo_manager.rb, line 4 def initialize @k_factor = 20 end
Public Instance Methods
evaulate_results(results)
click to toggle source
# File lib/multiplayer_elo/elo_manager.rb, line 17 def evaulate_results(results) results.each do |i| elo_change = 0 results.each do |j| next if i == j # we are using places so first place < 2nd place means a win if i[:place] > j[:place] winner = 0 elsif i[:place] == j[:place] winner = 0.5 else winner = 1 end elo_change += points_change(i[:elo], j[:elo], winner) end i[:new_elo] = i[:elo] + elo_change end end
expected_percentage(elo1, elo2)
click to toggle source
# File lib/multiplayer_elo/elo_manager.rb, line 8 def expected_percentage(elo1, elo2) 1.0 / ( 1.0 + ( 10.0 ** ((elo2.to_f - elo1.to_f) / 400.0) ) ) end
points_change(elo1, elo2, result)
click to toggle source
result is 0 for a loss 1 for a win or .5 for a tie
# File lib/multiplayer_elo/elo_manager.rb, line 13 def points_change(elo1, elo2, result) (@k_factor.to_f * (result.to_f - expected_percentage(elo1, elo2))).round end