|
|
|
|
@ -667,7 +667,8 @@ defer { |
|
|
|
|
setCourt(_courtIndex) |
|
|
|
|
} |
|
|
|
|
case .random: |
|
|
|
|
if let _courtIndex = availableCourts().randomElement() { |
|
|
|
|
let runningMatches: [Match] = DataStore.shared.runningMatches() |
|
|
|
|
if let _courtIndex = availableCourts(runningMatches: runningMatches).randomElement() { |
|
|
|
|
setCourt(_courtIndex) |
|
|
|
|
} |
|
|
|
|
case .field(let _courtIndex): |
|
|
|
|
@ -707,8 +708,8 @@ defer { |
|
|
|
|
return currentTournament()?.courtCount ?? 1 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func courtIsAvailable(_ courtIndex: Int) -> Bool { |
|
|
|
|
let courtUsed = currentTournament()?.courtUsed() ?? [] |
|
|
|
|
func courtIsAvailable(_ courtIndex: Int, in runningMatches: [Match]) -> Bool { |
|
|
|
|
let courtUsed = currentTournament()?.courtUsed(runningMatches: runningMatches) ?? [] |
|
|
|
|
return courtUsed.contains(courtIndex) == false |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -721,8 +722,8 @@ defer { |
|
|
|
|
return availableCourts |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func availableCourts() -> [Int] { |
|
|
|
|
let courtUsed = currentTournament()?.courtUsed() ?? [] |
|
|
|
|
func availableCourts(runningMatches: [Match]) -> [Int] { |
|
|
|
|
let courtUsed = currentTournament()?.courtUsed(runningMatches: runningMatches) ?? [] |
|
|
|
|
return Set(allCourts().map { $0 }).subtracting(Set(courtUsed)).sorted() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -1002,10 +1003,10 @@ defer { |
|
|
|
|
return " depuis " + startDate.timeElapsedString() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func canBePlayedInSpecifiedCourt() -> Bool { |
|
|
|
|
func canBePlayedInSpecifiedCourt(runningMatches: [Match]) -> Bool { |
|
|
|
|
guard let courtIndex else { return false } |
|
|
|
|
if expectedToBeRunning() { |
|
|
|
|
return courtIsAvailable(courtIndex) |
|
|
|
|
return courtIsAvailable(courtIndex, in: runningMatches) |
|
|
|
|
} else { |
|
|
|
|
return true |
|
|
|
|
} |
|
|
|
|
|