If i understand the above algorithm correctly, it simply calculates the summed difference of rating per team for every possible team combination.
IF that is true, it does nothing in terms of position balancing and is exactly the same as auto-teams except its worse than that because it uses shown rating instead of game quality (i might be wrong though because recursive code is somewhat confusing to me).
Btw., even though i am a programmer, i don't like expressing ideas in code (even worse if its low-level C-like stuff). It means that non-programmers can't discuss it and it doesn't work if the algorithm us non-trivial.
Proposed Algorithm for for best position balancing:
Treat every position in game as 1v1 game. So, you just ask Trueskill for all game qualities of all possible one-vs-one for all members of the team. Example:
If there are four players (A, B, C, D) you get game qualities of:
AvB, AvC, AvD, BvC, BvD, CvD
(If teams are fixed like AB vs CD but you want to randomize positions only, just get: AvC, AvD, BvC, BvD)
Then you calculate squared sum of game quality for all possible team compositons,where a team compositon is a combination of 1v1s so that every players appears once per composition:
Compositon 1 Quality = (AvB + CvD)
Compositon 2 Quality = (AvC + BvD)
Compositon 3 Quality = (AvD + BvC)
and choose the one with highest quality. If you don't want to punish high differences, use sum instead of squared sum, simple. Then you put players that are in a 1v1 into opposing spots on map. Of course this only works for two teams of same size.
Edit: Example code:
https://gist.github.com/Katharsas/c2697 ... 1d7a549087