I have 5 arrays. I want to combine these 5 arrays and then shuffle them respectively.
I'm using the Fisher-Yates shuffle method.
The code:
for (let i = 0; i < numPlayersIsNumLoops; i++) {
movePlayerToTeam = maxPlayers.shift();
cmpPlayer = QueryPlayerIDInterface(movePlayerToTeam);
playerTeam = cmpPlayer.GetTeam(movePlayerToTeam);
playerTeam = playerTeam+1;
if (playerTeam == 0) {
team0.push(movePlayerToTeam);
}if (playerTeam == 1) {
team1.push(movePlayerToTeam);
} if (playerTeam == 2) {
team2.push(movePlayerToTeam);
} if (playerTeam == 3) {
team3.push(movePlayerToTeam);
} if (playerTeam == 4) {
team4.push(movePlayerToTeam);
}
}
/* Positions inside teams also gets shuffled to further reduce the chance of
getting the same spot on subsequent playthroughs (also this way you never know who is next to you) */
if (numPlayers === 8) {
team0 = shuffleArray(team0);
team1 = shuffleArray(team1);
team2 = shuffleArray(team2);
team3 = shuffleArray(team3);
team4 = shuffleArray(team4);
playersShuffledAsTeams = playersShuffledAsTeams.concat(team1, team2, team3, team4, team0); // this is what i want shuffled aswell
The last line of code is what i want to shuffle.
The results i'm aiming for is something like this after a shuffle:
(team2, team0, team1, team3, team4) or (team0, team3, team1, team2, team4)
The solution with the answer below is:
playersShuffledAsTeams = playersShuffledAsTeams.concat(team1, team2, team3, team4, team0);
playersShuffledAsTeams = shuffleArray([team0, team1, team2, team3, team4]);