From 4a74fe87fc8543c103a244a5b12ebe558af9d1e5 Mon Sep 17 00:00:00 2001 From: elcnesh Date: Tue, 27 Jan 2015 14:22:03 +0000 Subject: [PATCH] Fix some possible issues with attack constraints and how the AI handles them. --- .../src/main/java/forge/game/combat/AttackConstraints.java | 7 +++++-- forge-game/src/main/java/forge/game/combat/Combat.java | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/forge-game/src/main/java/forge/game/combat/AttackConstraints.java b/forge-game/src/main/java/forge/game/combat/AttackConstraints.java index 57c71bf8840..be27e86d7d2 100644 --- a/forge-game/src/main/java/forge/game/combat/AttackConstraints.java +++ b/forge-game/src/main/java/forge/game/combat/AttackConstraints.java @@ -145,11 +145,11 @@ public class AttackConstraints { final Set types = restrictions.get(attacker).getTypes(); if (types.contains(AttackRestrictionType.NEED_BLACK_OR_GREEN)) { // It's insufficient if this attacker is B/G itself, so filter itself out! - if (CardLists.filter(myPossibleAttackers, CardPredicates.isColor((byte) (MagicColor.BLACK | MagicColor.GREEN)), Predicates.not(Predicates.equalTo(attacker))).size() == 0) { + if (CardLists.filter(myPossibleAttackers, CardPredicates.isColor((byte) (MagicColor.BLACK | MagicColor.GREEN)), Predicates.not(Predicates.equalTo(attacker))).isEmpty()) { attackersToRemove.add(attacker); } } else if (types.contains(AttackRestrictionType.NEED_GREATER_POWER)) { - if (CardLists.filter(myPossibleAttackers, CardPredicates.hasGreaterPowerThan(attacker.getNetPower())).size() == 0) { + if (CardLists.filter(myPossibleAttackers, CardPredicates.hasGreaterPowerThan(attacker.getNetPower())).isEmpty()) { attackersToRemove.add(attacker); } } @@ -291,10 +291,13 @@ public class AttackConstraints { toDefender.add(req.defender); reqs.removeAll(findAll(reqs, req.attacker)); reserved.remove(req.attacker); + localMaximum--; // need two other attackers: set that number to the number of attackers we still need (but never < 0) if (restrictions.get(req.attacker).getTypes().contains(AttackRestrictionType.NEED_TWO_OTHERS)) { + final int previousNeeded = attackersNeeded; attackersNeeded = Ints.max(3 - (myAttackers.size() + reserved.size()), 0); + localMaximum -= Ints.max(attackersNeeded - previousNeeded, 0); } } diff --git a/forge-game/src/main/java/forge/game/combat/Combat.java b/forge-game/src/main/java/forge/game/combat/Combat.java index ba489ed528c..b9876c106f6 100644 --- a/forge-game/src/main/java/forge/game/combat/Combat.java +++ b/forge-game/src/main/java/forge/game/combat/Combat.java @@ -109,7 +109,9 @@ public class Combat { } public final void clearAttackers() { - attackedByBands.clear(); + for (final Card attacker : getAttackers()) { + removeFromCombat(attacker); + } } public final Player getAttackingPlayer() {