diff --git a/src/main/java/forge/ComputerAIGeneral.java b/src/main/java/forge/ComputerAIGeneral.java index d022dba44da..ec08391f547 100644 --- a/src/main/java/forge/ComputerAIGeneral.java +++ b/src/main/java/forge/ComputerAIGeneral.java @@ -89,9 +89,9 @@ public class ComputerAIGeneral implements Computer { * a {@link java.lang.String} object. */ private void playCards(final String phase) { - final SpellAbility[] sp = phase.equals(Constant.Phase.MAIN1) ? this.getMain1() : this.getMain2(); + final CardList list = phase.equals(Constant.Phase.MAIN1) ? this.getMain1() : this.getMain2(); - final boolean nextPhase = ComputerUtil.playSpellAbilities(sp); + final boolean nextPhase = ComputerUtil.playSpellAbilities(getSpellAbilities(list)); if (nextPhase) { AllZone.getPhaseHandler().passPriority(); @@ -105,14 +105,16 @@ public class ComputerAIGeneral implements Computer { * * @return an array of {@link forge.card.spellability.SpellAbility} objects. */ - private SpellAbility[] getMain1() { + private CardList getMain1() { + final Player computer = AllZone.getComputerPlayer(); + final Player human = AllZone.getHumanPlayer(); // Card list of all cards to consider - CardList hand = AllZone.getComputerPlayer().getCardsIn(Zone.Hand); + CardList hand = computer.getCardsIn(Zone.Hand); final boolean hasACardGivingHaste = this.hasACardGivingHaste(); // If mana pool is not empty try to play anything - if (AllZone.getComputerPlayer().getManaPool().isEmpty()) { + if (computer.getManaPool().isEmpty()) { hand = hand.filter(new CardListFilter() { @Override public boolean addCard(final Card c) { @@ -131,7 +133,7 @@ public class ComputerAIGeneral implements Computer { } // get all cards the computer controls with BuffedBy - final CardList buffed = AllZone.getComputerPlayer().getCardsIn(Zone.Battlefield); + final CardList buffed = computer.getCardsIn(Zone.Battlefield); for (int j = 0; j < buffed.size(); j++) { final Card buffedcard = buffed.get(j); if (buffedcard.getSVar("BuffedBy").length() > 0) { @@ -144,7 +146,7 @@ public class ComputerAIGeneral implements Computer { } // BuffedBy // get all cards the human controls with AntiBuffedBy - final CardList antibuffed = AllZone.getHumanPlayer().getCardsIn(Zone.Battlefield); + final CardList antibuffed = human.getCardsIn(Zone.Battlefield); for (int k = 0; k < antibuffed.size(); k++) { final Card buffedcard = antibuffed.get(k); if (buffedcard.getSVar("AntiBuffedBy").length() > 0) { @@ -160,9 +162,9 @@ public class ComputerAIGeneral implements Computer { return false; } - final CardList vengevines = AllZone.getComputerPlayer().getCardsIn(Zone.Graveyard, "Vengevine"); + final CardList vengevines = computer.getCardsIn(Zone.Graveyard, "Vengevine"); if (vengevines.size() > 0) { - final CardList creatures = AllZone.getComputerPlayer().getCardsIn(Zone.Hand); + final CardList creatures = computer.getCardsIn(Zone.Hand); final CardList creatures2 = new CardList(); for (int i = 0; i < creatures.size(); i++) { if (creatures.get(i).isCreature() @@ -182,21 +184,17 @@ public class ComputerAIGeneral implements Computer { } }); } - final CardList all = AllZone.getComputerPlayer().getCardsIn(Zone.Battlefield); - all.addAll(CardFactoryUtil.getExternalZoneActivationCards(AllZone.getComputerPlayer())); + final CardList all = computer.getCardsIn(Zone.Battlefield); + all.addAll(computer.getCardsIn(Zone.Exile)); + all.addAll(computer.getCardsIn(Zone.Graveyard)); + if (!computer.getCardsIn(Zone.Library).isEmpty()) { + all.add(computer.getCardsIn(Zone.Library).get(0)); + } + all.addAll(human.getCardsIn(Zone.Battlefield)); + all.addAll(human.getCardsIn(Zone.Exile)); all.addAll(hand); - CardList humanPlayable = AllZone.getHumanPlayer().getCardsIn(Zone.Battlefield); - humanPlayable = humanPlayable.filter(new CardListFilter() { - @Override - public boolean addCard(final Card c) { - return (c.canAnyPlayerActivate()); - } - }); - - all.addAll(humanPlayable); - - return this.getPlayable(all); + return all; } // getMain1() /** @@ -240,49 +238,39 @@ public class ComputerAIGeneral implements Computer { * * @return an array of {@link forge.card.spellability.SpellAbility} objects. */ - private SpellAbility[] getMain2() { + private CardList getMain2() { + final Player computer = AllZone.getComputerPlayer(); + final Player human = AllZone.getHumanPlayer(); // Card list of all cards to consider - CardList all = AllZone.getComputerPlayer().getCardsIn(Zone.Hand); + CardList all = computer.getCardsIn(Zone.Hand); // Don't play permanents with Flash before humans declare attackers step all = all.filter(new CardListFilter() { @Override public boolean addCard(final Card c) { if (c.isPermanent() && c.hasKeyword("Flash") - && (AllZone.getPhaseHandler().isPlayerTurn(AllZone.getComputerPlayer()) || AllZone.getPhaseHandler() + && (AllZone.getPhaseHandler().isPlayerTurn(computer) || AllZone.getPhaseHandler() .isBefore(Constant.Phase.COMBAT_DECLARE_ATTACKERS_INSTANT_ABILITY))) { return false; } return true; } }); - all.addAll(AllZone.getComputerPlayer().getCardsIn(Zone.Battlefield)); - all.addAll(CardFactoryUtil.getExternalZoneActivationCards(AllZone.getComputerPlayer())); + all.addAll(computer.getCardsIn(Zone.Exile)); + all.addAll(computer.getCardsIn(Zone.Graveyard)); + if (!computer.getCardsIn(Zone.Library).isEmpty()) { + all.add(computer.getCardsIn(Zone.Library).get(0)); + } + all.addAll(human.getCardsIn(Zone.Exile)); // Prevent the computer from summoning Ball Lightning type creatures // during main phase 2 all = all.getNotKeyword("At the beginning of the end step, sacrifice CARDNAME."); - all = all.filter(new CardListFilter() { - @Override - public boolean addCard(final Card c) { - if (c.isLand()) { - return false; - } - return true; - } - }); + all.addAll(computer.getCardsIn(Zone.Battlefield)); + all.addAll(human.getCardsIn(Zone.Battlefield)); - CardList humanPlayable = AllZone.getHumanPlayer().getCardsIn(Zone.Battlefield); - humanPlayable = humanPlayable.filter(new CardListFilter() { - @Override - public boolean addCard(final Card c) { - return (c.canAnyPlayerActivate()); - } - }); - all.addAll(humanPlayable); - - return this.getPlayable(all); + return all; } // getMain2() /** @@ -293,7 +281,9 @@ public class ComputerAIGeneral implements Computer { * @return a {@link forge.CardList} object. */ private CardList getAvailableSpellAbilities() { - CardList all = AllZone.getComputerPlayer().getCardsIn(Zone.Hand); + final Player computer = AllZone.getComputerPlayer(); + final Player human = AllZone.getHumanPlayer(); + CardList all = computer.getCardsIn(Zone.Hand); // Don't play permanents with Flash before humans declare attackers step all = all.filter(new CardListFilter() { @Override @@ -301,24 +291,21 @@ public class ComputerAIGeneral implements Computer { if (c.isPermanent() && c.hasKeyword("Flash") && !hasETBTrigger(c) - && (AllZone.getPhaseHandler().isPlayerTurn(AllZone.getComputerPlayer()) || AllZone.getPhaseHandler() + && (AllZone.getPhaseHandler().isPlayerTurn(computer) || AllZone.getPhaseHandler() .isBefore(Constant.Phase.COMBAT_DECLARE_ATTACKERS_INSTANT_ABILITY))) { return false; } return true; } }); - all.addAll(AllZone.getComputerPlayer().getCardsIn(Zone.Battlefield)); - all.addAll(CardFactoryUtil.getExternalZoneActivationCards(AllZone.getComputerPlayer())); - - CardList humanPlayable = AllZone.getHumanPlayer().getCardsIn(Zone.Battlefield); - humanPlayable = humanPlayable.filter(new CardListFilter() { - @Override - public boolean addCard(final Card c) { - return (c.canAnyPlayerActivate()); - } - }); - all.addAll(humanPlayable); + all.addAll(computer.getCardsIn(Zone.Battlefield)); + all.addAll(computer.getCardsIn(Zone.Exile)); + all.addAll(computer.getCardsIn(Zone.Graveyard)); + if (!computer.getCardsIn(Zone.Library).isEmpty()) { + all.add(computer.getCardsIn(Zone.Library).get(0)); + } + all.addAll(human.getCardsIn(Zone.Exile)); + all.addAll(human.getCardsIn(Zone.Battlefield)); return all; } @@ -351,17 +338,6 @@ public class ComputerAIGeneral implements Computer { return false; } - /** - *
- * getOtherPhases. - *
- * - * @return an array of {@link forge.card.spellability.SpellAbility} objects. - */ - private SpellAbility[] getOtherPhases() { - return this.getPlayable(this.getAvailableSpellAbilities()); - } - /** *
* getPossibleCounters.
@@ -381,25 +357,44 @@ public class ComputerAIGeneral implements Computer {
* @return a {@link java.util.ArrayList} object.
*/
private ArrayList
- * getETBCounters.
- *
* begin_combat.
@@ -562,10 +532,10 @@ public class ComputerAIGeneral implements Computer {
*/
public final void stackResponse() {
// if top of stack is empty
- final SpellAbility[] sas = this.getOtherPhases();
+ final ArrayList