Class: Elo::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/elo/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

:nodoc:



34
35
36
37
38
39
40
# File 'lib/elo/configuration.rb', line 34

def initialize #:nodoc:
  @pro_rating_boundry = 2400
  @starter_boundry    = 30
  @default_rating     = 1000
  @default_k_factor   = 15
  @use_FIDE_settings  = true
end

Instance Attribute Details

#default_k_factorObject

The default k-factor is chosen when no k-factor rules apply. K-factor rules can be added by using the k_factor-method. (default = 15)



15
16
17
# File 'lib/elo/configuration.rb', line 15

def default_k_factor
  @default_k_factor
end

#default_ratingObject

This is the rating every player starts out with. (default = 1000)



18
19
20
# File 'lib/elo/configuration.rb', line 18

def default_rating
  @default_rating
end

#pro_rating_boundryObject

This is the lower boundry of the rating you need to be a pro player. This setting is used in the FIDE k-factor rules. (default = 2400)



7
8
9
# File 'lib/elo/configuration.rb', line 7

def pro_rating_boundry
  @pro_rating_boundry
end

#starter_boundryObject

This is the lower boundry in the amount of games played to be a starting player This setting is used in the FIDE k-factor rules. (default = 30)



11
12
13
# File 'lib/elo/configuration.rb', line 11

def starter_boundry
  @starter_boundry
end

#use_FIDE_settingsObject

Use the settings that FIDE use for determening the K-factor. This is the case when all settings are unaltered. (default = true)

In short:

  • K-factor is 25 when a player is a starter (less than 30 games played)

  • K-factor is 10 when a player is a pro (rating above 2400, now or in the past)

  • K-factor is 15 when a player in other cases

If you want to use your own settings, either change the boundry settings, or set this setting to false and add you’re own k-factor rules. K-factor rules can be added by using the k_factor-method.



32
33
34
# File 'lib/elo/configuration.rb', line 32

def use_FIDE_settings
  @use_FIDE_settings
end

Instance Method Details

#applied_k_factorsObject

:nodoc:



62
63
64
65
# File 'lib/elo/configuration.rb', line 62

def applied_k_factors #:nodoc:
  apply_fide_k_factors if use_FIDE_settings
  k_factors
end

#k_factor(factor, &rule) ⇒ Object

Add a K-factor rule. The first argument is the k-factor value. The block should return a boolean that determines if this K-factor rule applies. The first rule that applies is the one determining the K-factor.

The block is instance_eval’ed into the player, so you can access all it’s properties directly. The K-factor is recalculated every time a match is played.

By default, the FIDE settings are used (see: use_FIDE_settings). To implement that yourself, you could write:

Elo.configure do |config|
  config.k_factor(10) { pro? or pro_rating? }
  config.k_factor(25) { starter? }
  config.default_k_factor = 15
end


58
59
60
# File 'lib/elo/configuration.rb', line 58

def k_factor(factor, &rule)
  k_factors << { :factor => factor, :rule => rule }
end