Handle a few map generation special cases

This commit is contained in:
Kalle (Sendou)
2021-12-17 17:50:28 +02:00
parent 54ca8aaab9
commit 02af571113
2 changed files with 34 additions and 2 deletions

View File

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

View File

@@ -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]--;