DEV Community

Bastien Sulyan
Bastien Sulyan

Posted on Edited on Originally published at bsulyan.github.io

Swiss Tournament Tiebreakers & Binomial Cut Math in Pure JavaScript

During large card game and esports tournaments, players want to know two numbers mid-event: how many players with X-2 records make Top 8, and why an early Round 1 loss behaves differently in tiebreakers than a final-round loss.

We packaged the pure mathematical engine behind the Sunasty Tournament Calculator and Swiss Tournament Generator as the zero-dependency MIT library swiss-math on npm and JSR (@sunasty/tournament-math).

1. Exact Win-Loss Field Projection & Cross-Seeded Brackets

When draw rate is non-zero, exact binomial buckets shift because intentional or natural draws modify total points. computeStructure handles draw convolution and generates standard cross-seeded playoff brackets (1v8, 4v5, 2v7, 3v6) with automatic BYE slots:

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, 8
console.log(exportBracketText(structure.cutSize));
Enter fullscreen mode Exit fullscreen mode

2. Reproducible Monte-Carlo OMW% / OOMW% / Loss-Round Simulation

In Swiss pairings, Round 1 losers face weaker Round 2 opponents than undefeated players do, shifting final Opponent Match Win percentage (OMW%). Meanwhile, systems using squared loss rounds (lossRoundSquares) penalize late losses differently. Using Mulberry32 seeded PRNG simulation across up to 4096 players, simulate quantifies tiebreak odds deterministically:

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,
});

console.log('Top 8 probability:', probRankAtMost(earlyLoss, 8));
Enter fullscreen mode Exit fullscreen mode

Related Web Tools & Packages

Top comments (0)