I have map of groups. Each groups have list of players:
Map<String, List<Player>> playerByGroup = new LinkedHashMap<String, List<Player>>();
for example:
map contains:
group A: players 1 2 3 4 5 6
group B: players 7 8 9 10 11 12
group C: players 13 14 15 16 17 18
group D: players 19 20 21 22 23 24
now I need to create schedule. Each player from every groups should be player with player from another group
for example:
player 1 should be player with player 7 – 24 but not with player 2 – 6
this isnt problem to create
But now I have problem:
I need to create round which contains numberOfPlayer/2 of games. In round every player can play just once
for example
1.round should be looks like:
1.game 1 vs 7
2.game 13 vs 19
3.game 3 vs 9
4.game 14 vs 20
5.game 2 vs 8
6.game 15 vs 21
7.game 4 vs 10
8.game 16 vs 22
9.game 5 vs 11
10.game 17 vs 23
11.game 6 vs 12
12.game 18 vs 24
2.round ...
there should be just 18 rounds because one player should play with 18 players.
PROBLEM:
Problem is to create just 18 rounds where in each round one player play just once
I will explain the answer for you example.
it’s easy to extend it for general situations.divide your rounds into three main set so we have 6 round in each set.
in the first set with six rounds:
all players of group A will play to all players of group B and all players of group C will play to all players of group D.
in the second set all players of group A will play to all players of group C and all players of group B will play to all players of group D.
in the third set all players of group A will play to all players of group D and all players of group B will play to all players of group C.