Module: TournamentSystem::PagePlayoff

Extended by:
PagePlayoff
Included in:
PagePlayoff
Defined in:
lib/tournament_system/page_playoff.rb

Overview

Implements the page playoff system.

Instance Method Summary collapse

Instance Method Details

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

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

  • bronze_match (Boolean)

    whether to generate a bronze match on the final round.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/tournament_system/page_playoff.rb', line 15

def generate(driver, options = {})
  teams = driver.ranked_teams
  raise 'Page Playoffs only works with 4 teams' if teams.length != 4

  round = options[:round] || guess_round(driver)

  case round
  when 0 then semi_finals(driver, teams)
  when 1 then preliminary_finals(driver)
  when 2 then grand_finals(driver, options)
  else
    raise 'Invalid round number'
  end
end

#guess_round(driver) ⇒ Integer

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

Parameters:

Returns:

  • (Integer)


47
48
49
# File 'lib/tournament_system/page_playoff.rb', line 47

def guess_round(driver)
  Algorithm::PagePlayoff.guess_round(driver.matches.length)
end

#total_rounds(_ = nil) ⇒ Integer

The total number of rounds in a page playoff tournament

Parameters:

  • _ (defaults to: nil)

    for keeping the same interface as other tournament systems.

Returns:

  • (Integer)


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

def total_rounds(_ = nil)
  Algorithm::PagePlayoff::TOTAL_ROUNDS
end