feat: support double-elimination series games
This commit is contained in:
1 parent
2ee8c3807b
commit
e188828423
16 files changed
+1176
-234
No files matched your search
@@ -1,7 +1,9 @@
|
||||
import {
|
||||
buildDoubleEliminationGameSlots,
|
||||
buildDoubleEliminationBracket,
|
||||
cancelDoubleEliminationBracketMatch,
|
||||
completeDoubleEliminationBracketMatch,
|
||||
resolveDoubleEliminationSeriesWinner,
|
||||
reshuffleDoubleEliminationSeeds,
|
||||
swapDoubleEliminationSeeds,
|
||||
} from './double-elimination.util';
|
||||
@@ -15,14 +17,111 @@ describe('double-elimination util', () => {
|
||||
expect(bracket.bracketMatches.map((match) => match.bracketMatchId)).toEqual(
|
||||
['WB_R1_M1', 'WB_R1_M2', 'WB_FINAL', 'LB_R1_M1', 'LB_FINAL', 'GF'],
|
||||
);
|
||||
expect(bracket.bracketMatches.find((match) => match.bracketMatchId === 'WB_R1_M1'))
|
||||
.toMatchObject({
|
||||
teamAIndex: 1,
|
||||
teamBIndex: 4,
|
||||
winnerAdvancesTo: { bracketMatchId: 'WB_FINAL', position: 'A' },
|
||||
loserAdvancesTo: { bracketMatchId: 'LB_R1_M1', position: 'A' },
|
||||
state: 'ready',
|
||||
});
|
||||
expect(
|
||||
bracket.bracketMatches.find(
|
||||
(match) => match.bracketMatchId === 'WB_R1_M1',
|
||||
),
|
||||
).toMatchObject({
|
||||
teamAIndex: 1,
|
||||
teamBIndex: 4,
|
||||
winnerAdvancesTo: { bracketMatchId: 'WB_FINAL', position: 'A' },
|
||||
loserAdvancesTo: { bracketMatchId: 'LB_R1_M1', position: 'A' },
|
||||
state: 'ready',
|
||||
});
|
||||
});
|
||||
|
||||
it('assigns extensible series rules to winner-bracket matches', () => {
|
||||
const bracket = buildDoubleEliminationBracket([1, 2, 3, 4], {
|
||||
resetFinalEnabled: true,
|
||||
winnerBracketGameCount: 5,
|
||||
});
|
||||
|
||||
expect(
|
||||
bracket.bracketMatches
|
||||
.filter((match) => match.bracketSide === 'winner')
|
||||
.map((match) => ({
|
||||
bracketMatchId: match.bracketMatchId,
|
||||
gameCount: match.gameCount,
|
||||
requiredWins: match.requiredWins,
|
||||
})),
|
||||
).toEqual([
|
||||
{ bracketMatchId: 'WB_R1_M1', gameCount: 5, requiredWins: 3 },
|
||||
{ bracketMatchId: 'WB_R1_M2', gameCount: 5, requiredWins: 3 },
|
||||
{ bracketMatchId: 'WB_FINAL', gameCount: 5, requiredWins: 3 },
|
||||
]);
|
||||
expect(
|
||||
bracket.bracketMatches.find(
|
||||
(match) => match.bracketMatchId === 'LB_R1_M1',
|
||||
),
|
||||
).toMatchObject({ gameCount: 1, requiredWins: 1 });
|
||||
expect(
|
||||
bracket.bracketMatches.find((match) => match.bracketMatchId === 'GF'),
|
||||
).toMatchObject({ gameCount: 1, requiredWins: 1 });
|
||||
});
|
||||
|
||||
it('expands bracket match series into game slots', () => {
|
||||
const bracket = buildDoubleEliminationBracket([1, 2, 3, 4], {
|
||||
resetFinalEnabled: true,
|
||||
});
|
||||
|
||||
expect(
|
||||
buildDoubleEliminationGameSlots(bracket.bracketMatches).slice(0, 7),
|
||||
).toEqual([
|
||||
expect.objectContaining({
|
||||
gameNumber: 1,
|
||||
seriesGameNumber: 1,
|
||||
bracketMatch: expect.objectContaining({ bracketMatchId: 'WB_R1_M1' }),
|
||||
}),
|
||||
expect.objectContaining({
|
||||
gameNumber: 2,
|
||||
seriesGameNumber: 2,
|
||||
bracketMatch: expect.objectContaining({ bracketMatchId: 'WB_R1_M1' }),
|
||||
}),
|
||||
expect.objectContaining({
|
||||
gameNumber: 3,
|
||||
seriesGameNumber: 3,
|
||||
bracketMatch: expect.objectContaining({ bracketMatchId: 'WB_R1_M1' }),
|
||||
}),
|
||||
expect.objectContaining({
|
||||
gameNumber: 4,
|
||||
seriesGameNumber: 1,
|
||||
bracketMatch: expect.objectContaining({ bracketMatchId: 'WB_R1_M2' }),
|
||||
}),
|
||||
expect.objectContaining({
|
||||
gameNumber: 5,
|
||||
seriesGameNumber: 2,
|
||||
bracketMatch: expect.objectContaining({ bracketMatchId: 'WB_R1_M2' }),
|
||||
}),
|
||||
expect.objectContaining({
|
||||
gameNumber: 6,
|
||||
seriesGameNumber: 3,
|
||||
bracketMatch: expect.objectContaining({ bracketMatchId: 'WB_R1_M2' }),
|
||||
}),
|
||||
expect.objectContaining({
|
||||
gameNumber: 7,
|
||||
seriesGameNumber: 1,
|
||||
bracketMatch: expect.objectContaining({ bracketMatchId: 'WB_FINAL' }),
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
it('requires the configured number of wins before resolving a series winner', () => {
|
||||
const bracketMatch = buildDoubleEliminationBracket([1, 2, 3, 4], {
|
||||
resetFinalEnabled: true,
|
||||
}).bracketMatches.find((match) => match.bracketMatchId === 'WB_R1_M1');
|
||||
|
||||
expect(
|
||||
resolveDoubleEliminationSeriesWinner(
|
||||
{ teamAIndex: 1, teamBIndex: 4, teamAWins: 1, teamBWins: 0 },
|
||||
bracketMatch!,
|
||||
),
|
||||
).toBeUndefined();
|
||||
expect(
|
||||
resolveDoubleEliminationSeriesWinner(
|
||||
{ teamAIndex: 1, teamBIndex: 4, teamAWins: 2, teamBWins: 1 },
|
||||
bracketMatch!,
|
||||
),
|
||||
).toBe(1);
|
||||
});
|
||||
|
||||
it('moves winners and losers through a 4-team bracket and records top 3', () => {
|
||||
@@ -43,10 +142,16 @@ describe('double-elimination util', () => {
|
||||
completedAt: new Date('2026-06-01T10:30:00.000Z'),
|
||||
});
|
||||
|
||||
expect(bracket.bracketMatches.find((match) => match.bracketMatchId === 'WB_FINAL'))
|
||||
.toMatchObject({ teamAIndex: 1, teamBIndex: 2, state: 'ready' });
|
||||
expect(bracket.bracketMatches.find((match) => match.bracketMatchId === 'LB_R1_M1'))
|
||||
.toMatchObject({ teamAIndex: 4, teamBIndex: 3, state: 'ready' });
|
||||
expect(
|
||||
bracket.bracketMatches.find(
|
||||
(match) => match.bracketMatchId === 'WB_FINAL',
|
||||
),
|
||||
).toMatchObject({ teamAIndex: 1, teamBIndex: 2, state: 'ready' });
|
||||
expect(
|
||||
bracket.bracketMatches.find(
|
||||
(match) => match.bracketMatchId === 'LB_R1_M1',
|
||||
),
|
||||
).toMatchObject({ teamAIndex: 4, teamBIndex: 3, state: 'ready' });
|
||||
|
||||
bracket = completeDoubleEliminationBracketMatch(bracket, {
|
||||
bracketMatchId: 'WB_FINAL',
|
||||
@@ -97,14 +202,17 @@ describe('double-elimination util', () => {
|
||||
|
||||
expect(bracket.resetFinalCreated).toBe(true);
|
||||
expect(bracket.placements).toEqual({ thirdTeamIndex: 3 });
|
||||
expect(bracket.bracketMatches.find((match) => match.bracketMatchId === 'GF_RESET'))
|
||||
.toMatchObject({
|
||||
gameNumber: 7,
|
||||
bracketSide: 'reset-final',
|
||||
teamAIndex: 1,
|
||||
teamBIndex: 2,
|
||||
state: 'ready',
|
||||
});
|
||||
expect(
|
||||
bracket.bracketMatches.find(
|
||||
(match) => match.bracketMatchId === 'GF_RESET',
|
||||
),
|
||||
).toMatchObject({
|
||||
gameNumber: 7,
|
||||
bracketSide: 'reset-final',
|
||||
teamAIndex: 1,
|
||||
teamBIndex: 2,
|
||||
state: 'ready',
|
||||
});
|
||||
});
|
||||
|
||||
it('rejects completion cancellation when downstream matches are already completed', () => {
|
||||
|
||||
Reference in new issue
Block a user