class ICU::TieBreak
This class is used to recognise the names of tie break rules. The class method identify takes a string as it’s only argument and returns a new intstance if it recognises a tie break rule from the string, or nil otherwise. An instance has three read-only methods: id (a shoet symbolic name), code (a two letter code) and name (the full name). For example:
ICU::TieBreak.identify("no such rule") # => nil tb = ICU::TieBreak.identify("Neustadlt") tb.id # => :neustadtl tb.code # => "SB" tb.name # => "Sonneborn-Berger"
The method is case insensitive and can cope with extraneous white space and, to a limited extent, name variations and spelling mistakes:
ICU::TieBreak.identify("SB").name # => "Sonneborn-Berger" ICU::TieBreak.identify("NESTADL").name # => "Sonneborn-Berger" ICU::TieBreak.identify(" wins ").name # => "Number of wins" ICU::TieBreak.identify(:sum_ratings).name # => "Sum of opponent's ratings" ICU::TieBreak.identify("median").name # => "Harkness" ICU::TieBreak.identify("MODIFIED").name # => "Modified median" ICU::TieBreak.identify("Modified\nMedian").name # => "Modified median" ICU::TieBreak.identify("\tbuccholts\t").name # => "Buchholz" ICU::TieBreak.identify("progressive\r\n").name # => "Sum of progressive scores" ICU::TieBreak.identify("SumOfCumulative").name # => "Sum of progressive scores"
The full list of supported tie break rules is:
-
Buchholz (:buchholz, “BH”): sum of opponents’ scores
-
Harkness (:harkness, “HK”): like Buchholz except the highest and lowest opponents’ scores are discarded (or two highest and lowest if 9 rounds or more)
-
Modified median (:modified_median, “MM”): same as Harkness except only lowest (or highest) score(s) are discarded for players with more (or less) than 50%
-
Number of blacks (:blacks, “NB”) number of blacks
-
Number of wins (:wins, “NW”) number of wins
-
Player’s name (:name, “PN”): alphabetical by name
-
Sonneborn-Berger (:neustadtl, “SB”): sum of scores of players defeated plus half sum of scores of players drawn against
-
Sum of opponents’ ratings (:ratings, “SR”): sum of opponents ratings (FIDE ratings are used in preference to local ratings if available)
-
Sum of progressive scores (:progressive, “SP”): sum of running score for each round
An array of all supported TieBreak
instances (ordered by name) is returned by the class method rules.
rules = ICU::TieBreak.rules rules.size # => 9 rules.first.name # => "Buchholz"
Note that this class only deals with the recognition of tie break names, not the calculation of tie break scores. The latter is currently implemented in the ICU::Tournament
class.
Constants
- RULES
Attributes
Public Class Methods
Given a string, return the TieBreak
rule it is recognised as, or return nil.
# File lib/icu_tournament/tie_break.rb, line 68 def self.identify(str) return nil unless str str = str.to_s.gsub(/\s+/, ' ').strip.downcase return nil if str.length <= 1 || str.length == 3 RULES.each_pair { |id, rule| return new(id, rule[0], rule[1]) if str.upcase == rule[0] || str.match(rule[2]) } nil end
Return an array of all tie break rules, ordered by name.
# File lib/icu_tournament/tie_break.rb, line 77 def self.rules RULES.keys.sort_by{ |id| RULES[id][1] }.inject([]) do |rules, id| rules << new(id, RULES[id][0], RULES[id][1]) end end