I'm quite familiar with how round robin works, now I'm trying to implement a function (Python works fine) to create round-robin matchings accounting for how many times during the tournament a player plays first.
Ideally, I would like to have everybody begin the same (±1 if even players) number of turns and have the function telling me that, without me making the adjustments manually.
Edit: this is my attempt so far, creating a discriminant to "randomize" somehow the first player, but in doesn't work in general
import random
def get_rr_rounds(players):
"""
players = ["Player1", "Player2", "Player3","Player4", "Player5", "Player6"]
"""
if len(players) % 2:
players.append('DUMMY')
n = len(players)
matchs = []
rounds = []
discriminant = random.choice([0, 1])
for round in range(1, n):
for i in range(n//2):
if (round % 2 == discriminant):
matchs.append((players[i], players[n - 1 - i]))
else:
matchs.append((players[n - 1 - i], players[i]))
players.insert(1, players.pop())
rounds.append(matchs)
matchs = []
return rounds