diff --git a/PadelClubData/Data/Tournament.swift b/PadelClubData/Data/Tournament.swift index 3c3514d..b92a476 100644 --- a/PadelClubData/Data/Tournament.swift +++ b/PadelClubData/Data/Tournament.swift @@ -2119,7 +2119,18 @@ defer { } } } - + + public func removeRound(_ round: Round) async { + await MainActor.run { + let teams = round.seeds() + teams.forEach { team in + team.resetBracketPosition() + } + tournamentStore?.teamRegistrations.addOrUpdate(contentOfs: teams) + tournamentStore?.rounds.delete(instance: round) + } + } + public func addNewRound(_ roundIndex: Int) async { await MainActor.run { let round = Round(tournament: id, index: roundIndex, format: matchFormat) diff --git a/PadelClubData/ViewModel/PadelRule.swift b/PadelClubData/ViewModel/PadelRule.swift index f73e759..9ac9e70 100644 --- a/PadelClubData/ViewModel/PadelRule.swift +++ b/PadelClubData/ViewModel/PadelRule.swift @@ -1852,6 +1852,16 @@ public enum RoundRule { } } + public static func cumulatedNumberOfMatches(forTeams teams: Int) -> Int { + var i = teams / 2 + if teams / 2 > 1 { + i += Self.cumulatedNumberOfMatches(forTeams: teams / 2) + i += Self.cumulatedNumberOfMatches(forTeams: teams / 4) + } + + return i + } + public static func teamsInFirstRound(forTeams teams: Int) -> Int { Int(pow(2.0, ceil(log2(Double(teams))))) }