- Basic Witch's Vengeance AI, some refactoring in ChooseTypeAi.

This commit is contained in:
Michael Kamensky
2020-10-05 07:30:57 +03:00
parent 7dc92c33c1
commit 3ce3d70c62
2 changed files with 48 additions and 30 deletions

View File

@@ -2,25 +2,21 @@ package forge.ai.ability;
import com.google.common.base.Predicates;
import com.google.common.collect.Lists;
import forge.ai.AiCardMemory;
import forge.ai.ComputerUtilAbility;
import forge.ai.ComputerUtilCard;
import forge.ai.ComputerUtilMana;
import forge.ai.SpellAbilityAi;
import forge.ai.*;
import forge.card.CardType;
import forge.game.ability.AbilityUtils;
import forge.game.card.Card;
import forge.game.card.CardCollection;
import forge.game.card.CardCollectionView;
import forge.game.card.CardLists;
import forge.game.card.CardPredicates;
import forge.game.ability.ApiType;
import forge.game.card.*;
import forge.game.keyword.Keyword;
import forge.game.phase.PhaseType;
import forge.game.player.Player;
import forge.game.spellability.SpellAbility;
import forge.game.zone.ZoneType;
import forge.util.Aggregates;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class ChooseTypeAi extends SpellAbilityAi {
@Override
@@ -31,6 +27,8 @@ public class ChooseTypeAi extends SpellAbilityAi {
if (ComputerUtilAbility.getAbilitySourceName(sa).equals("Mirror Entity Avatar")) {
return doMirrorEntityLogic(aiPlayer, sa);
}
} else if ("MostProminentOppControls".equals(sa.getParam("AILogic"))) {
return !chooseType(sa, aiPlayer.getOpponents().getCardsIn(ZoneType.Battlefield)).isEmpty();
}
return doTriggerAINoCost(aiPlayer, sa, false);
@@ -44,27 +42,11 @@ public class ChooseTypeAi extends SpellAbilityAi {
return false;
}
CardCollectionView otb = aiPlayer.getCardsIn(ZoneType.Battlefield);
List<String> valid = Lists.newArrayList(CardType.getAllCreatureTypes());
String chosenType = ComputerUtilCard.getMostProminentType(otb, valid);
String chosenType = chooseType(sa, aiPlayer.getCardsIn(ZoneType.Battlefield));
if (chosenType.isEmpty()) {
// Account for the situation when only changelings are on the battlefield
boolean allChangeling = false;
for (Card c : otb) {
if (c.isCreature() && c.hasStartOfKeyword(Keyword.CHANGELING.toString())) {
chosenType = Aggregates.random(valid); // just choose a random type for changelings
allChangeling = true;
break;
}
}
if (!allChangeling) {
// Still empty, probably no creatures on board
return false;
}
return false;
}
int maxX = ComputerUtilMana.determineMaxAffordableX(aiPlayer, sa);
int avgPower = 0;
@@ -127,4 +109,40 @@ public class ChooseTypeAi extends SpellAbilityAi {
return true;
}
private String chooseType(SpellAbility sa, CardCollectionView cards) {
Set<String> valid = new HashSet<>();
if (sa.getSubAbility() != null && sa.getSubAbility().getApi() == ApiType.PumpAll
&& sa.getSubAbility().isCurse() && sa.getSubAbility().hasParam("NumDef")) {
final SpellAbility pumpSa = sa.getSubAbility();
final int defense = AbilityUtils.calculateAmount(sa.getHostCard(), pumpSa.getParam("NumDef"), pumpSa);
for (Card c : cards) {
if (c.isCreature() && c.getNetToughness() <= -defense) {
valid.addAll(c.getType().getCreatureTypes());
}
}
} else {
valid.addAll(CardType.getAllCreatureTypes());
}
String chosenType = ComputerUtilCard.getMostProminentType(cards, valid);
if (chosenType.isEmpty()) {
// Account for the situation when only changelings are on the battlefield
boolean allChangeling = false;
for (Card c : cards) {
if (c.isCreature() && c.hasStartOfKeyword(Keyword.CHANGELING.toString())) {
chosenType = Aggregates.random(valid); // just choose a random type for changelings
allChangeling = true;
break;
}
}
if (!allChangeling) {
// Still empty, probably no creatures on board
return "";
}
}
return chosenType;
}
}

View File

@@ -1,6 +1,6 @@
Name:Witch's Vengeance
ManaCost:1 B B
Types:Sorcery
A:SP$ ChooseType | Cost$ 1 B B | Defined$ You | Type$ Creature | AILogic$ MostProminentHumanControls | SubAbility$ DBPumpAll | SpellDescription$ Creatures of the creature type of your choice get -3/-3 until end of turn.
A:SP$ ChooseType | Cost$ 1 B B | Defined$ You | Type$ Creature | AILogic$ MostProminentOppControls | SubAbility$ DBPumpAll | SpellDescription$ Creatures of the creature type of your choice get -3/-3 until end of turn.
SVar:DBPumpAll:DB$ PumpAll | ValidCards$ Creature.ChosenType | NumAtt$ -3 | NumDef$ -3 | IsCurse$ True
Oracle:Creatures of the creature type of your choice get -3/-3 until end of turn.