Module: TournamentSystem::RoundRobin

Extended by:
RoundRobin
Included in:
RoundRobin
Defined in:
lib/tournament_system/round_robin.rb

Overview

Implements the round-robin tournament system.

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):

  • round (Integer)

    the round to generate

Returns:

  • (nil)


14
15
16
17
18
19
20
21
22
# File 'lib/tournament_system/round_robin.rb', line 14

def generate(driver, options = {})
  round = options[:round] || guess_round(driver)

  teams = Algorithm::Util.padd_teams_even(driver.seeded_teams)

  matches = Algorithm::RoundRobin.round_robin_pairing(teams, round)

  create_matches driver, matches, round
end

#guess_round(driver) ⇒ Integer

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

Parameters:

Returns:

  • (Integer)


37
38
39
40
# File 'lib/tournament_system/round_robin.rb', line 37

def guess_round(driver)
  Algorithm::RoundRobin.guess_round(driver.seeded_teams.length,
                                    driver.matches.length)
end

#total_rounds(driver) ⇒ Integer

The total number of rounds needed for a round robin tournament with the given driver.

Parameters:

Returns:

  • (Integer)


29
30
31
# File 'lib/tournament_system/round_robin.rb', line 29

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