shuffle => CardListUtil as static

This commit is contained in:
Maxmtg
2012-10-01 21:23:04 +00:00
parent 2c980c78e5
commit 1b4b4bb138
13 changed files with 38 additions and 33 deletions

View File

@@ -46,19 +46,6 @@ public class CardList extends ArrayList<Card> {
public CardList(final Iterable<Card> al) { for(Card c : al) this.add(c); }
/**
* <p>
* shuffle.
* </p>
*/
public final void shuffle() {
// reseed Random each time we want to Shuffle
// MyRandom.random = MyRandom.random;
Collections.shuffle(this, MyRandom.getRandom());
Collections.shuffle(this, MyRandom.getRandom());
Collections.shuffle(this, MyRandom.getRandom());
}
/**
* Create a new list of cards by applying a filter to this one.
*

View File

@@ -19,11 +19,13 @@ package forge;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import com.google.common.base.Predicate;
import forge.card.cardfactory.CardFactoryUtil;
import forge.util.Aggregates;
import forge.util.MyRandom;
/**
@@ -275,10 +277,22 @@ public class CardListUtil {
final CardList subList = new CardList();
while (subList.size() < amount) {
c.shuffle();
CardListUtil.shuffle(c);
subList.add(c.get(0));
c.remove(0);
}
return subList;
}
/**
* TODO: Write javadoc for this method.
* @param cardList
*/
public static void shuffle(List<Card> list) {
// reseed Random each time we want to Shuffle
// MyRandom.random = MyRandom.random;
Collections.shuffle(list, MyRandom.getRandom());
Collections.shuffle(list, MyRandom.getRandom());
Collections.shuffle(list, MyRandom.getRandom());
}
}

View File

@@ -194,7 +194,7 @@ public final class GameActionUtil {
}
}
}
revealed.shuffle();
CardListUtil.shuffle(revealed);
for (final Card bottom : revealed) {
Singletons.getModel().getGameAction().moveToBottomOfLibrary(bottom);
}
@@ -323,7 +323,7 @@ public final class GameActionUtil {
}
}
}
revealed.shuffle();
CardListUtil.shuffle(revealed);
for (final Card bottom : revealed) {
Singletons.getModel().getGameAction().moveToBottomOfLibrary(bottom);
}

View File

@@ -30,6 +30,7 @@ import forge.AllZone;
import forge.AllZoneUtil;
import forge.Card;
import forge.CardList;
import forge.CardListUtil;
import forge.CardPredicates.Presets;
import forge.CardUtil;
import forge.Command;
@@ -368,7 +369,7 @@ public class AbilityFactoryAttach {
Card c = AbilityFactoryAttach.attachGeneralAI(sa, list, mandatory, attachSource, params.get("AILogic"));
if ((c == null) && mandatory) {
list.shuffle();
CardListUtil.shuffle(list);
c = list.get(0);
}

View File

@@ -1169,7 +1169,7 @@ public final class AbilityFactoryChangeZone {
} else if (defined) {
c = fetchList.get(0);
} else {
fetchList.shuffle();
CardListUtil.shuffle(fetchList);
// Save a card as a default, in case we can't find anything suitable.
Card first = fetchList.get(0);
if (ZoneType.Battlefield.equals(destination)) {
@@ -1830,7 +1830,7 @@ public final class AbilityFactoryChangeZone {
}
if (choice == null) {
// No creatures or spells?
list.shuffle();
CardListUtil.shuffle(list);
choice = list.get(0);
}
} else {
@@ -1943,7 +1943,7 @@ public final class AbilityFactoryChangeZone {
}
if (choice == null) {
// No creatures or spells?
list.shuffle();
CardListUtil.shuffle(list);
choice = list.get(0);
}
} else {

View File

@@ -32,6 +32,7 @@ import forge.AllZoneUtil;
import forge.Card;
import forge.CardCharacteristicName;
import forge.CardList;
import forge.CardListUtil;
import forge.CardPredicates;
import forge.CardPredicates.Presets;
import forge.CardUtil;
@@ -126,7 +127,7 @@ public class CardFactoryCreatures {
return (c.sumAllCounters() > 0);
}
});
perms.shuffle();
CardListUtil.shuffle(perms);
this.setTargetCard(perms.get(0)); // TODO improve this.
}
@@ -653,14 +654,14 @@ public class CardFactoryCreatures {
return c.hasKeyword("Indestructible");
}
});
indestructibles.shuffle();
CardListUtil.shuffle(indestructibles);
indestructibles.get(0).addDamage(1, target);
}
// Then just add Damage randomnly
else {
damageableWolves.shuffle();
CardListUtil.shuffle(damageableWolves);
wolves.get(0).addDamage(1, target);
}
}
@@ -743,7 +744,7 @@ public class CardFactoryCreatures {
this.setTargetPlayer(AllZone.getHumanPlayer());
} else {
final CardList list = this.getCreature();
list.shuffle();
CardListUtil.shuffle(list);
this.setTargetCard(list.get(0));
}
} // chooseTargetAI()

