// --- 3. Create Grand Finals --- let gfMatch = id: matchIdCounter++, round: 1, type: 'gf', team1: null, // WB Champ team2: null, // LB Champ winner: null, loser: null, nextMatchId: null, nextLoserMatchId: null ; // Optional Reset Match (not implemented for simplicity, standard "one match final" assumption unless specified) // Usually double elimination GF requires the LB winner to beat WB winner twice. // We will implement a "Reset" button logic if GF is won by LB champ. state.matches.push(gfMatch); state.rounds.gf.push([gfMatch]);
// Link Winner if (r < lb.length - 1) let nextRound = lb[r+1]; // LB match order logic: // Usually top half plays top half, bottom half plays bottom half. // For 8 teams: LB R1 (2 matches) -> LB R2 (2 matches). M0->M0, M1->M1. // LB R2 (2 matches) -> LB R3 (1 match). M0 & M1 feed into single match. double elimination bracket maker
In a double elimination tournament:
let players = []; for (let i=1; i<=n; i++) players.push("P"+i); // --- 3
Winners Round 1 Winners Round 2 Winners Final Grand Final A ──┐ (Winners final) │ ├── W1a ──┐ W2a ──┐ │ B ──┘ │ │ │ ├── W2a ──┐ ├── WF ──┐ │ C ──┐ │ │ │ │ │ ├── W1b ──┘ │ │ │ │ D ──┘ │ │ │ │ ├── W2b ──┐ │ │ │ E ──┐ │ │ │ │ │ │ ├── W1c ──┐ │ │ │ │ │ F ──┘ │ │ │ │ │ │ ├── W2b ──┘ │ │ │ │ G ──┐ │ │ │ │ │ ├── W1d ──┘ │ │ │ │ H ──┘ │ │ │ │ │ │ │ │ Losers Bracket │ │ │ │ Loser W1a ──┐ │ │ │ │ ├── L1a ──┐ │ │ │ │ Loser W1b ──┘ │ │ │ │ │ ├── L2a ──┐ │ │ │ │ Loser W1c ──┐ │ │ │ │ │ │ ├── L1b ──┘ │ │ │ │ │ Loser W1d ──┘ │ │ │ │ │ │ │ │ │ │ Loser W2a ──────────────────────┘ │ │ │ │ ├── L3 ──┐ │ │ │ Loser W2b ──────────────────────┐ │ │ │ │ │ │ │ │ │ │ │ L2b ─────┘ │ │ │ │ │ │ │ │ │ │ L2a ─────┘ │ │ │ │ │ │ │ │ L3 ─────────────┘ │ │ │ │ │ │ Loser of WF ───────┼── LF ──┘ │ │ │ └── GF1 ──────┤ (if LF wins, GF2) // LB R2 (2 matches) -> LB R3 (1 match)
for (let m = 0; m < numMatches; m++) let match = id: matchIdCounter++, round: lbRoundIndex + 1, type: 'lb', team1: null, team2: null, winner: null, loser: null, nextMatchId: null, nextLoserMatchId: null // Not used for LB, they are out ; state.matches.push(match); roundMatches.push(match);