68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/acts_as_elo/acts/elo.rb', line 68
def elo_update(opponent, opts={})
begin
if self.class.respond_to?(:acts_as_elo_options) && self.class.acts_as_elo_options[:one_way]
one_way = true
end
one_way ||= opts[:one_way]
send_opts = {one_way: true}
diff = opponent.elo_rank.to_f - elo_rank.to_f
expected = 1 / (1 + 10 ** (diff / 400))
coefficient = elo_proficiency_map[:coefficients][1]
if elo_rank < elo_proficiency_map[:rank_limits].first
coefficient = elo_proficiency_map[:coefficients].first
end
if elo_rank > elo_proficiency_map[:rank_limits].last
coefficient = elo_proficiency_map[:coefficients].last
end
if opts[:result] == :win
points = 1
send_opts.merge!(result: :lose)
elsif opts[:result] == :lose
points = 0
send_opts.merge!(result: :win)
elsif opts[:result] == :draw
points = 0.5
send_opts.merge!(result: :draw)
end
opponent.elo_update(self, send_opts) unless one_way
self.elo_rank = (elo_rank + coefficient*(points-expected)).round
rescue Exception => e
puts "Exception: #{e.message}"
end
end
|