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

Instance Method Details

#adjacent(teams) ⇒ Array<Array(team, team)>

Adjacent pairing (aka. King Of The Hill pairing)

Pair adjacent teams.

Examples:

adjacent([1, 2, 3, 4]) #=> [[1, 2], [3, 4]]

Parameters:

  • teams (Array<team>)

Returns:

  • (Array<Array(team, team)>)


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

Examples:

fold([1, 2, 3, 4]) #=> [[1, 4], [2, 3]]

Parameters:

  • teams (Array<team>)

Returns:

  • (Array<Array(team, 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.

Examples:

pair([1, 2, 3, 4, 5, 6]) #=> [[1, 4], [2, 6], [3, 5]]

Parameters:

  • teams (Array<team>)

Returns:

  • (Array<Array(team, team)>)


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.

Examples:

pair([1, 2, 3, 4]) #=> [[1, 3], [2, 4]]

Parameters:

  • teams (Array<team>)

Returns:

  • (Array<Array(team, team)>)


46
47
48
49
50
# 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