lorchess/great12/roundrobin.py

47 lines
1.1 KiB
Python
Raw Normal View History

2013-04-21 22:39:59 +04:00
#!/usr/bin/python2
# -*- coding: utf-8 -*-
def roundRobin(units, sets=None):
""" Generates a schedule of "fair" pairings from a list of units """
if len(units) % 2:
units.append(None)
count = len(units)
sets = sets or (count - 1)
half = count / 2
schedule = []
for turn in range(sets):
pairings = []
for i in range(half):
pairings.append((units[i], units[count-i-1]))
units.insert(1, units.pop())
schedule.append(pairings)
return schedule
# LOR sheduler
2013-04-28 23:32:52 +04:00
players = [
"HunOL",
"snoopcat",
"Michkova",
"trex6",
"Komintern",
"William",
"J",
"shell-script",
"Zodd",
"raven_cler",
2013-05-31 19:36:22 +04:00
"aptyp",
2013-04-28 23:32:52 +04:00
"Debasher"
]
2013-04-21 22:39:59 +04:00
tour_count = 0
# Generate LORCODE for pairings.
# Also generate "reversal" for autumm season.
for pairings in roundRobin(players):
tours = (len(players) - 1) * 2
tour_count = tour_count + 1
print "[b]Тур" + str(tour_count) + "[/b]"
print "[list]"
for pair in pairings:
2013-04-28 23:32:52 +04:00
print "[*][user]" + pair[0] + "[/user] играет против [user]" + pair[1] + "[/user]"
2013-04-21 22:39:59 +04:00
print "[/list]"