change the shuffle logic

This commit is contained in:
Beu 2023-07-12 12:16:23 +02:00
parent c59cc3f3d6
commit d89ee0739e

View File

@ -278,22 +278,20 @@ declare Integer LandmarkIndex for This = 0;
AccountIdsOfPlayers = []; AccountIdsOfPlayers = [];
// Suffle Players list to randomise spawn // Suffle Players list to randomise spawn
declare CSmPlayer[] ShuffledPlayers = Players; declare CSmPlayer[Integer] ShuffledPlayers;
declare Integer i=0;
while(i<ShuffledPlayers.count) { // this should be enough, you can use arbitrary values, should the need arise
// find a pair (a,b) of valid indices to swap
declare a=ML::Rand(0, ShuffledPlayers.count-1);
declare b=ML::Rand(0, ShuffledPlayers.count-1);
// now swap them foreach (Player in Players) {
declare tmp=ShuffledPlayers[b]; declare Integer RandomIndex = 0;
ShuffledPlayers[b]=ShuffledPlayers[a]; while (RandomIndex == 0 || ShuffledPlayers.existskey(RandomIndex)) {
ShuffledPlayers[a]=tmp; RandomIndex = ML::Rand(1, 10000);
}
i=i+1; ShuffledPlayers[RandomIndex] = Player;
} }
ShuffledPlayers = ShuffledPlayers.sortkey();
foreach (Player in ShuffledPlayers) { foreach (Player in ShuffledPlayers) {
if (Player == Null) continue;
PlayerLM = Null; PlayerLM = Null;
while (PlayerLM == Null) { while (PlayerLM == Null) {
if (LandmarkIndex > Landmarks.count - 1 ) { if (LandmarkIndex > Landmarks.count - 1 ) {