needs testing

This commit is contained in:
Tobias Huber 2025-03-02 13:17:38 +01:00
parent 92acbbc221
commit 5a7ff67e73
1 changed files with 8 additions and 8 deletions

View File

@ -138,14 +138,14 @@ class GroupStageService
# @param teams_per_group_ranked [Array] a 2D array of teams ranked by group scores # @param teams_per_group_ranked [Array] a 2D array of teams ranked by group scores
# @return [Array] the teams advancing from the group stage # @return [Array] the teams advancing from the group stage
def handle_special_case(teams_per_group_ranked) def handle_special_case(teams_per_group_ranked)
advancing_teams = [] # transpose the array to group first and second places together
teams_per_group_ranked.each_with_index do |_group_teams, i| teams_per_group_ranked_transposed = teams_per_group_ranked.transpose
first = teams_per_group_ranked[i % teams_per_group_ranked.size][0] first_places = teams_per_group_ranked_transposed[0]
second = teams_per_group_ranked[(i + teams_per_group_ranked.size / 2) % teams_per_group_ranked.size][1] second_places = teams_per_group_ranked_transposed[1]
advancing_teams << first # split the second places in half and place the second half at the beginning
advancing_teams << second mid = second_places.length / 2
end second_places_new_order = second_places[mid..-1] + second_places[0..mid]
advancing_teams first_places.zip(second_places_new_order).flatten
end end
# Handles the default case for advancing teams # Handles the default case for advancing teams