Module: TournamentSystem::Algorithm::RoundRobin
- Extended by:
- RoundRobin
- Included in:
- RoundRobin
- Defined in:
- lib/tournament_system/algorithm/round_robin.rb
Overview
This module provides algorithms for dealing with round robin tournament systems.
Instance Method Summary collapse
-
#guess_round(teams_count, matches_count) ⇒ Integer
Guess the next round (starting at 0) for round robin.
-
#round_robin(array, round) ⇒ Object
Rotate array using round robin.
-
#round_robin_enum(array) ⇒ Object
Enumerate all round robin rotations.
-
#round_robin_pairing(teams, round) ⇒ Array<Array(team, team)>
Rotates teams and pairs them for a round of round robin.
-
#total_rounds(teams_count) ⇒ Integer
Calculates the total number of rounds needed for round robin with a certain amount of teams.
Instance Method Details
#guess_round(teams_count, matches_count) ⇒ Integer
Guess the next round (starting at 0) for round robin.
25 26 27 |
# File 'lib/tournament_system/algorithm/round_robin.rb', line 25 def guess_round(teams_count, matches_count) matches_count / (Util.padded_teams_even_count(teams_count) / 2) end |
#round_robin(array, round) ⇒ Object
Rotate array using round robin.
33 34 35 36 37 |
# File 'lib/tournament_system/algorithm/round_robin.rb', line 33 def round_robin(array, round) rotateable = array[1..-1] [array[0]] + rotateable.rotate(-round) end |
#round_robin_enum(array) ⇒ Object
Enumerate all round robin rotations.
40 41 42 43 44 |
# File 'lib/tournament_system/algorithm/round_robin.rb', line 40 def round_robin_enum(array) Array.new(total_rounds(array.length)) do |index| round_robin(array, index) end end |
#round_robin_pairing(teams, round) ⇒ Array<Array(team, team)>
Rotates teams and pairs them for a round of round robin.
Uses GroupPairing#fold for pairing after rotating.
53 54 55 56 57 |
# File 'lib/tournament_system/algorithm/round_robin.rb', line 53 def round_robin_pairing(teams, round) rotated = round_robin(teams, round) GroupPairing.fold(rotated) end |
#total_rounds(teams_count) ⇒ Integer
Calculates the total number of rounds needed for round robin with a certain amount of teams.
16 17 18 |
# File 'lib/tournament_system/algorithm/round_robin.rb', line 16 def total_rounds(teams_count) Util.padded_teams_even_count(teams_count) - 1 end |