I have an array of players (string[]) and now I need to get an array of pairs representing games (playerN-playerM) to orginize tournament table like at this picture:
The implementation I really wanted:
public static List>> ListMatches(List listTeam)
{
var result = new List>>();
int numDays = (listTeam.Count - 1);
int halfSize = listTeam.Count / 2;
var teams = new List();
teams.AddRange(listTeam.Skip(halfSize).Take(halfSize));
teams.AddRange(listTeam.Skip(1).Take(halfSize - 1).ToArray().Reverse());
int teamsSize = teams.Count;
for (int day = 0; day < numDays; day++)
{
var round = new List>();
int teamIdx = day % teamsSize;
round.Add(new Tuple(teams[teamIdx], listTeam[0]));
for (int idx = 1; idx < halfSize; idx++)
{
int firstTeam = (day + idx) % teamsSize;
int secondTeam = (day + teamsSize - idx) % teamsSize;
round.Add(new Tuple(teams[firstTeam], teams[secondTeam]));
}
result.Add(round);
}
return result;
}