0

我在这里使用了一些帖子来创建一个使用 JavaScript 和 Jquery 来显示括号的锦标赛括号系统。

我有 16 支球队 1-16 号种子。目前我排序的种子如下:

[1,8],[4,5],[2,7],[3,6]

如您所见,它在某种程度上有效,但半决赛将是 1v4 和 2v3,这是不正确的。我希望半决赛是 1v3 和 2v4,但无论我尝试什么,我似乎都无法将其打印出来。所以应该是:

[1,8],[3,6],[5,4],[7,2]

这也使得当您查看纸上的括号时,1 和 2 在括号的两端是正确的,但无论我尝试什么,它都不起作用。

编辑:我也希望这适用于更多团队,因此是 16/32 团队锦标赛,但是当我尝试使用此算法时,我似乎根本没有得到正确的种子。

这是我的代码:

var seeds = [ 1,2,3,4,5,6,7,8],
    num_rounds = Math.log(seeds.length) / Math.log(2);

// 2-dimensional array
// Each subarray holds the seeds active in that round in order of matches played
// Example:
// seeds in first match of 2nd round are: bracket_round[1][0] & bracket_round[1][1]
var bracket_round = [];

// Create empty arrays inside bracket_round
for(var i = 0; i < num_rounds; i++) {
  bracket_round[i] = [];
}

// Assuming no upsets
// Final is seed 1 and seed 2
bracket_round[num_rounds] = [ seeds[0], seeds[1] ];

// For each round in the bracket
for(var roundNum = num_rounds; roundNum > 0; roundNum--) {
  var round = bracket_round[roundNum];
  var prev_round = bracket_round[roundNum - 1];

  // For each seed in the round, work out who they defeated in previous round, storing result
  for(var m = 0; m < round.length; m++) {
    // round.length = number of matches in the round
    // number of teams in the round will be, number of matches * 2
    var num_teams_in_round = round.length * 2;

    // previous match team A = current match team "m"
    prev_round[m * 2] = round[m];

    // previous match team  B = (# teams in previous round + 1) - (current match seed "m")
    prev_round[(m * 2) + 1] = (num_teams_in_round + 1) - round[m];
  }
}

document.write(bracket_round[1]);

var singleElimData = {
    teams : [              // Matchups
        [ bracket_round[1][0], bracket_round[1][1] ],
    [ bracket_round[1][2], bracket_round[1][3] ],
    [ bracket_round[1][4], bracket_round[1][5] ],
    [ bracket_round[1][6], bracket_round[1][7] ]
  ],
  results : [[
      [ [1, 0], [1, 0], [1,0], [1, 0] ],
      [ [1, 0], [1, 0] ],
      [ [1, 0], [0, 1] ]
    ]
  ]
}

$(function() {
    $('#singleElim').bracket({
        init: singleElimData
    })
})

1 = 0001    0001 = 1
2 = 0010    0011 = 3
3 = 0011    0010 = 2
4 = 0100    0110 = 6
5 = 0101    0111 = 7
6 = 0110    0101 = 5
7 = 0111    0100 = 4
8 = 1111    1000 = 8
4

1 回答 1

0

创建树时,您可以使用格雷码来确定哪条边是玩家。基本上它是反转位并添加 1。阅读此处:http ://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/229068 。

于 2012-12-19T19:26:49.887 回答