mirror of
https://github.com/correl/mage.git
synced 2025-01-11 19:13:02 +00:00
Fixed shuffle algorithm.
This commit is contained in:
parent
c731a10360
commit
d1fd69f685
1 changed files with 4 additions and 6 deletions
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue