module TournamentSystem::Algorithm::GroupPairing
This module provides group pairing algorithms
Public Instance Methods
adjacent(teams)
click to toggle source
Adjacent pairing (aka. King Of The Hill pairing)
Pair adjacent teams.
@example
adjacent([1, 2, 3, 4]) #=> [[1, 2], [3, 4]]
@param teams [Array<team>] @return [Array<Array(team, team)>]
# File lib/tournament_system/algorithm/group_pairing.rb, line 16 def adjacent(teams) teams.each_slice(2).to_a end
fold(teams)
click to toggle source
Fold pairing (aka. Slaughter pairing)
Pair the top team with the bottom team
@example
fold([1, 2, 3, 4]) #=> [[1, 4], [2, 3]]
@param teams [Array<team>] @return [Array<Array(team, team)>]
# File lib/tournament_system/algorithm/group_pairing.rb, line 29 def fold(teams) top, bottom = teams.each_slice(teams.length / 2).to_a bottom.reverse! top.zip(bottom).to_a end
random(teams)
click to toggle source
Random pairing
Pair teams randomly.
@example
pair([1, 2, 3, 4, 5, 6]) #=> [[1, 4], [2, 6], [3, 5]]
@param teams [Array<team>] @return [Array<Array(team, team)>]
# File lib/tournament_system/algorithm/group_pairing.rb, line 61 def random(teams) adjacent(teams.shuffle) end
slide(teams)
click to toggle source
Slide pairing (aka cross pairing).
Pair the top half of teams with the bottom half, respectively.
@example
pair([1, 2, 3, 4]) #=> [[1, 3], [2, 4]]
@param teams [Array<team>] @return [Array<Array(team, team)>]
# File lib/tournament_system/algorithm/group_pairing.rb, line 46 def slide(teams) top, bottom = teams.each_slice(teams.length / 2).to_a top.zip(bottom).to_a end