Handle counting SE rounds

This commit is contained in:
Kalle (Sendou)
2021-12-17 19:01:14 +02:00
parent 2332456ef2
commit d27683ecc9
2 changed files with 11 additions and 1 deletions

View File

@@ -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"));

View File

@@ -109,12 +109,15 @@ export function getRoundNames(bracket: Bracket): EliminationBracket<string[]> {
}
export function countRounds(bracket: Bracket): EliminationBracket<number> {
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];