diff --git a/app/core/tournament/bracket.test.ts b/app/core/tournament/bracket.test.ts index 0c6c84e62..3b9ec52b7 100644 --- a/app/core/tournament/bracket.test.ts +++ b/app/core/tournament/bracket.test.ts @@ -27,6 +27,13 @@ CountBracketRounds("Counts bracket (DE - 16)", () => { assert.equal(count, { winners: 6, losers: 6 }); }); +CountBracketRounds("Counts bracket (SE - 16)", () => { + const bracket = eliminationBracket(16, "SE"); + const count = countRounds(bracket); + + assert.equal(count, { winners: 5, losers: 0 }); +}); + RoundNames("No bracket reset round for SE", () => { const bracketSE = getRoundNames(eliminationBracket(16, "SE")); const bracketDE = getRoundNames(eliminationBracket(16, "DE")); diff --git a/app/core/tournament/bracket.ts b/app/core/tournament/bracket.ts index a1814c0f2..70363bf16 100644 --- a/app/core/tournament/bracket.ts +++ b/app/core/tournament/bracket.ts @@ -109,12 +109,15 @@ export function getRoundNames(bracket: Bracket): EliminationBracket { } export function countRounds(bracket: Bracket): EliminationBracket { - let winners = 2; + const isDE = bracket.losers.length > 0; + let winners = 1 + Number(isDE); for (let i = bracket.participantsWithByesCount; i > 1; i /= 2) { winners++; } + if (!isDE) return { winners, losers: 0 }; + const losersMatchIds = new Set(bracket.losers.map((match) => match.id)); let losers = 0; let losersMatch = bracket.losers[bracket.losers.length - 1];