@ -393,18 +393,32 @@ defer {
func availableSeedOpponentSpot ( inRoundIndex roundIndex : Int ) -> [ Match ] {
return getRound ( atRoundIndex : roundIndex ) ? . playedMatches ( ) . filter { $0 . hasSpaceLeft ( ) } ? ? [ ]
}
func availableSeedGroups ( ) -> [ SeedInterval ] {
func availableSeedGroups ( includeAll : Bool = false ) -> [ SeedInterval ] {
let seeds = seeds ( )
var availableSeedGroup = Set < SeedInterval > ( )
for ( index , seed ) in seeds . enumerated ( ) {
if seed . isSeedable ( ) , let seedGroup = seedGroup ( for : index ) {
availableSeedGroup . insert ( seedGroup )
if includeAll {
if let chunks = seedGroup . chunks ( ) {
chunksBy ( in : chunks , availableSeedGroup : & availableSeedGroup )
}
} else {
availableSeedGroup . insert ( seedGroup )
}
}
}
return availableSeedGroup . sorted ( by : < )
}
func chunksBy ( in chunks : [ SeedInterval ] , availableSeedGroup : inout Set < SeedInterval > ) {
chunks . forEach { chunk in
availableSeedGroup . insert ( chunk )
if let moreChunk = chunk . chunks ( ) {
self . chunksBy ( in : moreChunk , availableSeedGroup : & availableSeedGroup )
}
}
}
func seedGroup ( for alreadySetupSeeds : Int ) -> SeedInterval ? {
switch alreadySetupSeeds {
case 0. . . 1 :
@ -453,28 +467,32 @@ defer {
}
func seedGroupAvailable ( atRoundIndex roundIndex : Int , availableSeedGroup : SeedInterval ) -> SeedInterval ? {
if availableSeeds ( ) . isEmpty = = false && roundIndex >= lastSeedRound ( ) {
let fullLeftSeeds = availableSeeds ( )
if fullLeftSeeds . isEmpty = = false && roundIndex >= lastSeedRound ( ) {
if availableSeedGroup = = SeedInterval ( first : 1 , last : 2 ) { return availableSeedGroup }
let availableSeeds = seeds ( inSeedGroup : availableSeedGroup )
let availableSeedSpot = availableSeedSpot ( inRoundIndex : roundIndex )
let availableSeedOpponentSpot = availableSeedOpponentSpot ( inRoundIndex : roundIndex )
let targetSpots = availableSeedSpot . isEmpty ? availableSeedOpponentSpot . count : availableSeedSpot . count
if availableSeedGroup = = SeedInterval ( first : 3 , last : 4 ) , availableSeedSpot . count = = 6 {
print ( " availableSeedGroup == SeedInterval(first: 3, last: 4) " )
return availableSeedGroup
}
if availableSeeds . count = = availableSeedSpot . count && availableSeedGroup . count = = availableSeeds . count {
return availableSeedGroup
} else if availableSeeds . count = = availableSeedOpponentSpot . count && availableSeedGroup . count = = availableSeedOpponentSpot . count {
return availableSeedGroup
} else if let chunks = availableSeedGroup . chunks ( ) {
let seededTeamsCount = self . seededTeams ( ) . count
if let chunk = chunks . first ( where : { seedInterval in
seedInterval . first >= self . seededTeams ( ) . c ount
return seedInterval . first = = seededTeamsC ount
} ) {
return seedGroupAvailable ( atRoundIndex : roundIndex , availableSeedGroup : chunk )
} else if fullLeftSeeds . count > 1 , targetSpots > 1 , fullLeftSeeds . count >= targetSpots {
let seeds = seeds ( )
if let firstIndex = seeds . firstIndex ( where : { $0 . isSeedable ( ) } ) {
return seedGroupAvailable ( atRoundIndex : roundIndex , availableSeedGroup : SeedInterval ( first : firstIndex + 1 , last : firstIndex + targetSpots ) )
}
}
}
}
@ -507,6 +525,14 @@ defer {
for ( index , seed ) in availableSeeds . enumerated ( ) {
seed . setSeedPosition ( inSpot : spots [ index ] , slot : nil , opposingSeeding : false )
}
// } e l s e i f s e e d G r o u p = = S e e d I n t e r v a l ( f i r s t : 5 , l a s t : 6 ) , a v a i l a b l e S e e d S p o t . c o u n t = = 4 {
// v a r s p o t s = [ M a t c h ] ( )
// s p o t s . a p p e n d ( a v a i l a b l e S e e d S p o t [ 1 ] )
// s p o t s . a p p e n d ( a v a i l a b l e S e e d S p o t [ 2 ] )
// s p o t s = s p o t s . s h u f f l e d ( )
// f o r ( i n d e x , s e e d ) i n a v a i l a b l e S e e d s . e n u m e r a t e d ( ) {
// s e e d . s e t S e e d P o s i t i o n ( i n S p o t : s p o t s [ i n d e x ] , s l o t : n i l , o p p o s i n g S e e d i n g : f a l s e )
// }
} else {
if availableSeeds . count <= availableSeedSpot . count {
let spots = availableSeedSpot . shuffled ( )
@ -1105,7 +1131,17 @@ defer {
}
let groupStages = groupStages ( )
let baseRank = teamCount - groupStageSpots ( ) + qualifiedPerGroupStage * groupStageCount + groupStageAdditionalQualified
var baseRank = teamCount - groupStageSpots ( ) + qualifiedPerGroupStage * groupStageCount + groupStageAdditionalQualified
// TODO: R A Z a j o u t é u n e o p t i o n p o u r c h o i s i r e n t r e l a r è g l e o f f i c i e l e t l a r è g l e ' m a i s o n '
/*
Request by Philippe Morin 24 / 03 / 2025
*/
let defaultOption = false
if defaultOption {
baseRank += qualifiedPerGroupStage * groupStageCount + groupStageAdditionalQualified - 1
}
let alreadyPlaceTeams = Array ( teams . values . flatMap ( { $0 } ) )
groupStages . forEach { groupStage in
let groupStageTeams = groupStage . teams ( true )
@ -1115,6 +1151,7 @@ defer {
let groupStageWidth = max ( ( ( index = = qualifiedPerGroupStage ) ? groupStageCount - groupStageAdditionalQualified : groupStageCount ) * ( index - qualifiedPerGroupStage ) , 0 )
let _index = baseRank + groupStageWidth + 1 - ( index > qualifiedPerGroupStage ? groupStageAdditionalQualified : 0 )
print ( " finalRanking " , team . teamLabel ( ) , _index , baseRank , groupStageWidth )
if let existingTeams = teams [ _index ] {
teams [ _index ] = existingTeams + [ team . id ]
} else {
@ -2563,8 +2600,8 @@ extension Tournament {
extension Tournament {
func deadline ( for type : TournamentDeadlineType ) -> Date ? {
guard [ . p500 , . p1000 , . p1500 , . p2000 ] . contains ( tournamentLevel ) else { return nil }
var daysOffset = type . daysOffset ( level : tournamentLevel )
let daysOffset = type . daysOffset ( level : tournamentLevel )
if let date = Calendar . current . date ( byAdding : . day , value : daysOffset , to : startDate ) {
let startOfDay = Calendar . current . startOfDay ( for : date )
return Calendar . current . date ( byAdding : type . timeOffset , to : startOfDay )