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
Since this is round-robin, everybody plays against everybody, so the round-robin algorithm that decides the order of the matches can be independent from the function that determines whether player
ior playerjstarts wheniplays againstj.So, just paint the table you use for results in a checkerboard pattern:
Here the arrow points to the start player. This means that 0 starts when playing against 1, but is second when playing against 2, etc.
Turning this into an arithmetic formula:
When
iplays againstj, ifi < j, thenistarts iffj-iis odd.(Note: you can replace
j-iwithi+jin the above formula if you want; because+iand-ihave the same parity.)