- Fixed AI preferring blocking attackers attacking his planeswalkers.

This commit is contained in:
Sloth
2015-04-14 18:46:42 +00:00
parent 6dacb83c37
commit 8944b7dfdd

View File

@@ -54,26 +54,17 @@ public class AiBlockController {
/** Constant <code>attackers</code>. */ /** Constant <code>attackers</code>. */
private List<Card> attackers = new ArrayList<Card>(); // all attackers private List<Card> attackers = new ArrayList<Card>(); // all attackers
/** Constant <code>attackersLeft</code>. */ /** Constant <code>attackersLeft</code>. */
private List<Card> attackersLeft = new ArrayList<Card>(); // keeps track of private List<Card> attackersLeft = new ArrayList<Card>(); // keeps track of all currently unblocked attackers
// all currently
// unblocked
// attackers
/** Constant <code>blockedButUnkilled</code>. */ /** Constant <code>blockedButUnkilled</code>. */
private List<Card> blockedButUnkilled = new ArrayList<Card>(); // blocked private List<Card> blockedButUnkilled = new ArrayList<Card>(); // blocked attackers that currently wouldn't be destroyed
// attackers
// that
// currently
// wouldn't be
// destroyed
/** Constant <code>blockersLeft</code>. */ /** Constant <code>blockersLeft</code>. */
private List<Card> blockersLeft = new ArrayList<Card>(); // keeps track of all private List<Card> blockersLeft = new ArrayList<Card>(); // keeps track of all unassigned blockers
// unassigned
// blockers
private int diff = 0; private int diff = 0;
private boolean lifeInDanger = false; private boolean lifeInDanger = false;
public AiBlockController(Player aiPlayer) { public AiBlockController(Player aiPlayer) {
this.ai = aiPlayer; ai = aiPlayer;
} }
// finds the creatures able to block the attacker // finds the creatures able to block the attacker
@@ -81,8 +72,7 @@ public class AiBlockController {
final List<Card> blockers = new ArrayList<Card>(); final List<Card> blockers = new ArrayList<Card>();
for (final Card blocker : blockersLeft) { for (final Card blocker : blockersLeft) {
// if the blocker can block a creature with lure it can't block a // if the blocker can block a creature with lure it can't block a creature without
// creature without
if (CombatUtil.canBlock(attacker, blocker, combat)) { if (CombatUtil.canBlock(attacker, blocker, combat)) {
if (solo && blocker.hasKeyword("CARDNAME can't attack or block alone.")) { if (solo && blocker.hasKeyword("CARDNAME can't attack or block alone.")) {
continue; continue;
@@ -120,44 +110,38 @@ public class AiBlockController {
return blockers; return blockers;
} }
private static List<CardCollection> sortAttackerByDefender(final Combat combat) {
FCollectionView<GameEntity> defenders = combat.getDefenders();
final ArrayList<CardCollection> attackers = new ArrayList<CardCollection>(defenders.size());
for (GameEntity defender : defenders) {
attackers.add(combat.getAttackersOf(defender));
}
return attackers;
}
private List<Card> sortPotentialAttackers(final Combat combat) { private List<Card> sortPotentialAttackers(final Combat combat) {
final List<CardCollection> attackerLists = sortAttackerByDefender(combat);
final CardCollection sortedAttackers = new CardCollection(); final CardCollection sortedAttackers = new CardCollection();
final CardCollection firstAttacker = attackerLists.get(0); CardCollection firstAttacker = new CardCollection();
final FCollectionView<GameEntity> defenders = combat.getDefenders(); final FCollectionView<GameEntity> defenders = combat.getDefenders();
// Begin with the attackers that pose the biggest threat
ComputerUtilCard.sortByEvaluateCreature(firstAttacker);
CardLists.sortByPowerDesc(firstAttacker);
// If I don't have any planeswalkers than sorting doesn't really matter // If I don't have any planeswalkers then sorting doesn't really matter
if (defenders.size() == 1) { if (defenders.size() == 1) {
return firstAttacker; final CardCollection attackers = combat.getAttackersOf(defenders.get(0));
// Begin with the attackers that pose the biggest threat
ComputerUtilCard.sortByEvaluateCreature(attackers);
CardLists.sortByPowerDesc(attackers);
return attackers;
} }
final boolean bLifeInDanger = ComputerUtilCombat.lifeInDanger(ai, combat); final boolean bLifeInDanger = ComputerUtilCombat.lifeInDanger(ai, combat);
// TODO Add creatures attacking Planeswalkers in order of which we want // TODO Add creatures attacking Planeswalkers in order of which we want to protect
// to protect // defend planeswalkers with more loyalty before planeswalkers with less loyalty
// defend planeswalkers with more loyalty before planeswalkers with less
// loyalty
// if planeswalker will be too difficult to defend don't even bother // if planeswalker will be too difficult to defend don't even bother
for (List<Card> attacker : attackerLists) { for (GameEntity defender : defenders) {
if (defender instanceof Card) {
final CardCollection attackers = combat.getAttackersOf(defender);
// Begin with the attackers that pose the biggest threat // Begin with the attackers that pose the biggest threat
CardLists.sortByPowerDesc(attacker); CardLists.sortByPowerDesc(attackers);
for (final Card c : attacker) { for (final Card c : attackers) {
sortedAttackers.add(c); sortedAttackers.add(c);
} }
} else {
firstAttacker = combat.getAttackersOf(defender);
}
} }
if (bLifeInDanger) { if (bLifeInDanger) {