Skip to content

Instantly share code, notes, and snippets.

@safoyeth
Created March 24, 2017 03:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save safoyeth/83bf504174ff0b401ae508c243bfe5be to your computer and use it in GitHub Desktop.
Save safoyeth/83bf504174ff0b401ae508c243bfe5be to your computer and use it in GitHub Desktop.
This script generates the circle system schedule
def circle(*players):
'''
you can find the description here https://safoyeth.com/2017/03/04/chessscripts/
'''
if isinstance(players, tuple):
players = list(players)
if not len(players) % 2 == 0:
players.append(None)
result = [[["", ""] for _ in range(int(len(players)/2))] for i in range(int(len(players)-1))]
for each in result:
if result.index(each) % 2 == 0:
each[0][1] = players[-1]
else:
each[0][0] = players[-1]
i = 0
for tour in result:
for game in tour:
if game[0] == "":
game[0] = players[i]
if i < len(players)-2:
i += 1
else:
i = 0
else:
game[1] = players[i]
if i < len(players)-2:
i += 1
else:
i = 0
players.pop(-1)
i = len(players)-1
for tour in result:
for game in tour:
if game[0] == "":
if not game[1] == players[i]:
game[0] = players[i]
if i >= 1:
i -= 1
else:
i = len(players) - 1
if game[1] == "":
if not game[0] == players[i]:
game[1] = players[i]
if i >= 1:
i -= 1
else:
i = len(players) - 1
return tuple(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment