从池中选择国际象棋棋手 - 算法
你好,我有这个问题
有 n[偶] 名玩家想要下棋
我怎样才能随机化玩家和对手? [每个玩家只有一次机会]
认为有 6 个玩家 - p1,p2,p3,p4,p5,p6
我想做一个代码来为我完成这样的例程
p1 与 p5
p2 与 p6
p3 与 p4
Hii, i have this problem
There are n[even] number of players who want to play chess
How can i get randomize player and opponents ? [every player will get only one chance]
Think there are 6 player - p1,p2,p3,p4,p5,p6
I want to do a code which will do such routine for me
p1 vs p5
p2 vs p6
p3 vs p4
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以为每个玩家分配一个唯一的随机数,使用该数字对玩家列表进行排序,并选择 1-2、3-4、5-6 等对。应该非常快,因为现在几乎每种语言都有内置排序。
You can assign a unique random number to every player, sort the player list using that number and select pairs 1-2, 3-4, 5-6 and so on. Should be very fast because of built-in sorting that almost every language has now.
执行所有组合并随机播放Fisher-Yates
Do all combinations and shuffle them Fisher-Yates