所以我有 3 到 8 个玩家,我希望每个人都与其他人进行 1 对 1 的比赛。 比赛按顺序进行,一次一场。 一对中的顺序并不重要(a vs b == b vs a)。
我在一个简单的嵌套循环中创建对战对,在这个循环中我遍历玩家并将当前索引与以下所有索引配对。
问题是玩家 1 将完成所有比赛,然后无事可做,而玩家 8 则必须等待。
有没有什么办法可以平均分配对数,让所有玩家的停机时间均等?
我目前正在随机化包含对的数组,但我正在寻找更好的方法。
最佳答案
您可以使用 Round-robin tournament scheduling algorithm .
The circle method is the standard algorithm to create a schedule for a round-robin tournament. All competitors are assigned to numbers, and then paired in the first round:
Round 1. (1 plays 14, 2 plays 13, ... )
1 2 3 4 5 6 7 14 13 12 11 10 9 8
then fix one of the contributors in the first or last column of the table (number one in this example) and rotate the others clockwise one position
Round 2. (1 plays 13, 14 plays 12, ... )
1 14 2 3 4 5 6 13 12 11 10 9 8 7
Round 3. (1 plays 12, 13 plays 11, ... )
1 13 14 2 3 4 5 12 11 10 9 8 7 6
until you end up almost back at the initial position
Round 13. (1 plays 2, 3 plays 14, ... )
1 3 4 5 6 7 8 2 14 13 12 11 10 9
关于algorithm - 从列表中的元素创建所有可能的对,然后对它们进行均匀排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44944568/