def rate!(opt={})
      # The original algorithm (version 0).
      max_iterations  = [30, 1]
      phase_2_bonuses = true
      update_bonuses  = false
      threshold       = 0.5

      # New versions of the algorithm.
      version = opt[:version].to_i
      if version >= 1
        # See http://ratings.icu.ie/articles/18 (Part 1)
        max_iterations[1] = 30
      end
      if version >= 2
        # See http://ratings.icu.ie/articles/18 (Part 2)
        phase_2_bonuses = false
        update_bonuses  = true
        threshold       = 0.1
      end
      if version >= 3
        # See http://ratings.icu.ie/articles/18 (Part 3)
        max_iterations = [50, 50]
      end

      # Phase 1.
      players.each { |p| p.reset }
      @iterations1 = performance_ratings(max_iterations[0], threshold)
      players.each { |p| p.rate! }

      # Phase 2.
      if !no_bonuses && calculate_bonuses > 0
        players.each { |p| p.rate!(update_bonuses) }
        @iterations2 = performance_ratings(max_iterations[1], threshold)
        calculate_bonuses if phase_2_bonuses
      else
        @iterations2 = 0
      end
    end
def rate!(opt={})
      # The original algorithm (version 0).
      max_iterations  = [30, 1]
      phase_2_bonuses = true
      update_bonuses  = false
      threshold       = 0.5

      # New versions of the algorithm.
      version = opt[:version].to_i
      if version >= 1
        # See http://ratings.icu.ie/articles/18 (Part 1)
        max_iterations[1] = 30
      end
      if version >= 2
        # See http://ratings.icu.ie/articles/18 (Part 2)
        phase_2_bonuses = false
        update_bonuses  = true
        threshold       = 0.1
      end
      if version >= 3
        # See http://ratings.icu.ie/articles/18 (Part 3)
        max_iterations = [50, 50]
      end

      # Phase 1.
      players.each { |p| p.reset }
      @iterations1 = performance_ratings(max_iterations[0], threshold)
      players.each { |p| p.rate! }

      # Phase 2.
      if !no_bonuses && calculate_bonuses > 0
        players.each { |p| p.rate!(update_bonuses) }
        @iterations2 = performance_ratings(max_iterations[1], threshold)
        calculate_bonuses if phase_2_bonuses
      else
        @iterations2 = 0
      end
    end
Rate the tournament. Called after all players and results have been added.