- Improved AI logic when attacking by applying AiBlockController logic block for each attacker

This commit is contained in:
excessum
2014-05-10 06:28:01 +00:00
parent b37be577cf
commit e382b29212
2 changed files with 31 additions and 5 deletions

View File

@@ -1005,6 +1005,9 @@ public class AiAttackController {
} }
} }
} }
if (AiBlockController.canBeBlockedProfitably(defendingOpponent, attacker)) {
canKillAllDangerous = false;
}
// if the creature cannot block and can kill all opponents they might as // if the creature cannot block and can kill all opponents they might as
// well attack, they do nothing staying back // well attack, they do nothing staying back

View File

@@ -652,10 +652,10 @@ public class AiBlockController {
/** Assigns blockers for the provided combat instance (in favor of player passes to ctor) */ /** Assigns blockers for the provided combat instance (in favor of player passes to ctor) */
public void assignBlockers(final Combat combat) { public void assignBlockers(final Combat combat) {
assignBlockers(combat, null); assignBlockers(combat, null, null);
} }
public void assignBlockers(final Combat combat, Card evalBlocker) { public void assignBlockers(final Combat combat, Card evalBlocker, Card evalAttacker) {
List<Card> possibleBlockers = null; List<Card> possibleBlockers = null;
if (evalBlocker == null) { if (evalBlocker == null) {
@@ -664,8 +664,12 @@ public class AiBlockController {
possibleBlockers = new ArrayList<Card>(); possibleBlockers = new ArrayList<Card>();
possibleBlockers.add(evalBlocker); possibleBlockers.add(evalBlocker);
} }
if (evalAttacker == null) {
attackers = sortPotentialAttackers(combat); attackers = sortPotentialAttackers(combat);
} else {
attackers = new ArrayList<Card>();
attackers.add(evalAttacker);
}
if (attackers.isEmpty()) { if (attackers.isEmpty()) {
return; return;
@@ -843,10 +847,16 @@ public class AiBlockController {
return first; return first;
} }
/**
* Decide if a creature is going to be used as a blocker (is only used for AnimateAi so far)
* @param ai controller of creature
* @param blocker creature to be evaluated (must NOT already be in combat)
* @return creature will be a blocker
*/
public static boolean shouldThisBlock(final Player ai, Card blocker) { public static boolean shouldThisBlock(final Player ai, Card blocker) {
AiBlockController aiBlk = new AiBlockController(ai); AiBlockController aiBlk = new AiBlockController(ai);
Combat combat = ai.getGame().getCombat(); Combat combat = ai.getGame().getCombat();
aiBlk.assignBlockers(combat, blocker); aiBlk.assignBlockers(combat, blocker, null);
if (combat.getAllBlockers().isEmpty()) { if (combat.getAllBlockers().isEmpty()) {
return false; return false;
} else { } else {
@@ -854,4 +864,17 @@ public class AiBlockController {
return true; return true;
} }
} }
/**
* Check if an attacker can be blocked profitably (ie. kill attacker)
* @param ai controller of attacking creature
* @param attacker attacking creature to evaluate
* @return attacker will die
*/
public static boolean canBeBlockedProfitably(final Player ai, Card attacker) {
AiBlockController aiBlk = new AiBlockController(ai);
Combat combat = new Combat(ai);
combat.addAttacker(attacker, ai);
aiBlk.assignBlockers(combat, null, attacker);
return ComputerUtilCombat.attackerWouldBeDestroyed(ai, attacker, combat);
}
} }