Consider different groups(1 or more players) queuing together,
we want to make 2 opposing teams containing each the same amount of players while keeping the groups together. At the same time we want to make both teams' average ranking as close as possible.
Now also consider we have as a working set the subset of groups currently queuing within a given ranking range.
For an example, let's say we have the following groups, ordered by queuing time:
Id, playerCount, totalRank, avgRank
0, 3, 126, 42
1, 2, 60, 30
2, 1, 25, 25
3, 2, 80, 40
4, 1, 40, 40
5, 1, 20, 20
6, 3, 150, 50
for this specific subset, the expected output should ideally be:
team1: 0, 1 (total: 186)
team2: 2, 5, 6 (total: 195)
up to now the solution I have been using is to balance out each team by making each team pick the group with highest ranking within the subset turn by turn. The team who picks is the one with the currently lowest average rank unless one is already full. If one team is already full the other team tries to complete itself with groups that would make the rank gap as small as possible.
This solution turns out to have issues with frequent edge cases and I'm looking for a better solution, or some fine-tuning that could be made.
In most cases, players seems to want teams of 5 people and queue in group of 2. Our average subset when 2 teams of 5 are chosen is made of about 14 players if that may be of any help.