View File

@@ -619,7 +619,7 @@ public class CardFactorySorceries {
final CardList compLand = AllZoneUtil.getPlayerLandsInPlay(AllZone.getComputerPlayer());
if (compLand.size() > humLand.size()) {
compLand.shuffle();
CardListUtil.shuffle(compLand);
for (int i = 0; i < (compLand.size() - humLand.size()); i++) {
Singletons.getModel().getGameAction().sacrifice(compLand.get(i), this);
}

View File

@@ -26,6 +26,7 @@ import forge.AllZone;
import forge.AllZoneUtil;
import forge.Card;
import forge.CardList;
import forge.CardListUtil;
import forge.CardPredicates;
import forge.Command;
import forge.CommandReturn;
@@ -107,7 +108,7 @@ public class SpellPermanent extends Spell {
computer = computer.getValidCards(SpellPermanent.this.championValid, controller, source);
computer.remove(source);
computer.shuffle();
CardListUtil.shuffle(computer);
if (computer.size() != 0) {
final Card c = computer.get(0);
source.setChampionedCard(c);

View File

@@ -14,6 +14,7 @@ import com.google.common.collect.Iterables;
import forge.AllZone;
import forge.Card;
import forge.CardList;
import forge.CardListUtil;
import forge.CardPredicates.Presets;
import forge.CardPredicates;
import forge.CardUtil;
@@ -375,7 +376,7 @@ public class GameNew {
*/
private static Iterable<Card> smoothComputerManaCurve(final Iterable<Card> in) {
final CardList library = new CardList(in);
library.shuffle();
CardListUtil.shuffle(library);
// remove all land, keep non-basicland in there, shuffled
CardList land = library.filter(CardPredicates.Presets.LANDS);

View File

@@ -596,10 +596,10 @@ public class Upkeep extends Phase implements java.io.Serializable {
}
});
if (humanCreatures.isEmpty()) {
options.shuffle();
CardListUtil.shuffle(options);
return options.get(0);
} else {
humanCreatures.shuffle();
CardListUtil.shuffle(humanCreatures);
return humanCreatures.get(0);
}
}

View File

@@ -139,7 +139,7 @@ public class AIPlayer extends Player {
// use dredge if there are more than one of them in your graveyard
if ((dredgers.size() > 1) || ((dredgers.size() == 1) && random.nextBoolean())) {
dredgers.shuffle();
CardListUtil.shuffle(dredgers);
final Card c = dredgers.get(0);
// rule 702.49a
if (this.getDredgeNumber(c) <= this.getCardsIn(ZoneType.Library).size()) {

View File

@@ -1453,7 +1453,7 @@ public class ComputerUtil {
final CardList prefList = typeList.getValidCards(prefValid[1].split(","), activate.getController(),
activate);
if (prefList.size() != 0) {
prefList.shuffle();
CardListUtil.shuffle(prefList);
return prefList.get(0);
}
}
@@ -1469,7 +1469,7 @@ public class ComputerUtil {
}
});
if (sacMeList.size() != 0) {
sacMeList.shuffle();
CardListUtil.shuffle(sacMeList);
return sacMeList.get(0);
}
}

View File

@@ -898,7 +898,7 @@ public class ComputerUtilBlock {
}
}
if (!chumpBlockers.isEmpty()) {
ComputerUtilBlock.getAttackers().shuffle();
CardListUtil.shuffle(ComputerUtilBlock.getAttackers());
for (final Card attacker : ComputerUtilBlock.getAttackers()) {
blockers = ComputerUtilBlock.getPossibleBlockers(attacker, chumpBlockers, combat);
for (final Card blocker : blockers) {