Module: TournamentSystem::DoubleElimination

Extended by:
DoubleElimination
Included in:
DoubleElimination
Defined in:
lib/tournament_system/double_elimination.rb

Overview

Implements the double bracket elimination tournament system.

Instance Method Summary collapse

Instance Method Details

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

Generate matches with the given driver

Parameters:

Returns:

  • (nil)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/tournament_system/double_elimination.rb', line 13

def generate(driver, _options = {})
  round = guess_round driver

  teams_padded = Algorithm::Util.padd_teams_pow2 driver.seeded_teams
  teams_seeded = Algorithm::DoubleBracket.seed teams_padded

  teams = if driver.matches.empty?
            teams_seeded
          else
            get_round_teams driver, round, teams_seeded
          end

  driver.create_matches Algorithm::GroupPairing.adjacent(teams)
end

#guess_round(driver) ⇒ Integer

Guess the next round number (starting at 0) from the state in driver.

Parameters:

Returns:

  • (Integer)


41
42
43
44
# File 'lib/tournament_system/double_elimination.rb', line 41

def guess_round(driver)
  Algorithm::DoubleBracket.guess_round(driver.seeded_teams.length,
                                       driver.non_bye_matches .length)
end

#total_rounds(driver) ⇒ Integer

The total number of rounds needed for a single elimination tournament with the given driver.

Parameters:

Returns:

  • (Integer)


33
34
35
# File 'lib/tournament_system/double_elimination.rb', line 33

def total_rounds(driver)
  Algorithm::DoubleBracket.total_rounds(driver.seeded_teams.length)
end