- Added the new AI function "hasAFogEffect".

This commit is contained in:
Sloth
2014-10-26 15:24:42 +00:00
parent 3da6b32a7b
commit baf0af3a24
2 changed files with 83 additions and 59 deletions

View File

@@ -754,65 +754,69 @@ public class AiBlockController {
// == 1. choose best blocks first == // == 1. choose best blocks first ==
makeGoodBlocks(combat); makeGoodBlocks(combat);
makeGangBlocks(combat); makeGangBlocks(combat);
if (ComputerUtilCombat.lifeInDanger(ai, combat)) {
makeTradeBlocks(combat); // choose necessary trade blocks
}
// if life is in danger
if (ComputerUtilCombat.lifeInDanger(ai, combat)) {
makeChumpBlocks(combat); // choose necessary chump blocks
}
// if life is still in danger
// Reinforce blockers blocking attackers with trample if life is still
// in danger
if (ComputerUtilCombat.lifeInDanger(ai, combat)) {
reinforceBlockersAgainstTrample(combat);
}
// Support blockers not destroying the attacker with more blockers to
// try to kill the attacker
if (!ComputerUtilCombat.lifeInDanger(ai, combat)) {
reinforceBlockersToKill(combat);
}
// == 2. If the AI life would still be in danger make a safer approach == // When the AI holds some Fog effect, don't bother about lifeInDanger
if (ComputerUtilCombat.lifeInDanger(ai, combat)) { if (!ComputerUtil.hasAFogEffect(ai)) {
lifeInDanger = true; if (ComputerUtilCombat.lifeInDanger(ai, combat)) {
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
makeGoodBlocks(combat); if (ComputerUtilCombat.lifeInDanger(ai, combat)) {
// choose necessary chump blocks if life is still in danger makeChumpBlocks(combat); // choose necessary chump blocks
if (ComputerUtilCombat.lifeInDanger(ai, combat)) { }
makeChumpBlocks(combat); // 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 // in danger
// still in danger if (ComputerUtilCombat.lifeInDanger(ai, combat)) {
if (ComputerUtilCombat.lifeInDanger(ai, combat)) { reinforceBlockersAgainstTrample(combat);
reinforceBlockersAgainstTrample(combat); }
} // Support blockers not destroying the attacker with more blockers to
makeGangBlocks(combat); // try to kill the attacker
reinforceBlockersToKill(combat); if (!ComputerUtilCombat.lifeInDanger(ai, combat)) {
} reinforceBlockersToKill(combat);
}
// == 3. If the AI life would be in serious danger make an even safer approach == // == 2. If the AI life would still be in danger make a safer approach ==
if (lifeInDanger && ComputerUtilCombat.lifeInSeriousDanger(ai, combat)) { if (ComputerUtilCombat.lifeInDanger(ai, combat)) {
clearBlockers(combat, possibleBlockers); // reset every block assignment lifeInDanger = true;
makeChumpBlocks(combat); // choose chump blocks clearBlockers(combat, possibleBlockers); // reset every block assignment
if (ComputerUtilCombat.lifeInDanger(ai, combat)) { makeTradeBlocks(combat); // choose necessary trade blocks
makeTradeBlocks(combat); // choose necessary trade // if life is in danger
} makeGoodBlocks(combat);
// choose necessary chump blocks if life is still in danger
if (ComputerUtilCombat.lifeInDanger(ai, combat)) {
makeChumpBlocks(combat);
}
// Reinforce blockers blocking attackers with trample if life is
// still in danger
if (ComputerUtilCombat.lifeInDanger(ai, combat)) {
reinforceBlockersAgainstTrample(combat);
}
makeGangBlocks(combat);
reinforceBlockersToKill(combat);
}
if (!ComputerUtilCombat.lifeInDanger(ai, combat)) { // == 3. If the AI life would be in serious danger make an even safer approach ==
makeGoodBlocks(combat); if (lifeInDanger && ComputerUtilCombat.lifeInSeriousDanger(ai, combat)) {
} clearBlockers(combat, possibleBlockers); // reset every block assignment
// Reinforce blockers blocking attackers with trample if life is makeChumpBlocks(combat); // choose chump blocks
// still in danger if (ComputerUtilCombat.lifeInDanger(ai, combat)) {
else { makeTradeBlocks(combat); // choose necessary trade
reinforceBlockersAgainstTrample(combat); }
}
makeGangBlocks(combat); if (!ComputerUtilCombat.lifeInDanger(ai, combat)) {
// Support blockers not destroying the attacker with more blockers makeGoodBlocks(combat);
// to try to kill the attacker }
reinforceBlockersToKill(combat); // Reinforce blockers blocking attackers with trample if life is
// still in danger
else {
reinforceBlockersAgainstTrample(combat);
}
makeGangBlocks(combat);
// Support blockers not destroying the attacker with more blockers
// to try to kill the attacker
reinforceBlockersToKill(combat);
}
} }
// assign blockers that have to block // assign blockers that have to block

View File

@@ -999,6 +999,26 @@ public class ComputerUtil {
return false; return false;
} }
public static boolean hasAFogEffect(final Player ai) {
final CardCollection all = new CardCollection(ai.getCardsIn(ZoneType.Battlefield));
all.addAll(ai.getCardsActivableInExternalZones(true));
all.addAll(ai.getCardsIn(ZoneType.Hand));
for (final Card c : all) {
for (final SpellAbility sa : c.getSpellAbilities()) {
if (sa.getApi() != ApiType.Fog) {
continue;
}
if (!ComputerUtilCost.canPayCost(sa, ai)) {
continue;
}
return true;
}
}
return false;
}
public static int possibleNonCombatDamage(Player ai) { public static int possibleNonCombatDamage(Player ai) {
int damage = 0; int damage = 0;
final CardCollection all = new CardCollection(ai.getCardsIn(ZoneType.Battlefield)); final CardCollection all = new CardCollection(ai.getCardsIn(ZoneType.Battlefield));