Module: TournamentSystem::Swiss

Extended by:
Swiss
Included in:
Swiss
Defined in:
lib/tournament_system/swiss.rb,
lib/tournament_system/swiss/dutch.rb,
lib/tournament_system/swiss/accelerated_dutch.rb

Overview

Robust implementation of the swiss tournament system

Defined Under Namespace

Modules: AcceleratedDutch, Dutch

Instance Method Summary collapse

Instance Method Details

#generate(driver, options = {}) ⇒ nil

Generate matches with the given driver.

Parameters:

  • driver (Driver)
  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • pairer (Pairer)

    the pairing system to use, defaults to Dutch

  • pair_options (Hash)

    options for the chosen pairing system, see Dutch for more details

Returns:

  • (nil)


18
19
20
21
22
23
24
25
# File 'lib/tournament_system/swiss.rb', line 18

def generate(driver, options = {})
  pairer = options[:pairer] || Dutch
  pairer_options = options[:pair_options] || {}

  pairings = pairer.pair(driver, pairer_options)

  driver.create_matches(pairings)
end

#guess_round(driver) ⇒ Integer

Guesses the round number (starting from 0) from the maximum amount of matches any team has played. The guess will be wrong for long running competitions where teams are free to sign up and drop out at any time.

Parameters:

Returns:

  • (Integer)


32
33
34
# File 'lib/tournament_system/swiss.rb', line 32

def guess_round(driver)
  driver.team_matches_hash.values.map(&:length).max || 0
end

#minimum_rounds(driver) ⇒ Integer

The minimum number of rounds to determine a number of winners.

Parameters:

Returns:

  • (Integer)


40
41
42
# File 'lib/tournament_system/swiss.rb', line 40

def minimum_rounds(driver)
  Algorithm::Swiss.minimum_rounds(driver.seeded_teams.length)
end