From a96af50cdbf364bbf29c5a56e5498fd8311f6691 Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Sat, 4 May 2024 11:11:05 +0300 Subject: [PATCH] Fix swiss round advancing missing teams --- .../tournament-bracket/core/Bracket.ts | 2 +- app/features/tournament-bracket/core/Swiss.ts | 29 ++++++------------- 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/app/features/tournament-bracket/core/Bracket.ts b/app/features/tournament-bracket/core/Bracket.ts index 73f96b16a..2922fca7d 100644 --- a/app/features/tournament-bracket/core/Bracket.ts +++ b/app/features/tournament-bracket/core/Bracket.ts @@ -1256,8 +1256,8 @@ class SwissBracket extends Bracket { round?.maps?.type === "PLAY_ALL" ? round?.maps?.count : Math.ceil((round?.maps?.count ?? 0) / 2); + // preview if (!mapWins) { - logger.warn("SwissBracket.currentStandings: mapWins not found"); continue; } diff --git a/app/features/tournament-bracket/core/Swiss.ts b/app/features/tournament-bracket/core/Swiss.ts index 9531f9d3a..6790c55f0 100644 --- a/app/features/tournament-bracket/core/Swiss.ts +++ b/app/features/tournament-bracket/core/Swiss.ts @@ -545,27 +545,16 @@ function matchesByNotPlayedBefore( return null; } -// https://stackoverflow.com/a/75330248 +// https://stackoverflow.com/a/75330079 function makeRounds(n: number) { - const sets: Record[] = []; - const rounds: [number, number][][] = []; - - for (let r = 0; r < n - 1; r++) { - sets.push({}); - rounds.push([]); - } - - for (let i = 0; i < n - 1; i++) { - for (let j = i + 1; j < n; j++) { - for (let r = 0; r < n - 1; r++) { - if (!sets[r][i] && !sets[r][j]) { - sets[r][i] = sets[r][j] = 1; - rounds[r].push([i, j]); - break; - } - } + const pairings = []; + const max = n - 1; + for (let i = 0; i < max; i++) { + const pairing = [[max, i]]; + for (let k = 1; k < n / 2; k++) { + pairing.push([(i + k) % max, (max + i - k) % max]); } + pairings.push(pairing); } - - return rounds; + return pairings; }