Fixes inefficient shuffle algorithm.

Note that shuffling 13 times in a row is not necessary. Collections.shuffle will produce every possible shuffle with equal probability already.
This commit is contained in:
Meerkov
2018-04-16 20:40:20 -07:00
parent 130fc4ee18
commit 645d70e6ce

View File

@@ -1608,26 +1608,8 @@ public class Player extends GameEntity implements Comparable<Player> {
return; return;
} }
// overdone but wanted to make sure it was really random // Note: Shuffling once is sufficient.
final Random random = MyRandom.getRandom(); Collections.shuffle(list, MyRandom.getRandom());
Collections.shuffle(list, random);
Collections.shuffle(list, random);
Collections.shuffle(list, random);
Collections.shuffle(list, random);
Collections.shuffle(list, random);
Collections.shuffle(list, random);
int s = list.size();
for (int i = 0; i < s; i++) {
list.add(random.nextInt(s - 1), list.remove(random.nextInt(s)));
}
Collections.shuffle(list, random);
Collections.shuffle(list, random);
Collections.shuffle(list, random);
Collections.shuffle(list, random);
Collections.shuffle(list, random);
Collections.shuffle(list, random);
getZone(ZoneType.Library).setCards(getController().cheatShuffle(list)); getZone(ZoneType.Library).setCards(getController().cheatShuffle(list));