Fix teams meeting too early in bracket

This commit is contained in:
Kalle 2023-05-19 19:41:56 +03:00
parent 0d981f4e5b
commit 98ec7fe99f
2 changed files with 33 additions and 1 deletions

View File

@ -84,7 +84,10 @@ export function resolveTournamentStageSettings(
case "SE":
return {};
case "DE":
return { grandFinal: "double" };
return {
grandFinal: "double",
seedOrdering: ["space_between"],
};
default: {
assertUnreachable(format);
}

View File

@ -2,6 +2,7 @@
import type { SeedOrdering } from "brackets-model";
import type { OrderingMap } from "./types";
import invariant from "tiny-invariant";
export const ordering: OrderingMap = {
natural: <T>(array: T[]) => [...array],
@ -20,6 +21,34 @@ export const ordering: OrderingMap = {
result.push(array[i + 1], array[i]);
return result;
},
// https://stackoverflow.com/a/11631472
space_between: <T>(array: T[]) => {
const numPlayers = array.length;
const rounds = Math.log(numPlayers) / Math.log(2) - 1;
let pls = [1, 2];
for (let i = 0; i < rounds; i++) {
pls = nextLayer(pls);
}
return seedsToOrderedArray(pls);
function nextLayer(pls: number[]) {
const out: number[] = [];
const length = pls.length * 2 + 1;
pls.forEach(function (d) {
out.push(d);
out.push(length - d);
});
return out;
}
// this part added to the SO answer
function seedsToOrderedArray(seeds: number[]) {
return seeds.map((seed) => {
const participant = array[seed - 1];
invariant(participant !== undefined, `No participant for seed ${seed}`);
return participant;
});
}
},
inner_outer: <T>(array: T[]) => {
if (array.length === 2) return array;