mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 12:18:00 +00:00
- More combat AI improvements (predicting pump abilities).
This commit is contained in:
@@ -1996,7 +1996,8 @@ public class CombatUtil {
|
|||||||
* a {@link forge.game.phase.Combat} object.
|
* a {@link forge.game.phase.Combat} object.
|
||||||
* @return a int.
|
* @return a int.
|
||||||
*/
|
*/
|
||||||
public static int predictToughnessBonusOfAttacker(final Card attacker, final Card defender, final Combat combat) {
|
public static int predictToughnessBonusOfAttacker(final Card attacker, final Card defender, final Combat combat
|
||||||
|
, boolean withoutAbilities) {
|
||||||
int toughness = 0;
|
int toughness = 0;
|
||||||
|
|
||||||
//check Exalted only for the first attacker
|
//check Exalted only for the first attacker
|
||||||
@@ -2121,6 +2122,25 @@ public class CombatUtil {
|
|||||||
toughness += CardFactoryUtil.xCount(source, bonus);
|
toughness += CardFactoryUtil.xCount(source, bonus);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (withoutAbilities) {
|
||||||
|
return toughness;
|
||||||
|
}
|
||||||
|
for (SpellAbility ability : attacker.getAllSpellAbilities()) {
|
||||||
|
if (!(ability instanceof AbilityActivated) || ability.getPayCosts() == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ability.getApi() != ApiType.Pump || !ability.hasParam("NumDef")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ability.getPayCosts().getTap() && ComputerUtil.canPayCost(ability, attacker.getController())) {
|
||||||
|
int tBonus = AbilityFactory.calculateAmount(ability.getSourceCard(), ability.getParam("NumDef"), ability);
|
||||||
|
if (tBonus > 0) {
|
||||||
|
toughness += tBonus;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return toughness;
|
return toughness;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2291,7 +2311,7 @@ public class CombatUtil {
|
|||||||
defenderDamage = defender.getNetDefense()
|
defenderDamage = defender.getNetDefense()
|
||||||
+ CombatUtil.predictToughnessBonusOfBlocker(attacker, defender, withoutAbilities);
|
+ CombatUtil.predictToughnessBonusOfBlocker(attacker, defender, withoutAbilities);
|
||||||
attackerDamage = attacker.getNetDefense()
|
attackerDamage = attacker.getNetDefense()
|
||||||
+ CombatUtil.predictToughnessBonusOfAttacker(attacker, defender, combat);
|
+ CombatUtil.predictToughnessBonusOfAttacker(attacker, defender, combat, withoutAbilities);
|
||||||
}
|
}
|
||||||
|
|
||||||
int possibleDefenderPrevention = 0;
|
int possibleDefenderPrevention = 0;
|
||||||
@@ -2308,7 +2328,7 @@ public class CombatUtil {
|
|||||||
final int defenderLife = defender.getKillDamage()
|
final int defenderLife = defender.getKillDamage()
|
||||||
+ CombatUtil.predictToughnessBonusOfBlocker(attacker, defender, withoutAbilities);
|
+ CombatUtil.predictToughnessBonusOfBlocker(attacker, defender, withoutAbilities);
|
||||||
final int attackerLife = attacker.getKillDamage()
|
final int attackerLife = attacker.getKillDamage()
|
||||||
+ CombatUtil.predictToughnessBonusOfAttacker(attacker, defender, combat);
|
+ CombatUtil.predictToughnessBonusOfAttacker(attacker, defender, combat, withoutAbilities);
|
||||||
|
|
||||||
if (defender.hasKeyword("Double Strike")) {
|
if (defender.hasKeyword("Double Strike")) {
|
||||||
if (defenderDamage > 0 && (defender.hasKeyword("Deathtouch")
|
if (defenderDamage > 0 && (defender.hasKeyword("Deathtouch")
|
||||||
@@ -2439,7 +2459,7 @@ public class CombatUtil {
|
|||||||
defenderDamage = defender.getNetDefense()
|
defenderDamage = defender.getNetDefense()
|
||||||
+ CombatUtil.predictToughnessBonusOfBlocker(attacker, defender, withoutAbilities);
|
+ CombatUtil.predictToughnessBonusOfBlocker(attacker, defender, withoutAbilities);
|
||||||
attackerDamage = attacker.getNetDefense()
|
attackerDamage = attacker.getNetDefense()
|
||||||
+ CombatUtil.predictToughnessBonusOfAttacker(attacker, defender, combat);
|
+ CombatUtil.predictToughnessBonusOfAttacker(attacker, defender, combat, withoutAbilities);
|
||||||
}
|
}
|
||||||
|
|
||||||
int possibleDefenderPrevention = 0;
|
int possibleDefenderPrevention = 0;
|
||||||
@@ -2464,7 +2484,7 @@ public class CombatUtil {
|
|||||||
final int defenderLife = defender.getKillDamage()
|
final int defenderLife = defender.getKillDamage()
|
||||||
+ CombatUtil.predictToughnessBonusOfBlocker(attacker, defender, withoutAbilities);
|
+ CombatUtil.predictToughnessBonusOfBlocker(attacker, defender, withoutAbilities);
|
||||||
final int attackerLife = attacker.getKillDamage()
|
final int attackerLife = attacker.getKillDamage()
|
||||||
+ CombatUtil.predictToughnessBonusOfAttacker(attacker, defender, combat);
|
+ CombatUtil.predictToughnessBonusOfAttacker(attacker, defender, combat, withoutAbilities);
|
||||||
|
|
||||||
if (attacker.hasKeyword("Double Strike")) {
|
if (attacker.hasKeyword("Double Strike")) {
|
||||||
if (attackerDamage > 0 && (attacker.hasKeyword("Deathtouch")
|
if (attackerDamage > 0 && (attacker.hasKeyword("Deathtouch")
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ public class ComputerUtilAttack {
|
|||||||
public final boolean isEffectiveAttacker(final Player ai, final Card attacker, final Combat combat) {
|
public final boolean isEffectiveAttacker(final Player ai, final Card attacker, final Combat combat) {
|
||||||
|
|
||||||
// if the attacker will die when attacking don't attack
|
// if the attacker will die when attacking don't attack
|
||||||
if ((attacker.getNetDefense() + CombatUtil.predictToughnessBonusOfAttacker(attacker, null, combat)) <= 0) {
|
if ((attacker.getNetDefense() + CombatUtil.predictToughnessBonusOfAttacker(attacker, null, combat, true)) <= 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -426,7 +426,7 @@ public class ComputerUtilBlock {
|
|||||||
CardLists.sortAttack(firstStrikeBlockers);
|
CardLists.sortAttack(firstStrikeBlockers);
|
||||||
for (final Card blocker : firstStrikeBlockers) {
|
for (final Card blocker : firstStrikeBlockers) {
|
||||||
final int damageNeeded = attacker.getKillDamage()
|
final int damageNeeded = attacker.getKillDamage()
|
||||||
+ CombatUtil.predictToughnessBonusOfAttacker(attacker, blocker, combat);
|
+ CombatUtil.predictToughnessBonusOfAttacker(attacker, blocker, combat, false);
|
||||||
// if the total damage of the blockgang was not enough
|
// if the total damage of the blockgang was not enough
|
||||||
// without but is enough with this blocker finish the
|
// without but is enough with this blocker finish the
|
||||||
// blockgang
|
// blockgang
|
||||||
@@ -493,7 +493,7 @@ public class ComputerUtilBlock {
|
|||||||
.getEnoughDamageToKill(attacker.getNetCombatDamage(), attacker, true);
|
.getEnoughDamageToKill(attacker.getNetCombatDamage(), attacker, true);
|
||||||
final int addedValue = CardFactoryUtil.evaluateCreature(blocker);
|
final int addedValue = CardFactoryUtil.evaluateCreature(blocker);
|
||||||
final int damageNeeded = attacker.getKillDamage()
|
final int damageNeeded = attacker.getKillDamage()
|
||||||
+ CombatUtil.predictToughnessBonusOfAttacker(attacker, blocker, combat);
|
+ CombatUtil.predictToughnessBonusOfAttacker(attacker, blocker, combat, false);
|
||||||
if ((damageNeeded > currentDamage || CombatUtil.needsBlockers(attacker) > blockGang.size())
|
if ((damageNeeded > currentDamage || CombatUtil.needsBlockers(attacker) > blockGang.size())
|
||||||
&& !(damageNeeded > currentDamage + additionalDamage)
|
&& !(damageNeeded > currentDamage + additionalDamage)
|
||||||
// The attacker will be killed
|
// The attacker will be killed
|
||||||
@@ -666,7 +666,7 @@ public class ComputerUtilBlock {
|
|||||||
safeBlockers = ComputerUtilBlock.getSafeBlockers(attacker, blockers, combat);
|
safeBlockers = ComputerUtilBlock.getSafeBlockers(attacker, blockers, combat);
|
||||||
for (final Card blocker : safeBlockers) {
|
for (final Card blocker : safeBlockers) {
|
||||||
final int damageNeeded = attacker.getKillDamage()
|
final int damageNeeded = attacker.getKillDamage()
|
||||||
+ CombatUtil.predictToughnessBonusOfAttacker(attacker, blocker, combat);
|
+ CombatUtil.predictToughnessBonusOfAttacker(attacker, blocker, combat, false);
|
||||||
// Add an additional blocker if the current blockers are not
|
// Add an additional blocker if the current blockers are not
|
||||||
// enough and the new one would deal additional damage
|
// enough and the new one would deal additional damage
|
||||||
if ((damageNeeded > CombatUtil.totalDamageOfBlockers(attacker, combat.getBlockers(attacker)))
|
if ((damageNeeded > CombatUtil.totalDamageOfBlockers(attacker, combat.getBlockers(attacker)))
|
||||||
@@ -690,7 +690,7 @@ public class ComputerUtilBlock {
|
|||||||
|
|
||||||
for (final Card blocker : safeBlockers) {
|
for (final Card blocker : safeBlockers) {
|
||||||
final int damageNeeded = attacker.getKillDamage()
|
final int damageNeeded = attacker.getKillDamage()
|
||||||
+ CombatUtil.predictToughnessBonusOfAttacker(attacker, blocker, combat);
|
+ CombatUtil.predictToughnessBonusOfAttacker(attacker, blocker, combat, false);
|
||||||
// Add an additional blocker if the current blockers are not
|
// Add an additional blocker if the current blockers are not
|
||||||
// enough and the new one would deal the remaining damage
|
// enough and the new one would deal the remaining damage
|
||||||
final int currentDamage = CombatUtil.totalDamageOfBlockers(attacker, combat.getBlockers(attacker));
|
final int currentDamage = CombatUtil.totalDamageOfBlockers(attacker, combat.getBlockers(attacker));
|
||||||
|
|||||||
Reference in New Issue
Block a user