Merge branch 'ai-exalted' into 'master'

Improve AI considerations for attacking in presence of Exalted

Closes #1039

See merge request core-developers/forge!1796
This commit is contained in:
Michael Kamensky
2019-06-06 19:20:03 +00:00
2 changed files with 23 additions and 3 deletions

View File

@@ -217,9 +217,22 @@ public class AiAttackController {
}
final Player opp = this.defendingOpponent;
if (ComputerUtilCombat.damageIfUnblocked(attacker, opp, combat, true) > 0) {
// Damage opponent if unblocked
final int dmgIfUnblocked = ComputerUtilCombat.damageIfUnblocked(attacker, opp, combat, true);
if (dmgIfUnblocked > 0) {
boolean onlyIfExalted = false;
if (combat.getAttackers().isEmpty() && ai.countExaltedBonus() > 0
&& dmgIfUnblocked - ai.countExaltedBonus() == 0) {
// Make sure we're not counting on the Exalted bonus when the AI is planning to attack with more than one creature
onlyIfExalted = true;
}
if (!onlyIfExalted || this.attackers.size() == 1 || this.aiAggression == 6 /* 6 is Exalted attack */) {
return true;
}
}
// Poison opponent if unblocked
if (ComputerUtilCombat.poisonIfUnblocked(attacker, opp) > 0) {
return true;
}
@@ -234,7 +247,7 @@ public class AiAttackController {
final CardCollectionView controlledByCompy = ai.getCardsIn(ZoneType.STATIC_ABILITIES_SOURCE_ZONES);
for (final Card c : controlledByCompy) {
for (final Trigger trigger : c.getTriggers()) {
if (ComputerUtilCombat.combatTriggerWillTrigger(attacker, null, trigger, combat)) {
if (ComputerUtilCombat.combatTriggerWillTrigger(attacker, null, trigger, combat, this.attackers)) {
return true;
}
}

View File

@@ -769,6 +769,10 @@ public class ComputerUtilCombat {
*/
public static boolean combatTriggerWillTrigger(final Card attacker, final Card defender, final Trigger trigger,
Combat combat) {
return combatTriggerWillTrigger(attacker, defender, trigger, combat, null);
}
public static boolean combatTriggerWillTrigger(final Card attacker, final Card defender, final Trigger trigger,
Combat combat, final List<Card> plannedAttackers) {
final Game game = attacker.getGame();
final Map<String, String> trigParams = trigger.getMapParams();
boolean willTrigger = false;
@@ -815,6 +819,9 @@ public class ComputerUtilCombat {
}
}
}
if (trigParams.containsKey("Alone") && plannedAttackers != null && plannedAttackers.size() != 1) {
return false; // won't trigger since the AI is planning to attack with more than one creature
}
}
// defender == null means unblocked