From 987cac7eaba0c766d4ab0c24c19626327226e1a2 Mon Sep 17 00:00:00 2001 From: Sloth Date: Mon, 15 Sep 2014 13:02:24 +0000 Subject: [PATCH] - Added "withoutAbilities" parameter to damageIfUnblocked function (fixes AI not pumping Killer Bees). --- .../src/main/java/forge/ai/AiAttackController.java | 12 ++++++------ .../src/main/java/forge/ai/ComputerUtilCard.java | 2 +- .../src/main/java/forge/ai/ComputerUtilCombat.java | 8 ++++---- .../src/main/java/forge/ai/ability/ChooseCardAi.java | 4 ++-- .../main/java/forge/ai/ability/ChooseSourceAi.java | 4 ++-- .../src/main/java/forge/ai/ability/ProtectAi.java | 2 +- .../src/main/java/forge/ai/ability/PumpAiBase.java | 10 +++++----- 7 files changed, 21 insertions(+), 21 deletions(-) diff --git a/forge-ai/src/main/java/forge/ai/AiAttackController.java b/forge-ai/src/main/java/forge/ai/AiAttackController.java index 6373a36fadb..c949951f7a7 100644 --- a/forge-ai/src/main/java/forge/ai/AiAttackController.java +++ b/forge-ai/src/main/java/forge/ai/AiAttackController.java @@ -196,7 +196,7 @@ public class AiAttackController { } final Player opp = this.defendingOpponent; - if (ComputerUtilCombat.damageIfUnblocked(attacker, opp, combat) > 0) { + if (ComputerUtilCombat.damageIfUnblocked(attacker, opp, combat, false) > 0) { return true; } if (ComputerUtilCombat.poisonIfUnblocked(attacker, opp) > 0) { @@ -401,7 +401,7 @@ public class AiAttackController { blockersLeft--; continue; } - totalAttack += ComputerUtilCombat.damageIfUnblocked(attacker, ai, null); + totalAttack += ComputerUtilCombat.damageIfUnblocked(attacker, ai, null, false); totalPoison += ComputerUtilCombat.poisonIfUnblocked(attacker, ai); } @@ -696,7 +696,7 @@ public class AiAttackController { if (ComputerUtil.canAttackNextTurn(pCard)) { candidateAttackers.add(pCard); if (pCard.getNetCombatDamage() > 0) { - candidateUnblockedDamage += ComputerUtilCombat.damageIfUnblocked(pCard, opp, null); + candidateUnblockedDamage += ComputerUtilCombat.damageIfUnblocked(pCard, opp, null, false); computerForces += 1; } } @@ -784,7 +784,7 @@ public class AiAttackController { } } if (isUnblockableCreature) { - unblockableDamage += ComputerUtilCombat.damageIfUnblocked(attacker, opp, combat); + unblockableDamage += ComputerUtilCombat.damageIfUnblocked(attacker, opp, combat, false); } } for (final Card attacker : nextTurnAttackers) { @@ -798,7 +798,7 @@ public class AiAttackController { } } if (isUnblockableCreature) { - nextUnblockableDamage += ComputerUtilCombat.damageIfUnblocked(attacker, opp, null); + nextUnblockableDamage += ComputerUtilCombat.damageIfUnblocked(attacker, opp, null, false); } } if (unblockableDamage > 0 && !opp.cantLoseForZeroOrLessLife() @@ -872,7 +872,7 @@ public class AiAttackController { CardLists.sortByPowerAsc(attacking); for (Card atta : attacking) { if (attackNum >= blockNum || !CombatUtil.canBeBlocked(attacker, this.blockers, combat)) { - damage += ComputerUtilCombat.damageIfUnblocked(atta, opp, null); + damage += ComputerUtilCombat.damageIfUnblocked(atta, opp, null, false); } else if (CombatUtil.canBeBlocked(attacker, this.blockers, combat)) { attackNum++; } diff --git a/forge-ai/src/main/java/forge/ai/ComputerUtilCard.java b/forge-ai/src/main/java/forge/ai/ComputerUtilCard.java index 012de8c799a..9c0dd2780f4 100644 --- a/forge-ai/src/main/java/forge/ai/ComputerUtilCard.java +++ b/forge-ai/src/main/java/forge/ai/ComputerUtilCard.java @@ -1002,7 +1002,7 @@ public class ComputerUtilCard { float threat = 0; if (c.isCreature()) { Combat combat = ai.getGame().getCombat(); - threat = 1.0f * ComputerUtilCombat.damageIfUnblocked(c, opp, combat) / ai.getLife(); + threat = 1.0f * ComputerUtilCombat.damageIfUnblocked(c, opp, combat, true) / ai.getLife(); //TODO:add threat from triggers and other abilities (ie. Master of Cruelties) } else { for (final StaticAbility stAb : c.getStaticAbilities()) { diff --git a/forge-ai/src/main/java/forge/ai/ComputerUtilCombat.java b/forge-ai/src/main/java/forge/ai/ComputerUtilCombat.java index c3f902b2c6c..33974ceb127 100644 --- a/forge-ai/src/main/java/forge/ai/ComputerUtilCombat.java +++ b/forge-ai/src/main/java/forge/ai/ComputerUtilCombat.java @@ -118,13 +118,13 @@ public class ComputerUtilCombat { * a {@link forge.game.combat.Combat} object. * @return a int. */ - public static int damageIfUnblocked(final Card attacker, final Player attacked, final Combat combat) { + public static int damageIfUnblocked(final Card attacker, final Player attacked, final Combat combat, boolean withoutAbilities) { int damage = attacker.getNetCombatDamage(); int sum = 0; if (!attacked.canLoseLife()) { return 0; } - damage += ComputerUtilCombat.predictPowerBonusOfAttacker(attacker, null, combat, false); + damage += ComputerUtilCombat.predictPowerBonusOfAttacker(attacker, null, combat, withoutAbilities); if (!attacker.hasKeyword("Infect")) { sum = ComputerUtilCombat.predictDamageTo(attacked, damage, attacker, true); if (attacker.hasKeyword("Double Strike")) { @@ -179,7 +179,7 @@ public class ComputerUtilCombat { public static int sumDamageIfUnblocked(final List attackers, final Player attacked) { int sum = 0; for (final Card attacker : attackers) { - sum += ComputerUtilCombat.damageIfUnblocked(attacker, attacked, null); + sum += ComputerUtilCombat.damageIfUnblocked(attacker, attacked, null, false); } return sum; } @@ -293,7 +293,7 @@ public class ComputerUtilCombat { for(Card c : combat.getAttackers()) { if(c.isCommander()) { int currentCommanderDamage = ai.getCommanderDamage().containsKey(c) ? ai.getCommanderDamage().get(c) : 0; - if (damageIfUnblocked(c, ai, combat) + currentCommanderDamage >= 21) + if (damageIfUnblocked(c, ai, combat, false) + currentCommanderDamage >= 21) res.add(c); } } diff --git a/forge-ai/src/main/java/forge/ai/ability/ChooseCardAi.java b/forge-ai/src/main/java/forge/ai/ability/ChooseCardAi.java index b31f193ce95..6e4ef77dc89 100644 --- a/forge-ai/src/main/java/forge/ai/ability/ChooseCardAi.java +++ b/forge-ai/src/main/java/forge/ai/ability/ChooseCardAi.java @@ -81,7 +81,7 @@ public class ChooseCardAi extends SpellAbilityAi { return false; } int ref = host.getName().equals("Forcefield") ? 1 : 0; - return ComputerUtilCombat.damageIfUnblocked(c, ai, combat) > ref; + return ComputerUtilCombat.damageIfUnblocked(c, ai, combat, true) > ref; } }); if (choices.isEmpty()) { @@ -157,7 +157,7 @@ public class ChooseCardAi extends SpellAbilityAi { return false; } int ref = host.getName().equals("Forcefield") ? 1 : 0; - return ComputerUtilCombat.damageIfUnblocked(c, ai, combat) > ref; + return ComputerUtilCombat.damageIfUnblocked(c, ai, combat, true) > ref; } }); if (!better.isEmpty()) { diff --git a/forge-ai/src/main/java/forge/ai/ability/ChooseSourceAi.java b/forge-ai/src/main/java/forge/ai/ability/ChooseSourceAi.java index ee501075236..4d34c4baa06 100644 --- a/forge-ai/src/main/java/forge/ai/ability/ChooseSourceAi.java +++ b/forge-ai/src/main/java/forge/ai/ability/ChooseSourceAi.java @@ -109,7 +109,7 @@ public class ChooseSourceAi extends SpellAbilityAi { if (combat == null || !combat.isAttacking(c, ai) || !combat.isUnblocked(c)) { return false; } - return ComputerUtilCombat.damageIfUnblocked(c, ai, combat) > 0; + return ComputerUtilCombat.damageIfUnblocked(c, ai, combat, true) > 0; } }); if (choices.isEmpty()) { @@ -144,7 +144,7 @@ public class ChooseSourceAi extends SpellAbilityAi { || combat == null || !combat.isAttacking(c, ai) || !combat.isUnblocked(c)) { return false; } - return ComputerUtilCombat.damageIfUnblocked(c, ai, combat) > 0; + return ComputerUtilCombat.damageIfUnblocked(c, ai, combat, true) > 0; } }); return ComputerUtilCard.getBestCreatureAI(permanentSources); diff --git a/forge-ai/src/main/java/forge/ai/ability/ProtectAi.java b/forge-ai/src/main/java/forge/ai/ability/ProtectAi.java index 369fbda9fd1..4328cfd5f1d 100644 --- a/forge-ai/src/main/java/forge/ai/ability/ProtectAi.java +++ b/forge-ai/src/main/java/forge/ai/ability/ProtectAi.java @@ -148,7 +148,7 @@ public class ProtectAi extends SpellAbilityAi { return false; } else { Combat combat = ai.getGame().getCombat(); - int dmg = ComputerUtilCombat.damageIfUnblocked(c, ai.getOpponent(), combat); + int dmg = ComputerUtilCombat.damageIfUnblocked(c, ai.getOpponent(), combat, true); float ratio = 1.0f * dmg / ai.getOpponent().getLife(); Random r = MyRandom.getRandom(); return r.nextFloat() < ratio; diff --git a/forge-ai/src/main/java/forge/ai/ability/PumpAiBase.java b/forge-ai/src/main/java/forge/ai/ability/PumpAiBase.java index 335c4bd1a53..f5d77145b6e 100644 --- a/forge-ai/src/main/java/forge/ai/ability/PumpAiBase.java +++ b/forge-ai/src/main/java/forge/ai/ability/PumpAiBase.java @@ -484,7 +484,7 @@ public abstract class PumpAiBase extends SpellAbilityAi { if (phase.getPhase().isBefore(PhaseType.COMBAT_DECLARE_ATTACKERS) && phase.isPlayerTurn(ai)) { //1. become attacker for whatever reason if (!ComputerUtilCard.doesCreatureAttackAI(ai, c) && ComputerUtilCard.doesSpecifiedCreatureAttackAI(ai, pumped)) { - float threat = 1.0f * ComputerUtilCombat.damageIfUnblocked(pumped, opp, combat) / opp.getLife(); + float threat = 1.0f * ComputerUtilCombat.damageIfUnblocked(pumped, opp, combat, true) / opp.getLife(); if (CardLists.filter(oppCreatures, CardPredicates.possibleBlockers(pumped)).isEmpty()) { threat *= 2; } @@ -495,7 +495,7 @@ public abstract class PumpAiBase extends SpellAbilityAi { if (keywords.contains("Haste") && c.hasSickness() && !c.isTapped()) { chance += 0.5f; if (ComputerUtilCard.doesSpecifiedCreatureAttackAI(ai, pumped)) { - chance += 0.5f * ComputerUtilCombat.damageIfUnblocked(pumped, opp, combat) / opp.getLife(); + chance += 0.5f * ComputerUtilCombat.damageIfUnblocked(pumped, opp, combat, true) / opp.getLife(); } } @@ -503,7 +503,7 @@ public abstract class PumpAiBase extends SpellAbilityAi { if (!CardLists.filter(oppCreatures, CardPredicates.possibleBlockers(c)).isEmpty()) { if (CardLists.filter(oppCreatures, CardPredicates.possibleBlockers(pumped)).isEmpty() && ComputerUtilCard.doesSpecifiedCreatureAttackAI(ai, pumped)) { - chance += 0.5f * ComputerUtilCombat.damageIfUnblocked(pumped, opp, combat) / opp.getLife(); + chance += 0.5f * ComputerUtilCombat.damageIfUnblocked(pumped, opp, combat, true) / opp.getLife(); } } } @@ -566,8 +566,8 @@ public abstract class PumpAiBase extends SpellAbilityAi { //3. buff attacker if (combat.isAttacking(c)) { - int dmg = ComputerUtilCombat.damageIfUnblocked(c, opp, combat); - int pumpedDmg = ComputerUtilCombat.damageIfUnblocked(pumped, opp, pumpedCombat); + int dmg = ComputerUtilCombat.damageIfUnblocked(c, opp, combat, true); + int pumpedDmg = ComputerUtilCombat.damageIfUnblocked(pumped, opp, pumpedCombat, true); if (combat.isBlocked(c)) { if (!c.hasKeyword("Trample")) { dmg = 0;