From c016e5e0c8f9a488286a215fad20ef9c80ac0f84 Mon Sep 17 00:00:00 2001 From: Raz Date: Sat, 26 Oct 2024 10:31:19 +0200 Subject: [PATCH] fix game difference calculation for format b / c --- PadelClub/Data/Match.swift | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/PadelClub/Data/Match.swift b/PadelClub/Data/Match.swift index 4573827..9d3b181 100644 --- a/PadelClub/Data/Match.swift +++ b/PadelClub/Data/Match.swift @@ -816,8 +816,24 @@ defer { } else { setDifference = zip.filter { $0 > $1 }.count - zip.filter { $1 > $0 }.count } - let gameDifference = zip.map { ($0, $1) }.map { $0.0 - $0.1 }.reduce(0,+) - return (setDifference * reverseValue, gameDifference * reverseValue) + + // si 3 sets et 3eme set super tie break, different des 2 premiers sets, alors super tie points ne sont pas des jeux et doivent etre compté comme un jeu + + if matchFormat.canSuperTie, endedSetsOne.count == 3 { + let games = zip.map { ($0, $1) } + let gameDifference = games.enumerated().map({ index, pair in + if index < 2 { + return pair.0 - pair.1 + } else { + return pair.0 < pair.1 ? -1 : 1 + } + }) + .reduce(0,+) + return (setDifference * reverseValue, gameDifference * reverseValue) + } else { + let gameDifference = zip.map { ($0, $1) }.map { $0.0 - $0.1 }.reduce(0,+) + return (setDifference * reverseValue, gameDifference * reverseValue) + } } func groupStageProjectedTeam(_ team: TeamPosition) -> TeamRegistration? {