Tournament bracket placement algorithm

前端 未结 10 637
生来不讨喜
生来不讨喜 2020-12-02 09:37

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

10条回答
  •  佛祖请我去吃肉
    2020-12-02 10:05

    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 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]
    

提交回复
热议问题