Skip to content

Commit 17d882b

Browse files
authored
Add basic AI For Discover (#11184)
1 parent 0bfb918 commit 17d882b

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

forge-ai/src/main/java/forge/ai/ability/DiscoverAi.java

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
import forge.ai.*;
44
import forge.game.ability.AbilityUtils;
55
import forge.game.card.Card;
6+
import forge.game.cost.Cost;
67
import forge.game.player.Player;
78
import forge.game.player.PlayerActionConfirmMode;
9+
import forge.game.spellability.AbilitySub;
810
import forge.game.spellability.Spell;
911
import forge.game.spellability.SpellAbility;
1012

@@ -14,7 +16,32 @@ public class DiscoverAi extends SpellAbilityAi {
1416

1517
@Override
1618
protected AiAbilityDecision checkApiLogic(final Player ai, final SpellAbility sa) {
17-
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
19+
if (sa instanceof AbilitySub) {
20+
// If its a subability, just let the AI do it. Casting spells is fun!
21+
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
22+
}
23+
24+
Card c = sa.getHostCard();
25+
Cost cost = sa.getPayCosts();
26+
if (cost != null) {
27+
// IF self sacrifice, make sure its "work it". For lands, make sure we still have a decent amount of lands. Or not losing a color source we might need
28+
if (ComputerUtilCost.isSacrificeSelfCost(cost)) {
29+
if (c.isLand()) {
30+
// The discover lands cost 5 plus tapping this land to activate.
31+
// Let's make sure we don't have too few lands in play before we sacrifice this land.
32+
if (ai.getLandsInPlay().size() <= 6) {
33+
return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
34+
}
35+
}
36+
}
37+
38+
// Other discover costs that we should probably consider:
39+
// Sub Loyalty
40+
// Exile creature card from graveyard
41+
// Tapping creatures/artifacts
42+
}
43+
44+
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
1845
}
1946

2047
/**
@@ -34,6 +61,11 @@ protected AiAbilityDecision doTriggerNoCost(final Player ai, final SpellAbility
3461
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
3562
}
3663

64+
// If cost is free, and we're just resolving a trigger, lets just do it.
65+
if (sa.getPayCosts() == null || sa.getPayCosts().isFree()) {
66+
return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
67+
}
68+
3769
return checkApiLogic(ai, sa);
3870
}
3971

forge-game/src/main/java/forge/game/cost/Cost.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ public final boolean hasManaCost() {
7474
return this.getCostMana() != null;
7575
}
7676

77+
public final boolean isFree() {
78+
return isOnlyManaCost() && getTotalMana().isZero();
79+
}
7780
public final boolean hasSpecificCostType(Class<? extends CostPart> costType) {
7881
for (CostPart p : getCostParts()) {
7982
if (costType.isInstance(p)) {

0 commit comments

Comments
 (0)