- Improvements in AiBlockController.

This commit is contained in:
Sloth
2015-07-21 11:59:53 +00:00
parent 6904268f80
commit 56a1c70bc5

View File

@@ -622,18 +622,20 @@ public class AiBlockController {
blockers.removeAll(combat.getBlockers(attacker)); blockers.removeAll(combat.getBlockers(attacker));
// Try to use safe blockers first // Try to use safe blockers first
safeBlockers = getSafeBlockers(combat, attacker, blockers); if (blockers.size() > 1) {
for (final Card blocker : safeBlockers) { safeBlockers = getSafeBlockers(combat, attacker, blockers);
final int damageNeeded = ComputerUtilCombat.getDamageToKill(attacker) for (final Card blocker : safeBlockers) {
+ ComputerUtilCombat.predictToughnessBonusOfAttacker(attacker, blocker, combat, false); final int damageNeeded = ComputerUtilCombat.getDamageToKill(attacker)
// Add an additional blocker if the current blockers are not + ComputerUtilCombat.predictToughnessBonusOfAttacker(attacker, blocker, combat, false);
// enough and the new one would deal additional damage // Add an additional blocker if the current blockers are not
if (damageNeeded > ComputerUtilCombat.totalDamageOfBlockers(attacker, combat.getBlockers(attacker)) // enough and the new one would deal additional damage
&& ComputerUtilCombat.dealsDamageAsBlocker(attacker, blocker) > 0 if (damageNeeded > ComputerUtilCombat.totalDamageOfBlockers(attacker, combat.getBlockers(attacker))
&& CombatUtil.canBlock(attacker, blocker, combat)) { && ComputerUtilCombat.dealsDamageAsBlocker(attacker, blocker) > 0
combat.addBlocker(attacker, blocker); && CombatUtil.canBlock(attacker, blocker, combat)) {
} combat.addBlocker(attacker, blocker);
blockers.remove(blocker); // Don't check them again next }
blockers.remove(blocker); // Don't check them again next
}
} }
// Try to add blockers that could be destroyed, but are worth less than the attacker // Try to add blockers that could be destroyed, but are worth less than the attacker
@@ -755,28 +757,32 @@ public class AiBlockController {
// When the AI holds some Fog effect, don't bother about lifeInDanger // When the AI holds some Fog effect, don't bother about lifeInDanger
if (!ComputerUtil.hasAFogEffect(ai)) { if (!ComputerUtil.hasAFogEffect(ai)) {
if (ComputerUtilCombat.lifeInDanger(ai, combat)) { lifeInDanger = ComputerUtilCombat.lifeInDanger(ai, combat);
if (lifeInDanger) {
makeTradeBlocks(combat); // choose necessary trade blocks makeTradeBlocks(combat); // choose necessary trade blocks
} }
// if life is in danger // if life is still in danger
if (ComputerUtilCombat.lifeInDanger(ai, combat)) { if (lifeInDanger && ComputerUtilCombat.lifeInDanger(ai, combat)) {
makeChumpBlocks(combat); // choose necessary chump blocks makeChumpBlocks(combat); // choose necessary chump blocks
} } else {
lifeInDanger = false;
}
// if life is still in danger // if life is still in danger
// Reinforce blockers blocking attackers with trample if life is still // Reinforce blockers blocking attackers with trample if life is still
// in danger // in danger
if (ComputerUtilCombat.lifeInDanger(ai, combat)) { if (lifeInDanger && ComputerUtilCombat.lifeInDanger(ai, combat)) {
reinforceBlockersAgainstTrample(combat); reinforceBlockersAgainstTrample(combat);
} } else {
lifeInDanger = false;
}
// Support blockers not destroying the attacker with more blockers to // Support blockers not destroying the attacker with more blockers to
// try to kill the attacker // try to kill the attacker
if (!ComputerUtilCombat.lifeInDanger(ai, combat)) { if (!lifeInDanger) {
reinforceBlockersToKill(combat); reinforceBlockersToKill(combat);
} }
// == 2. If the AI life would still be in danger make a safer approach == // == 2. If the AI life would still be in danger make a safer approach ==
if (ComputerUtilCombat.lifeInDanger(ai, combat)) { if (lifeInDanger && ComputerUtilCombat.lifeInDanger(ai, combat)) {
lifeInDanger = true;
clearBlockers(combat, possibleBlockers); // reset every block assignment clearBlockers(combat, possibleBlockers); // reset every block assignment
makeTradeBlocks(combat); // choose necessary trade blocks makeTradeBlocks(combat); // choose necessary trade blocks
// if life is in danger // if life is in danger
@@ -784,11 +790,15 @@ public class AiBlockController {
// choose necessary chump blocks if life is still in danger // choose necessary chump blocks if life is still in danger
if (ComputerUtilCombat.lifeInDanger(ai, combat)) { if (ComputerUtilCombat.lifeInDanger(ai, combat)) {
makeChumpBlocks(combat); makeChumpBlocks(combat);
} else {
lifeInDanger = false;
} }
// Reinforce blockers blocking attackers with trample if life is // Reinforce blockers blocking attackers with trample if life is
// still in danger // still in danger
if (ComputerUtilCombat.lifeInDanger(ai, combat)) { if (lifeInDanger && ComputerUtilCombat.lifeInDanger(ai, combat)) {
reinforceBlockersAgainstTrample(combat); reinforceBlockersAgainstTrample(combat);
} else {
lifeInDanger = false;
} }
makeGangBlocks(combat); makeGangBlocks(combat);
reinforceBlockersToKill(combat); reinforceBlockersToKill(combat);