Module: TournamentSystem::Algorithm::GroupPairing
- Extended by:
- GroupPairing
- Included in:
- GroupPairing
- Defined in:
- lib/tournament_system/algorithm/group_pairing.rb
Overview
This module provides group pairing algorithms
Instance Method Summary collapse
-
#adjacent(teams) ⇒ Array<Array(team, team)>
Adjacent pairing (aka. King Of The Hill pairing).
-
#fold(teams) ⇒ Array<Array(team, team)>
Fold pairing (aka. Slaughter pairing).
-
#random(teams) ⇒ Array<Array(team, team)>
Random pairing.
-
#slide(teams) ⇒ Array<Array(team, team)>
Slide pairing (aka cross pairing).
Instance Method Details
#adjacent(teams) ⇒ Array<Array(team, team)>
Adjacent pairing (aka. King Of The Hill pairing)
Pair adjacent teams.
16 17 18 |
# File 'lib/tournament_system/algorithm/group_pairing.rb', line 16 def adjacent(teams) teams.each_slice(2).to_a end |
#fold(teams) ⇒ Array<Array(team, team)>
Fold pairing (aka. Slaughter pairing)
Pair the top team with the bottom team
29 30 31 32 33 34 35 |
# 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) ⇒ Array<Array(team, team)>
Random pairing
Pair teams randomly.
61 62 63 |
# File 'lib/tournament_system/algorithm/group_pairing.rb', line 61 def random(teams) adjacent(teams.shuffle) end |
#slide(teams) ⇒ Array<Array(team, team)>
Slide pairing (aka cross pairing).
Pair the top half of teams with the bottom half, respectively.
46 47 48 49 50 |
# File 'lib/tournament_system/algorithm/group_pairing.rb', line 46 def (teams) top, bottom = teams.each_slice(teams.length / 2).to_a top.zip(bottom).to_a end |