- AI improvements for AF Sacrifice with the Destroy parameter.

This commit is contained in:
Sloth
2011-12-01 11:49:46 +00:00
parent d1fb96396f
commit a8f36ca58c
3 changed files with 45 additions and 27 deletions

View File

@@ -2179,7 +2179,7 @@ public class CombatUtil {
public void resolve() { public void resolve() {
if (crd.getController().isHuman()) { if (crd.getController().isHuman()) {
final CardList list = AllZone.getComputerPlayer().getCardsIn(Zone.Battlefield); final CardList list = AllZone.getComputerPlayer().getCardsIn(Zone.Battlefield);
ComputerUtil.sacrificePermanents(a, list); ComputerUtil.sacrificePermanents(a, list, false);
} else { } else {
AllZone.getInputControl().setInput(PlayerUtil.inputSacrificePermanents(a)); AllZone.getInputControl().setInput(PlayerUtil.inputSacrificePermanents(a));
} }

View File

@@ -1524,7 +1524,7 @@ public class ComputerUtil {
* a {@link forge.CardList} object. * a {@link forge.CardList} object.
* @return the card list * @return the card list
*/ */
public static CardList sacrificePermanents(final int amount, final CardList list) { public static CardList sacrificePermanents(final int amount, final CardList list, boolean destroy) {
final CardList sacList = new CardList(); final CardList sacList = new CardList();
// used in Annihilator and AF_Sacrifice // used in Annihilator and AF_Sacrifice
int max = list.size(); int max = list.size();
@@ -1536,15 +1536,20 @@ public class ComputerUtil {
list.reverse(); list.reverse();
for (int i = 0; i < max; i++) { for (int i = 0; i < max; i++) {
// TODO: use getWorstPermanent() would be wayyyy better Card c = null;
Card c; if (destroy) {
CardList indestructibles = list.getKeyword("Indestructible");
if (!indestructibles.isEmpty()) {
c = indestructibles.get(0);
}
} else {
if (list.getNotType("Creature").size() == 0) { if (list.getNotType("Creature").size() == 0) {
c = CardFactoryUtil.getWorstCreatureAI(list); c = CardFactoryUtil.getWorstCreatureAI(list);
} else if (list.getNotType("Land").size() == 0) { } else if (list.getNotType("Land").size() == 0) {
c = CardFactoryUtil.getWorstLand(AllZone.getComputerPlayer()); c = CardFactoryUtil.getWorstLand(AllZone.getComputerPlayer());
} else { } else {
c = list.get(0); c = CardFactoryUtil.getWorstPermanentAI(list, true, true, true, true);
} }
final ArrayList<Card> auras = c.getEnchantedBy(); final ArrayList<Card> auras = c.getEnchantedBy();
@@ -1559,10 +1564,18 @@ public class ComputerUtil {
} }
} }
} }
if (destroy) {
if(!AllZone.getGameAction().destroy(c)) {
continue;
}
} else {
if(!AllZone.getGameAction().sacrifice(c)) {
continue;
}
}
}
list.remove(c); list.remove(c);
sacList.add(c); sacList.add(c);
AllZone.getGameAction().sacrifice(c);
} }
return sacList; return sacList;
} }

View File

@@ -214,7 +214,12 @@ public class AbilityFactorySacrifice {
msg = valid; msg = valid;
} }
sb.append("Sacrifices ").append(amount).append(" ").append(msg).append("."); if (params.containsKey("Destroy")) {
sb.append("Destroys ");
} else {
sb.append("Sacrifices ");
}
sb.append(amount).append(" ").append(msg).append(".");
} }
final AbilitySub abSub = sa.getSubAbility(); final AbilitySub abSub = sa.getSubAbility();
@@ -514,7 +519,7 @@ public class AbilityFactorySacrifice {
CardList list = p.getCardsIn(Zone.Battlefield); CardList list = p.getCardsIn(Zone.Battlefield);
list = list.getValidCards(valid.split(","), sa.getActivatingPlayer(), sa.getSourceCard()); list = list.getValidCards(valid.split(","), sa.getActivatingPlayer(), sa.getSourceCard());
final CardList sacList = ComputerUtil.sacrificePermanents(amount, list); final CardList sacList = ComputerUtil.sacrificePermanents(amount, list, destroy);
return sacList; return sacList;
} }
@@ -551,11 +556,11 @@ public class AbilityFactorySacrifice {
final Card c = (Card) o; final Card c = (Card) o;
if (destroy) { if (destroy) {
if(!AllZone.getGameAction().destroy(c)) { if (!AllZone.getGameAction().destroy(c)) {
continue; continue;
} }
} else { } else {
if(!AllZone.getGameAction().sacrifice(c)){ if (!AllZone.getGameAction().sacrifice(c)) {
continue; continue;
} }
} }