Commit 6b3e4df0 authored by Tomáš Strachoň's avatar Tomáš Strachoň
Browse files

fix: resolve issues with updating playoffs

parent f806d6be
Loading
Loading
Loading
Loading
+5 −11
Original line number Diff line number Diff line
@@ -112,23 +112,17 @@ namespace TournamentManager.ViewModels
        /// <param name="teams">All teams participating in given tournament</param>
        private static void UpdatePlayoffs(List<Match> matches, List<TournamentTeam> teams)
        {
            if (matches.Count(m => m.Round == 0 && m.GoalsHost != m.GoalsGuest) != Match.groupMatchesTotal)
            if (matches.Count(m => m.Round == 1 && m.GoalsHost != m.GoalsGuest) != Match.groupMatchesTotal)
            {
                return;
            }

            List<TournamentTeam> groupA = [.. teams.Where(tt => tt.Group == TournamentTeamGroup.A)];
            List<TournamentTeam> groupB = [.. teams.Where(tt => tt.Group == TournamentTeamGroup.B)];
            List<TournamentTeam> groupA = [.. teams.Where(tt => tt.Group == TournamentTeamGroup.A).OrderBy(tt => tt.Place)];
            List<TournamentTeam> groupB = [.. teams.Where(tt => tt.Group == TournamentTeamGroup.B).OrderBy(tt => tt.Place)];

            for (int i = 0; i < 8; ++i)
            for (int i = 0; i <= 3; ++i)
            {
                Debug.Assert(groupA[i].Place == i + 1);
                Debug.Assert(groupB[i].Place == i + 1);
            }

            for (int i = 0; i < 3; ++i)
            {
                AssignTeams(matches[Match.groupMatchesTotal], groupA[i].IdTeam, groupB[3 - i].IdTeam);
                AssignTeams(matches[Match.groupMatchesTotal + i], groupA[i].IdTeam, groupB[3 - i].IdTeam);
            }
        }