Module: TournamentSystem::SingleElimination

Extended by:
SingleElimination
Included in:
SingleElimination
Defined in:
lib/tournament_system/single_elimination.rb

Overview

Implements the single 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
# File 'lib/tournament_system/single_elimination.rb', line 13

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

  teams = if driver.matches.empty?
            padded = Algorithm::Util.padd_teams_pow2 driver.seeded_teams
            Algorithm::SingleBracket.seed padded
          else
            last_matches = previous_round_matches driver, round
            get_match_winners driver, last_matches
          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)


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

def guess_round(driver)
  Algorithm::SingleBracket.guess_round(driver.seeded_teams.length,
                                       driver.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)


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

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