This is a problem similar to others which are asked a lot but I can't quite find anything matching what I'm trying to achieve.
In my scenario, a team is made up of 5 players, represented by this class:
class Team
{
int ID {get; set;}
List<Player> Players { get; set; } = new List<Player>();
}
And my Player
class looks like this:
class Player
{
string Name { get; set; }
}
From my database I get a List<Player>
containing every available player (guaranteed to be unique). I ensure I only get as many as I can get into complete teams (e.g. maximumPlayers = numberPlayers / 5;
).
At the moment I can easily loop through the List<Player>
and assign each Player
one to a Team
and create a new Team
every 5 players (maximum team size). I put these teams into a List<Team>
.
I want to create every combination of List<Team>
where the players are in different combinations of teams different, excluding where it's the same players in a different order. The intention is to put them into a List<List<Team>>
for later evaluation.
How could I do this?