- 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() {
if (crd.getController().isHuman()) {
final CardList list = AllZone.getComputerPlayer().getCardsIn(Zone.Battlefield);
ComputerUtil.sacrificePermanents(a, list);
ComputerUtil.sacrificePermanents(a, list, false);
} else {
AllZone.getInputControl().setInput(PlayerUtil.inputSacrificePermanents(a));
}

View File

@@ -1524,7 +1524,7 @@ public class ComputerUtil {
* a {@link forge.CardList} object.
* @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();
// used in Annihilator and AF_Sacrifice
int max = list.size();
@@ -1536,33 +1536,46 @@ public class ComputerUtil {
list.reverse();
for (int i = 0; i < max; i++) {
// TODO: use getWorstPermanent() would be wayyyy better
Card c;
if (list.getNotType("Creature").size() == 0) {
c = CardFactoryUtil.getWorstCreatureAI(list);
} else if (list.getNotType("Land").size() == 0) {
c = CardFactoryUtil.getWorstLand(AllZone.getComputerPlayer());
Card c = null;
if (destroy) {
CardList indestructibles = list.getKeyword("Indestructible");
if (!indestructibles.isEmpty()) {
c = indestructibles.get(0);
}
} else {
c = list.get(0);
}
final ArrayList<Card> auras = c.getEnchantedBy();
if (auras.size() > 0) {
// TODO: choose "worst" controlled enchanting Aura
for (int j = 0; j < auras.size(); j++) {
final Card aura = auras.get(j);
if (aura.getController().isPlayer(c.getController()) && list.contains(aura)) {
c = aura;
break;
if (list.getNotType("Creature").size() == 0) {
c = CardFactoryUtil.getWorstCreatureAI(list);
} else if (list.getNotType("Land").size() == 0) {
c = CardFactoryUtil.getWorstLand(AllZone.getComputerPlayer());
} else {
c = CardFactoryUtil.getWorstPermanentAI(list, true, true, true, true);
}
final ArrayList<Card> auras = c.getEnchantedBy();
if (auras.size() > 0) {
// TODO: choose "worst" controlled enchanting Aura
for (int j = 0; j < auras.size(); j++) {
final Card aura = auras.get(j);
if (aura.getController().isPlayer(c.getController()) && list.contains(aura)) {
c = aura;
break;
}
}
}
if (destroy) {
if(!AllZone.getGameAction().destroy(c)) {
continue;
}
} else {
if(!AllZone.getGameAction().sacrifice(c)) {
continue;
}
}
}
list.remove(c);
sacList.add(c);
AllZone.getGameAction().sacrifice(c);
}
return sacList;
}

View File

@@ -214,7 +214,12 @@ public class AbilityFactorySacrifice {
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();
@@ -514,7 +519,7 @@ public class AbilityFactorySacrifice {
CardList list = p.getCardsIn(Zone.Battlefield);
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;
}
@@ -551,11 +556,11 @@ public class AbilityFactorySacrifice {
final Card c = (Card) o;
if (destroy) {
if(!AllZone.getGameAction().destroy(c)) {
if (!AllZone.getGameAction().destroy(c)) {
continue;
}
} else {
if(!AllZone.getGameAction().sacrifice(c)){
if (!AllZone.getGameAction().sacrifice(c)) {
continue;
}
}