今日已更新 457 条资讯 | 累计 41677 条内容
关于我们

How to Generate a Single-Elimination Bracket When the Player Count Is Not a Power of Two

Joe Lin 2026年09月10日 21:00 0 次阅读 来源:Dev.to

Tournament brackets look like a list of matchups until the participant count is 6, 10, or 14. Then the missing slots need BYEs, seeds need a consistent distribution, and later rounds must wait for actual winners. I built this generator to make those rules visible instead of asking an organizer to fill gaps by hand. The interesting implementation problem is not drawing boxes; it is keeping identity, seeding, and progression correct when the tree is incomplete. Normalize names before creating matches The input accepts newlines, commas, and their full-width variants. Trimming and a Set remove duplicate tokens: const namesList = computed (() => { const tokens = rawNames . value . split ( / [\n ,,;; ] +/g ) . map (( s ) => s . trim ()) . filter ( Boolean ); return [... new Set ( tokens )]; }); The delimiter regex means a pasted list such as Ada, Ben;Cara becomes three names. Empty lines and accidental spaces disappear before bracket math starts. Set preserves the first occurrence while removing exact duplicate strings. That is a product decision as much as a parsing detail: two real players with the same name must add a team name or number themselves, or the generator cannot distinguish them. Generation refuses fewer than two distinct names. That is better than drawing a one-person “final” and pretending it is a tournament. The original participant list remains text until generation, so editing the textarea does not unexpectedly mutate a bracket that people may already be using. Build the next power-of-two bracket and place BYEs Single-elimination trees are easiest to represent when the first round has a power-of-two number of slots. The helper finds that size: function nextPowerOfTwo ( n ) { let size = 1 ; while ( size < n ) size *= 2 ; return size ; } function seedOrder ( size ) { let order = [ 1 , 2 ]; while ( order . length < size ) { const nextSize = order . length * 2 ; order = order . flatMap (( seed ) => [ seed , nextSize + 1 - seed ]); } return order . slice ( 0

本文内容来源于互联网,版权归原作者所有
查看原文