Pleas Refer this link which described Round Robin Algorithm for "Odd-Number of teams" as well as "Even-Number of teams".
Ref this link:- https://nrich.maths.org/1443
1) Odd Number of teams :-
For Odd number of teams, Consider following formulas and conditions
Abbreviations :-
TNR = Total Number Of Rounds
NOT = Number Of Teams
MPR = Match Per Round
Formulas :-
Total Number Of Rounds = Number Of Teams
Match Per Round = [ ( Number Of Teams - 1 ) / 2 ]
Conditions :- There must be only one team in round, which gets bye(would not play game). So each round has only one bye and each team will play once in round with other team.
Lets consider this algorithm's implementation in c# (Odd-Number Of Teams)
Suppose we have 5 Teams
Teams :-
Barcilona (0)
Brazil (1)
Madrid (2)
Colambo (3)
Woshington DC (4)
Here ,
Number Of Teams (NOT)= 5
Total Number Of Rounds (TNR) = 5
Matches Per Round (MPR) = [ ( NOT - 1 ) / 2 ] = [ ( 5 - 1 ) /2 ] = 2
Now Conside the link in which each round has one team which gets bye, and other team play once in round with another team.
now put all teams in array named Teams
int[] teams = new int[NOT];
so, int[] teams = new int[5];
now teams = [0,1,2,3,4]
now we will rotate array by 1 step left while moving on next round and teams[0] will always gets By and play games between other team but the problem is that how we can decide which team plays game with which team. so to resolve those issue, refere Reference Link. So you can identify that In round 0, matched will be played with following teams
Teams[0] = 0 = Barcilona Gets Bye(Not played game)
Teams[1] - Teams[4] = (Brazil - Woshington DC)
Teams[2] - Teams[3] = (Madrid - Colambo)
so, consider the following implementation
public class Teams {
public int Team1 { get; set; }
public int Team2 { get; set; }
}
//Dictionary< round , matches >
var matchScheduling = new Dictionary<int, List<Teams>>();
for (int round = 0; round < TNR; round++) {
List<Teams> matches = new List<Teams>();
int team1 = teams[0];
int team2 = -1;
matches.Add(new Teams() { Team1 = team1, Team2 = team2 });
for (int match = 0; match < MPR; match++) {
team1 = teams[match + 1];
team2 = teams[(NOT.Length - 1) - match];
roundTeams.Add(new Teams() { Team1 = team1, Team2 = team2 });
}
matchScheduling.Add(round, roundTeams);
//Now for next round, Rotate team Array
int length = teams.Length;
int tmp = teams[length - 1];
for (int i = length - 1; i > 0; i--) {
teams[i] = teams[i - 1];
}
teams[0] = tmp;
}