mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-09-13 06:36:49 -05:00
Handle trimming out third place match in prepared maps
This commit is contained in:
@@ -209,6 +209,17 @@ describe("PreparedMaps - trimPreparedEliminationMaps", () => {
|
||||
expect(trimmed).toBe(FOUR_TEAM_SE_PREPARED);
|
||||
});
|
||||
|
||||
test("returns trimmed if third place match disappeared", () => {
|
||||
const trimmed = PreparedMaps.trimPreparedEliminationMaps({
|
||||
preparedMaps: FOUR_TEAM_SE_PREPARED,
|
||||
teamCount: 3,
|
||||
bracket: tournament.bracketByIdx(0)!,
|
||||
});
|
||||
|
||||
expect(trimmed?.maps.length).toBe(FOUR_TEAM_SE_PREPARED.maps.length - 1);
|
||||
expect(trimmed?.maps.some((m) => m.groupId === 1)).toBe(false);
|
||||
});
|
||||
|
||||
test("trims the maps (SE - 1 extra round)", () => {
|
||||
const trimmed = PreparedMaps.trimPreparedEliminationMaps({
|
||||
preparedMaps: EIGHT_TEAM_SE_PREPARED,
|
||||
|
||||
@@ -101,6 +101,10 @@ export function trimPreparedEliminationMaps({
|
||||
eliminationTeamCountOptions(teamCount)[0].max;
|
||||
|
||||
if (isPerfectCountMatch) {
|
||||
if (thirdPlaceMatchDisappeared({ preparedMaps, teamCount, ...rest })) {
|
||||
return filterOutThirdPlaceMatch(preparedMaps);
|
||||
}
|
||||
|
||||
return preparedMaps;
|
||||
}
|
||||
|
||||
@@ -160,3 +164,28 @@ function roundsWithVirtualIds<T extends { roundId: number }>(
|
||||
|
||||
return rounds.map((r, i) => ({ ...r, roundId: virtualIds[i] }));
|
||||
}
|
||||
|
||||
function thirdPlaceMatchDisappeared({
|
||||
bracket,
|
||||
preparedMaps,
|
||||
teamCount,
|
||||
}: TrimPreparedEliminationMapsAgs & { preparedMaps: PreparedMaps }) {
|
||||
if (
|
||||
bracket.type !== "single_elimination" ||
|
||||
!bracket.settings?.thirdPlaceMatch
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const preparedHasThirdPlace =
|
||||
removeDuplicates(preparedMaps.maps.map((r) => r.groupId)).length > 1;
|
||||
|
||||
return preparedHasThirdPlace && teamCount < 4;
|
||||
}
|
||||
|
||||
function filterOutThirdPlaceMatch(prepared: PreparedMaps): PreparedMaps {
|
||||
return {
|
||||
...prepared,
|
||||
maps: prepared.maps.filter((map) => map.groupId === 0),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user