Given a list of opponent seeds (for example seeds 1 to 16), I'm trying to write an algorithm that will result in the top seed playing the lowest seed in that round, the 2nd seed playing the 2nd-lowest seed, etc.
Grouping 1 and 16, 2 and 15, etc. into "matches" is fairly easy, but I also need to make sure that the higher seed will play the lower seed in subsequent rounds.
An example bracket with the correct placement:
1 vs 16 1 vs 8 8 vs 9 1 vs 4 4 vs 13 4 vs 5 5 vs 12 1 vs 2 2 vs 15 2 vs 7 7 vs 10 2 vs 3 3 vs 14 3 vs 6 6 vs 11
As you can see, seed 1 and 2 only meet up in the final.
Most of the brackets are numbered in the order the matches will be played. This can be viewed in the illustration below. If they are not numbered, start at the top left and work your way down until the first round is complete, then move to the next row(2nd round) and work from top to bottom.
As the term is generally used, a competitor is said to have been "seeded" when that competitor has been ranked and placed on the bracket according to his/her "seed." The remaining competitors on the bracket who have not been ranked are said to be "unseeded" and are placed on the bracket in a random fashion.
How does it work? A tournament bracket pits an even number of teams in several rounds of games until there's only one team standing. A bracket contains a minimum of four games,, but usually the tournament field contains many more teams.
In an one hundred twenty eight-team tournament field, half the teams are eliminated at each stage until only one team is left. Here's what an 128-team blank bracket looks like on two pages/images: Due to the amount of teams, we offer the bracket in two layouts.
This JavaScript returns an array where each even index plays the next odd index
function seeding(numPlayers){ var rounds = Math.log(numPlayers)/Math.log(2)-1; var pls = [1,2]; for(var i=0;i<rounds;i++){ pls = nextLayer(pls); } return pls; function nextLayer(pls){ var out=[]; var length = pls.length*2+1; pls.forEach(function(d){ out.push(d); out.push(length-d); }); return out; } } > seeding(2) [1, 2] > seeding(4) [1, 4, 2, 3] > seeding(8) [1, 8, 4, 5, 2, 7, 3, 6] > seeding(16) [1, 16, 8, 9, 4, 13, 5, 12, 2, 15, 7, 10, 3, 14, 6, 11]
With your assumptions, players 1 and 2 will play in the final, players 1-4 in the semifinals, players 1-8 in the quarterfinals and so on, so you can build the tournament recursively backwards from the final as AakashM proposed. Think of the tournament as a tree whose root is the final.
In the root node, your players are {1, 2}.
To expand the tree recursively to the next level, take all the nodes on the bottom layer in the tree, one by one, and create two children for them each, and place one of the players of the original node to each one of the child nodes created. Then add the next layer of players and map them to the game so that the worst newly added player plays against the best pre-existing player and so on.
Here first rounds of the algorithm:
{1,2} --- create next layer {1, _} / --- now fill the empty slots {1,2} \{2, _} {1, 4} --- the slots filled in reverse order / {1,2} \{2, 3} --- create next layer again /{1, _} {1, 4} / \{4, _} {1,2} --- again fill \ /{2, _} {2, 3} \{3, _} /{1, 8} {1, 4} / \{4, 5} --- ... and so on {1,2} \ /{2, 7} {2, 3} \{3, 6}
As you can see, it produces the same tree you posted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With