From 80d3e6bd9a4ffb6fcb090f03fc3059675535dc74 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Fri, 27 Feb 2015 15:04:42 +0100 Subject: [PATCH] Fixed a bug of AI target selection that caused endless loops during build of test project. --- .../main/java/mage/player/ai/ComputerPlayer.java | 14 ++++++++++---- .../oneshot/sacrifice/MorticianBeetleTest.java | 2 +- .../abilities/effects/common/SacrificeEffect.java | 14 +++++++------- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java b/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java index 83df4dce0e..a05390f98a 100644 --- a/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java +++ b/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java @@ -75,6 +75,8 @@ import java.io.IOException; import java.io.Serializable; import java.util.*; import java.util.Map.Entry; +import mage.filter.Filter; +import mage.filter.predicate.other.PlayerIdPredicate; /** @@ -1947,10 +1949,14 @@ public class ComputerPlayer extends PlayerImpl implements Player { } protected List threats(UUID playerId, UUID sourceId, FilterPermanent filter, Game game, List targets) { - List threats = (playerId == null || sourceId ==null) ? - game.getBattlefield().getActivePermanents(filter, this.getId(), sourceId, game) : // all permanents within the range of the player - game.getBattlefield().getActivePermanents(filter, playerId, sourceId, game); - + List threats; + if (playerId == null) { + threats = game.getBattlefield().getActivePermanents(filter, this.getId(), sourceId, game); // all permanents within the range of the player + } else { + FilterPermanent filterCopy = filter.copy(); + filterCopy.add(new PlayerIdPredicate(playerId)); + threats = game.getBattlefield().getActivePermanents(filter, this.getId(), sourceId, game); + } Iterator it = threats.iterator(); while (it.hasNext()) { // remove permanents already targeted Permanent test = it.next(); diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/oneshot/sacrifice/MorticianBeetleTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/oneshot/sacrifice/MorticianBeetleTest.java index c6e1535f5d..9d109b6a75 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/oneshot/sacrifice/MorticianBeetleTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/oneshot/sacrifice/MorticianBeetleTest.java @@ -11,7 +11,7 @@ import org.mage.test.serverside.base.CardTestPlayerBase; public class MorticianBeetleTest extends CardTestPlayerBase { /** - * Checks that pro black can still be sacrificed + * Checks that creature with protection black can still be sacrificed */ @Test public void testSacrifice() { diff --git a/Mage/src/mage/abilities/effects/common/SacrificeEffect.java b/Mage/src/mage/abilities/effects/common/SacrificeEffect.java index cf60125351..3b635c7b7f 100644 --- a/Mage/src/mage/abilities/effects/common/SacrificeEffect.java +++ b/Mage/src/mage/abilities/effects/common/SacrificeEffect.java @@ -52,19 +52,19 @@ public class SacrificeEffect extends OneShotEffect{ private String preText; private DynamicValue count; - public SacrificeEffect ( FilterPermanent filter, DynamicValue count, String preText ) { + public SacrificeEffect (FilterPermanent filter, int count, String preText ) { + this(filter, new StaticValue(count), preText); + } + + public SacrificeEffect (FilterPermanent filter, DynamicValue count, String preText ) { super(Outcome.Sacrifice); this.filter = filter; this.count = count; this.preText = preText; setText(); } - - public SacrificeEffect ( FilterPermanent filter, int count, String preText ) { - this(filter, new StaticValue(count), preText); - } - - public SacrificeEffect ( final SacrificeEffect effect ) { + + public SacrificeEffect (final SacrificeEffect effect ) { super(effect); this.filter = effect.filter; this.count = effect.count;