Skip to content

Commit

Permalink
Try improve AI
Browse files Browse the repository at this point in the history
  • Loading branch information
tool4EvEr authored and tool4EvEr committed Dec 2, 2023
1 parent 05e9dbf commit 861e516
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
1 change: 0 additions & 1 deletion forge-ai/src/main/java/forge/ai/AiCostDecision.java
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,6 @@ public PaymentDecision visit(CostPayLife cost) {
if (!player.canPayLife(c, isEffect(), ability)) {
return null;
}
// activator.payLife(c, null);
return PaymentDecision.number(c);
}

Expand Down
23 changes: 23 additions & 0 deletions forge-ai/src/main/java/forge/ai/ability/ChangeZoneAi.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import forge.game.combat.Combat;
import forge.game.cost.Cost;
import forge.game.cost.CostDiscard;
import forge.game.cost.CostExile;
import forge.game.cost.CostPart;
import forge.game.cost.CostPutCounter;
import forge.game.keyword.Keyword;
Expand Down Expand Up @@ -50,6 +51,28 @@ public class ChangeZoneAi extends SpellAbilityAi {
// cards where multiple cards are fetched at once and they need to be coordinated
private static CardCollection multipleCardsToChoose = new CardCollection();

protected boolean willPayCosts(Player ai, SpellAbility sa, Cost cost, Card source) {
if (sa.isCraft()) {
CardCollection payingCards = new CardCollection();
int needed = 0;
for (final CostPart part : cost.getCostParts()) {
if (part instanceof CostExile) {
if (part.payCostFromSource()) {
continue;
}
int amt = part.getAbilityAmount(sa);
needed += amt;
payingCards.addAll(ComputerUtil.chooseExileFrom(ai, (CostExile) part, source, amt, sa));
}
}
if (payingCards.size() < needed) {
return false;
}
}

return super.willPayCosts(ai, sa, cost, source);
}

@Override
protected boolean checkAiLogic(final Player ai, final SpellAbility sa, final String aiLogic) {
if (sa.getHostCard() != null && sa.getHostCard().hasSVar("AIPreferenceOverride")) {
Expand Down
9 changes: 0 additions & 9 deletions forge-game/src/main/java/forge/game/cost/CostExile.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,6 @@ else if (type.contains("FromTopGrave")) {
if (ability.isCraft()) {
CostExile firstExileCost = ability.getPayCosts().getCostPartByType(CostExile.class);
if (firstExileCost != null && firstExileCost.payCostFromSource()) list.remove(ability.getHostCard());
// TODO: UGLY HACK! Ideally there should be no AI-specific code here, but not adding any (and adding it into ComputerUtil.chooseExileFrom)
// makes the game fail to play the SA with "AI failed to play....".
if (payer.isAI()) {
CardCollection toRemove = new CardCollection();
for (Card exileTgt : list) {
if (exileTgt.isInPlay() && exileTgt.getCMC() >= 3) toRemove.add(exileTgt);
}
list.removeAll(toRemove);
}
}

// for cards like Allosaurus Rider, do not count it
Expand Down

0 comments on commit 861e516

Please sign in to comment.