Class: ICU::RatedPlayer::FullRating

Inherits:
ICU::RatedPlayer show all
Defined in:
lib/icu_ratings/player.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Attributes inherited from ICU::RatedPlayer

#desc, #num, #performance, #results, #type

Instance Method Summary collapse

Methods inherited from ICU::RatedPlayer

#==, #add_result, #average_performance, check_games, check_kfactor, check_num, check_rating, #estimate_performance, #expected_score, factory, kfactor, #rate!, #score, #update_performance

Constructor Details

#initialize(num, desc, rating, kfactor) ⇒ FullRating

Returns a new instance of FullRating.



231
232
233
234
235
236
237
# File 'lib/icu_ratings/player.rb', line 231

def initialize(num, desc, rating, kfactor)
  @type = :rated
  @rating = rating
  @kfactor = kfactor
  @bonus = 0
  super(num, desc)
end

Instance Attribute Details

#bonusObject (readonly)

Returns the value of attribute bonus.



229
230
231
# File 'lib/icu_ratings/player.rb', line 229

def bonus
  @bonus
end

#kfactorObject (readonly)

Returns the value of attribute kfactor.



229
230
231
# File 'lib/icu_ratings/player.rb', line 229

def kfactor
  @kfactor
end

#pb_performanceObject (readonly)

Returns the value of attribute pb_performance.



229
230
231
# File 'lib/icu_ratings/player.rb', line 229

def pb_performance
  @pb_performance
end

#pb_ratingObject (readonly)

Returns the value of attribute pb_rating.



229
230
231
# File 'lib/icu_ratings/player.rb', line 229

def pb_rating
  @pb_rating
end

#ratingObject (readonly)

Returns the value of attribute rating.



229
230
231
# File 'lib/icu_ratings/player.rb', line 229

def rating
  @rating
end

Instance Method Details

#calculate_bonusObject



262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
# File 'lib/icu_ratings/player.rb', line 262

def calculate_bonus
  return if @kfactor <= 24 || @results.size <= 4 || @rating >= 2100
  change = rating_change
  # Remember the key inputs to the calculation
  @pb_rating = (@rating + change).round
  @pb_performance = @performance.round
  # Calculate the bonus.
  return if change <= 35 || @rating + change >= 2100
  threshold = 32 + 3 * (@results.size - 4)
  bonus = (change - threshold).round
  return if bonus <= 0
  bonus = (1.25 * bonus).round if kfactor >= 40
  # Determine if it should be capped or not.
  [2100, @performance].each { |max| bonus = (max - @rating - change).round if @rating + change + bonus >= max }
  return if bonus <= 0
  # Store the value.
  @bonus_rating = @rating + change + bonus
  @bonus = bonus
end

#new_rating(type = nil) ⇒ Object



251
252
253
254
255
256
257
258
259
260
# File 'lib/icu_ratings/player.rb', line 251

def new_rating(type=nil)
  case type
  when :start
    @rating                          # the player's start rating
  when :opponent
    @bonus_rating || @rating         # the rating used for opponents during the calculations
  else
    @rating + rating_change + @bonus # the player's final rating
  end
end

#rating_changeObject



247
248
249
# File 'lib/icu_ratings/player.rb', line 247

def rating_change
  @results.inject(0.0) { |c, r| c + (r.rating_change || 0.0) }
end

#resetObject



239
240
241
242
243
244
245
# File 'lib/icu_ratings/player.rb', line 239

def reset
  @pb_rating = nil
  @pb_performance = nil
  @bonus_rating = nil
  @bonus = 0
  super
end

#update_bonusObject



282
283
284
# File 'lib/icu_ratings/player.rb', line 282

def update_bonus
  @bonus_rating = @rating + @bonus + rating_change if @bonus_rating
end