From 02af571113d16d4dd146d2be44cc9cd93ed5f83a Mon Sep 17 00:00:00 2001 From: "Kalle (Sendou)" <38327916+Sendouc@users.noreply.github.com> Date: Fri, 17 Dec 2021 17:50:28 +0200 Subject: [PATCH] Handle a few map generation special cases --- app/core/tournament/mapList.test.ts | 30 +++++++++++++++++++++++++++++ app/core/tournament/mapList.ts | 6 ++++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/app/core/tournament/mapList.test.ts b/app/core/tournament/mapList.test.ts index e0ce353a6..dc313b7a0 100644 --- a/app/core/tournament/mapList.test.ts +++ b/app/core/tournament/mapList.test.ts @@ -83,4 +83,34 @@ MapListForRounds("Should not repeat map in adjacent rounds", () => { } }); +MapListForRounds( + "Should generate a map list even if only one map/mode combo (SZ)", + () => { + const mapListOfRepeatingNature = generateMapListForRounds({ + mapPool: [{ id: 1, mode: "SZ", name: "The Reef" }], + rounds, + }); + + assert.equal( + mapListOfRepeatingNature.winners.length, + mapList.winners.length + ); + } +); + +MapListForRounds( + "Should generate a map list even if only one map/mode combo (TC)", + () => { + const mapListOfRepeatingNature = generateMapListForRounds({ + mapPool: [{ id: 1, mode: "TC", name: "The Reef" }], + rounds, + }); + + assert.equal( + mapListOfRepeatingNature.winners.length, + mapList.winners.length + ); + } +); + MapListForRounds.run(); diff --git a/app/core/tournament/mapList.ts b/app/core/tournament/mapList.ts index 74bddcf92..de02dfba0 100644 --- a/app/core/tournament/mapList.ts +++ b/app/core/tournament/mapList.ts @@ -27,6 +27,7 @@ export function generateMapListForRounds({ }, []); let currentModes = clone(modes); const hasSZ = mapPool.some((stage) => stage.mode === "SZ"); + const onlySZ = mapPool.every((stage) => stage.mode === "SZ"); const allModesLength = modes.length + Number(hasSZ); let stagesOfPreviousRound: string[] = []; @@ -45,7 +46,9 @@ export function generateMapListForRounds({ }; function roundsMapList(bestOf: BestOf): Stage[] { - const modes = resolveModes(bestOf); + const modes = onlySZ + ? new Array(bestOf).fill(null).map(() => "SZ" as Mode) + : resolveModes(bestOf); const maps = resolveMaps(modes); return new Array(bestOf).fill(null).map((_, i) => { @@ -110,7 +113,6 @@ export function generateMapListForRounds({ const nextModeTuple = currentModes[0]; invariant(nextModeTuple, "nextModeTuple undefined"); - invariant(previous !== nextModeTuple[0], "Repeating mode"); resultWithNoNull.push(nextModeTuple[0]); nextModeTuple[1]--;