I'm trying to program a multiple players game in Java.
I need to create a list of all combinations and to store these in an array.
If 2 players are logged in as the game start, the combinations are: p1,p2 and p2, p1 (positions are important)
while if 3 players logged in to the game, the combinations are: p1,p2,p3 ; p1,p3,p2 ; p2,p1,p3 ; p2,p3,p1 ; p3,p1,p2 and p3,p2,p1
In fact, I need a redundant array: if 3 players are logged in, I need in advance the combinations of 3 AND the combinations of each possible pairs p1,p2,p3 ; p1,p3,p2 ; p2,p1,p3 ; p2,p3,p1 ; p3,p1,p2 and p3,p2,p1 and p1,p2 and p2, p1 and p1,p3 and p3, p1 and p2,p3 and p3, p2 )
Many players (EDITED: up to 8 players) may be logged in simultaneously to the same round of the game. (EDITED: there are up to 32 groups, but this is not important, because groups are independent)
Is there a quick, short and a simple way to create this combinations array for n players?
A recursive solution is foreseen and acceptable.
Many thanks
P.S.
My ongoing idea is to split the group into 2, a selected pair and the rest of the players. The sekected pairs are selected using 2 FOR loops and the rest with a third. If there are 2 players, no 'rest". If there are 3 players, the 2 FORs will select the positions of the pair and the rest will get the rest. then, the rest are ordered using the same split procedure. May this way get real? how? Will it be efficient? Thanks again.