如何自动生成一个体育联赛赛程 [英] How to automatically generate a sports league schedule

查看:1301
本文介绍了如何自动生成一个体育联赛赛程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我会说,我明白,这个主题是复杂的,大概没有一个简单的答案启动。如果是简单的那么所有人都会做。话虽这么说......

I'll start of by saying that I understand that this topic is complicated and that there probably isn't an easy answer. If it were easy then everybody would be doing it. That being said...

我被要求构建一个应用程序来管理一个体育联盟。大多数的概念是非常容易理解的,除了这一个:如何生成的播放时间表那里有没有重叠(团队将2队一次),其中一支球队在一个部门发挥其团队两次,但在扮演球队其他部门一次,并确保有在时间表没有孔(每队每周饰演)

I've been asked to build an application to manage a sports league. Most of the concepts are fairly easy to understand except for this one: How to generate a schedule of play where there are no overlaps (team plays 2 teams at once), where a team in a division plays its teams twice but plays teams from the other divisions once, and makes sure that there are no holes in the schedule (each team plays every week)

现在的过程是人工完成用我建立的服务于这个目的的罗赛塔石碑S型$ P ​​$ padsheet,但它仅适用于团队它是专为数量。我有30支球队,24支球队和28支球队进行改变。而不是不断地尝试调整我的翻译表,我希望能够编纂的逻辑和调整的过程,而不是。

Right now the process is done manually using a rosetta stone type spreadsheet that I've built to serve this purpose, but it only works for the number of teams it was designed for. I have variations made for 30 teams, 24 teams and 28 teams. Rather than continually attempt to readjust my translation table, I'd like to be able to codify that logic and tweak that process instead.

思考?

推荐答案

有一个在例如使用pretty的直观系统象棋锦标赛所谓循环。

There is a pretty straightforward system used in e.g. chess tournaments called round-robin.

的想法是将玩家的表的双方。其中一个球员被指定为枢纽(对于一个更好的词一想)。在比赛开始通过让玩家面对彼此相互嬉戏。第一轮每个人,但轮毂的一招椅子向前和白/黑(家庭/客场体育)命令后切换。当玩家坐在原来的位置,整个循环比赛结束。如果你希望大家都来两次打大家只需再次做同样的。

The idea is to divide the players to the two sides of a table. One of the players is designated as a "hub" (for a want of a better word). The tournament starts by having players facing each other playing against each other. After the first round everyone but the hub move one chair forward and the white/black (home/away in sports) order is switched. The entire round-robin competition is finished when the players sit in their original places. If you want everyone to play everyone twice just do the same again.

维基百科的文章与实施细则。

在你的特殊情况下,我会尝试做循环赛一次包括所有的球队。然后,你做同样的每个部门一次,以确保团队内部在主场部门打对方一次又一次的路程,从第一轮循环赛队在这一轮发挥什么样的方式进行检查。

In your special case I would try doing the round robin once including all teams. Then you do the same for each division once and to make sure teams within divisions play each other once at home and once away, check from the first round robin what way the teams played in that round.

这样做的不利的方面是,当然,你将扮演的所有跨事业部的比赛结束前,匹配良好(自上次n-1个匹配反对内部分裂队[N =队划分数])。如果这是一个问题,你可以简单地交换匹配了一下周围。

The down-side of this is, of course, that you will play all inter-division matches well before the tournament finishes (since the last n-1 matches are against intra-division teams [n=number of teams in division]). If this is a problem you could simply swap matches around a bit.

其实,我写了,这是否一个简单的Python脚本。它没有采取code很多线和生产pretty的好成绩。这将创造一个各队起着各队在他们的分裂两次,一次对球队中其他部门的时间表。有没有检查,以确保球队却彼此相遇两次,以这样的方式,同样的球队是在主场。但是,这code应该就如何创建自己的日程安排code是个好主意。

I actually wrote a simple Python script that does this. It didn't take many lines of code and produced pretty good results. This will create a schedule where each team plays each team in their division twice and once against teams in other divisions. There is no check to make sure that the teams meet each other twice in such a way that the same team is at home, however. But this code should give a good idea on how to create your own scheduling code.

#!/usr/bin/python

div1 = ["Lions", "Tigers", "Jaguars", "Cougars"]
div2 = ["Whales", "Sharks", "Piranhas", "Alligators"]
div3 = ["Cubs", "Kittens", "Puppies", "Calfs"]

def create_schedule(list):
    """ Create a schedule for the teams in the list and return it"""
    s = []

    if len(list) % 2 == 1: list = list + ["BYE"]

    for i in range(len(list)-1):

        mid = len(list) / 2
        l1 = list[:mid]
        l2 = list[mid:]
        l2.reverse()    

        # Switch sides after each round
        if(i % 2 == 1):
            s = s + [ zip(l1, l2) ]
        else:
            s = s + [ zip(l2, l1) ]

        list.insert(1, list.pop())

    return s


def main():
    for round in create_schedule(div1):
        for match in round:
            print match[0] + " - " + match[1]
    print
    for round in create_schedule(div2):
        for match in round:
            print match[0] + " - " + match[1]
    print
    for round in create_schedule(div3): 
        for match in round:
            print match[0] + " - " + match[1]
    print
    for round in create_schedule(div1+div2+div3): 
        for match in round:
            print match[0] + " - " + match[1]
        print

if __name__ == "__main__":
    main()

这篇关于如何自动生成一个体育联赛赛程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