认为有6名球员 - p1,p2,p3,p4,p5,p6
我想做一个代码,它会为我做这样的常规
p1 vs p5
p2 vs p6
p3 vs p4
答案 0 :(得分:2)
您可以为每个玩家分配一个唯一的随机数,使用该数字对玩家列表进行排序,然后选择1-2,3-4,5-6对等等。应该非常快,因为几乎每种语言都有内置的排序。
答案 1 :(得分:1)
执行all combinations并随机播放Fisher-Yates
答案 2 :(得分:0)
store players in array a of size n
let p be a pair(w, b)
let l be a list of pairs
while n > 0
let x be a random number between 0 and n
add player at index x in a to p as w
remove index x from a
n--
let y be a random number between 0 and n
add player at index y in a to p as b
remove index y from a
n--
add p to l
endwhile