Fixed shuffle algorithm.

This commit is contained in:
LevelX2 2017-05-09 17:01:46 +02:00
parent c731a10360
commit d1fd69f685

View file

@ -27,16 +27,15 @@
*/ */
package mage.players; package mage.players;
import java.io.Serializable;
import java.util.*;
import java.util.stream.Collectors;
import mage.cards.Card; import mage.cards.Card;
import mage.constants.Zone; import mage.constants.Zone;
import mage.filter.FilterCard; import mage.filter.FilterCard;
import mage.game.Game; import mage.game.Game;
import mage.util.RandomUtil; import mage.util.RandomUtil;
import java.io.Serializable;
import java.util.*;
import java.util.stream.Collectors;
/** /**
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
*/ */
@ -64,7 +63,7 @@ public class Library implements Serializable {
public void shuffle() { public void shuffle() {
UUID[] shuffled = library.toArray(new UUID[0]); UUID[] shuffled = library.toArray(new UUID[0]);
for (int n = shuffled.length - 1; n > 0; n--) { for (int n = shuffled.length - 1; n > 0; n--) {
int r = RandomUtil.nextInt(n); int r = RandomUtil.nextInt(n + 1);
UUID temp = shuffled[n]; UUID temp = shuffled[n];
shuffled[n] = shuffled[r]; shuffled[n] = shuffled[r];
shuffled[r] = temp; shuffled[r] = temp;
@ -235,7 +234,6 @@ public class Library implements Serializable {
return null; return null;
} }
public boolean hasCards() { public boolean hasCards() {
return size() > 0; return size() > 0;
} }