Swiss Tournament Tiebreakers and Binomial Cut Math in JavaScript
In large tabletop and esports tournaments, judges and players constantly ask two questions during Round 4: how many undefeated and X-2 players will finish in the Top 8 bubble, and what are the actual odds that a specific win-loss sequence (such as losing in Round 1 versus losing in the final round) survives Opponent Match Win percentage (OMW%) tiebreakers?
We extracted the pure mathematical engine behind the Sunasty Tournament Calculator and Swiss Tournament Generator into the MIT package swiss-math (JSR).
1. Expected Win-Loss Field via Exact Binomial & Draw Convolution
When no intentional draws or double losses occur, computeStructure evaluates the exact binomial distribution across R Swiss rounds. When drawRate or doubleLossRate is non-zero, expectedFieldWithDraws iterates over all valid (wins, draws, losses) triplets so points-based buckets reflect tie-adjusted standings:
import { getPreset, computeStructure, exportBracketText } from 'swiss-math';
const mtg = getPreset('mtg');
const structure = computeStructure(mtg, 64, undefined, { drawRate: 0.05 });
console.log(structure.rounds, structure.cutSize); // 6 Swiss rounds, Top 8
console.log(structure.cutLineWins); // Minimum wins in Top Cut
console.log(exportBracketText(structure.cutSize));
Because standard playoff pairings must ensure the #1 and #2 seeds cannot meet before the finals, buildCrossSeedOrder unfolds pairings recursively via s -> [s, 2n + 1 - s], yielding [1, 8, 4, 5, 2, 7, 3, 6] for Top 8 and assigning BYE slots when a cut size is not an exact power of two.
2. Why Loss Timing Changes Tiebreaker Survival (OMW%, OOMW%, Σr²)
Swiss pairings match players with similar current records each round. Winning early rounds pairs you into stronger undefeated opponents in middle rounds, raising your OMW% floor (clamped per tournament floor, typically 0.33 in Magic). Conversely, Yu-Gi-Oh! regional events break ties by opponent strength and sum of squared loss round numbers (lossRoundSquares), rewarding late losses over early ones.
import { getPreset, simulate, probRankAtMost } from 'swiss-math';
const mtg = getPreset('mtg');
const earlyLoss = simulate({
preset: mtg,
players: 64,
drawRate: 0.05,
doubleLossRate: 0,
results: ['L', 'W', 'W', 'W', 'W', 'W'],
iterations: 300,
});
const lateLoss = simulate({
preset: mtg,
players: 64,
drawRate: 0.05,
doubleLossRate: 0,
results: ['W', 'W', 'W', 'W', 'W', 'L'],
iterations: 300,
});
console.log('Top 8 odds:', probRankAtMost(earlyLoss, 8), probRankAtMost(lateLoss, 8));
By fixing the PRNG seed via Mulberry32 inside simulate, tournament organizers can compare early-loss versus late-loss sequences reproducibly up to MAX_SIMULATED_PLAYERS = 4096.
3. Related Tournament & Gaming Tools
Explore the complete live suite on Sunasty: Swiss Cut & Tiebreak Calculator, Playoff Bracket Generator, Round Robin Scheduler, Elo Rating Calculator, Hypergeometric Draw Calculator, and Offline TCG Proxy Print Studio.
4. Open-Source Package Links
Published under the MIT license on npm (swiss-math), JSR (@sunasty/tournament-math), and GitHub.