diff --git a/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer6.java b/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer6.java index 29d0ee5449..ad8247669a 100644 --- a/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer6.java +++ b/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer6.java @@ -428,7 +428,7 @@ public class ComputerPlayer6 extends ComputerPlayer implements * @return */ protected Integer addActionsTimed() { - FutureTask task = new FutureTask(new Callable() { + FutureTask task = new FutureTask<>(new Callable() { @Override public Integer call() throws Exception { return addActions(root, maxDepth, Integer.MIN_VALUE, Integer.MAX_VALUE); @@ -528,6 +528,7 @@ public class ComputerPlayer6 extends ComputerPlayer implements break; } Game sim = game.copy(); + sim.setSimulation(true); if (sim.getPlayer(currentPlayer.getId()).activateAbility((ActivatedAbility) action.copy(), sim)) { sim.applyEffects(); if (checkForRepeatedAction(sim, node, action, currentPlayer.getId())) { @@ -867,7 +868,7 @@ public class ComputerPlayer6 extends ComputerPlayer implements } private List filterOutNonblocking(Game game, List attackers, List blockers) { - List blockersLeft = new ArrayList(); + List blockersLeft = new ArrayList<>(); for (Permanent blocker : blockers) { for (Permanent attacker : attackers) { if (blocker.canBlock(attacker.getId(), game)) { @@ -880,7 +881,7 @@ public class ComputerPlayer6 extends ComputerPlayer implements } private List filterOutUnblockable(Game game, List attackers, List blockers) { - List attackersLeft = new ArrayList(); + List attackersLeft = new ArrayList<>(); for (Permanent attacker : attackers) { if (CombatUtil.canBeBlocked(game, attacker, blockers)) { attackersLeft.add(attacker); @@ -895,7 +896,7 @@ public class ComputerPlayer6 extends ComputerPlayer implements return null; } - List attackers = new ArrayList(); + List attackers = new ArrayList<>(); for (UUID attackerId : attackersUUID) { Permanent permanent = game.getPermanent(attackerId); attackers.add(permanent); @@ -1291,6 +1292,7 @@ public class ComputerPlayer6 extends ComputerPlayer implements */ protected Game createSimulation(Game game) { Game sim = game.copy(); + sim.setSimulation(true); for (Player copyPlayer : sim.getState().getPlayers().values()) { Player origPlayer = game.getState().getPlayers().get(copyPlayer.getId()).copy(); if (!suggested.isEmpty()) { diff --git a/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/SimulatedPlayer2.java b/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/SimulatedPlayer2.java index 449c742f3f..461e09be3a 100644 --- a/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/SimulatedPlayer2.java +++ b/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/SimulatedPlayer2.java @@ -28,13 +28,20 @@ package mage.player.ai; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.UUID; import java.util.concurrent.ConcurrentLinkedQueue; -import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.Ability; import mage.abilities.TriggeredAbility; import mage.abilities.common.PassAbility; import mage.abilities.costs.mana.ManaCost; +import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.costs.mana.VariableManaCost; import mage.abilities.effects.Effect; import mage.cards.Card; @@ -48,7 +55,6 @@ import mage.players.Player; import mage.target.Target; import org.apache.log4j.Logger; - /** * * @author BetaSteward_at_googlemail.com @@ -56,12 +62,12 @@ import org.apache.log4j.Logger; public class SimulatedPlayer2 extends ComputerPlayer { private static final transient Logger logger = Logger.getLogger(SimulatedPlayer2.class); - private boolean isSimulatedPlayer; + private final boolean isSimulatedPlayer; private transient ConcurrentLinkedQueue allActions; private boolean forced; private static PassAbility pass = new PassAbility(); - private List suggested; + private final List suggested; public SimulatedPlayer2(UUID id, boolean isSimulatedPlayer, List suggested) { super(id); @@ -73,7 +79,7 @@ public class SimulatedPlayer2 extends ComputerPlayer { public SimulatedPlayer2(final SimulatedPlayer2 player) { super(player); this.isSimulatedPlayer = player.isSimulatedPlayer; - this.suggested = new ArrayList(); + this.suggested = new ArrayList<>(); for (String s : player.suggested) { this.suggested.add(s); } @@ -86,13 +92,13 @@ public class SimulatedPlayer2 extends ComputerPlayer { } public List simulatePriority(Game game) { - allActions = new ConcurrentLinkedQueue(); + allActions = new ConcurrentLinkedQueue<>(); Game sim = game.copy(); - + sim.setSimulation(true); forced = false; simulateOptions(sim); - ArrayList list = new ArrayList(allActions); + ArrayList list = new ArrayList<>(allActions); Collections.reverse(list); if (!forced) { @@ -170,7 +176,9 @@ public class SimulatedPlayer2 extends ComputerPlayer { // add the specific value for x newAbility.getManaCostsToPay().add(new ManaCostsImpl(new StringBuilder("{").append(xAmount).append("}").toString())); newAbility.getManaCostsToPay().setX(xAmount); - varCost.setPaid(); + if (varCost != null) { + varCost.setPaid(); + } card.adjustTargets(newAbility, game); // add the different possible target option for the specific X value if (newAbility.getTargets().getUnchosen().size() > 0) { @@ -211,7 +219,7 @@ public class SimulatedPlayer2 extends ComputerPlayer { if (suggested == null || suggested.isEmpty()) { return playables; } - List filtered = new ArrayList(); + List filtered = new ArrayList<>(); for (Ability ability : playables) { Card card = game.getCard(ability.getSourceId()); for (String s : suggested) { @@ -235,7 +243,7 @@ public class SimulatedPlayer2 extends ComputerPlayer { if (suggested == null || suggested.isEmpty()) { return options; } - List filtered = new ArrayList(); + List filtered = new ArrayList<>(); for (Ability option : options) { if (option.getTargets().size() > 0 && option.getTargets().get(0).getMaxNumberOfTargets() == 1) { Card card = game.getCard(ability.getSourceId()); @@ -245,15 +253,15 @@ public class SimulatedPlayer2 extends ComputerPlayer { if (groups.length == 2) { if (groups[0].equals(card.getName()) && groups[1].startsWith("name=")) { // extract target and compare to suggested - String name = groups[1].split("=")[1]; + String targetName = groups[1].split("=")[1]; Player player = game.getPlayer(option.getFirstTarget()); - if (player != null && name.equals(player.getName())) { + if (player != null && targetName.equals(player.getName())) { System.out.println("matched(option): " + s); filtered.add(option); return filtered; } else { Card target = game.getCard(option.getFirstTarget()); - if (target != null && target.getName().equals(name)) { + if (target != null && target.getName().equals(targetName)) { System.out.println("matched(option): " + s); filtered.add(option); return filtered; @@ -323,7 +331,7 @@ public class SimulatedPlayer2 extends ComputerPlayer { } public List addAttackers(Game game) { - Map engagements = new HashMap(); + Map engagements = new HashMap<>(); //useful only for two player games - will only attack first opponent UUID defenderId = game.getOpponents(playerId).iterator().next(); List attackersList = super.getAvailableAttackers(game); @@ -338,8 +346,9 @@ public class SimulatedPlayer2 extends ComputerPlayer { binary.insert(0, "0"); } for (int j = 0; j < attackersList.size(); j++) { - if (binary.charAt(j) == '1') + if (binary.charAt(j) == '1') { sim.getCombat().declareAttacker(attackersList.get(j).getId(), defenderId, sim); + } } if (engagements.put(sim.getCombat().getValue().hashCode(), sim.getCombat()) != null) { logger.debug("simulating -- found redundant attack combination"); @@ -348,7 +357,7 @@ public class SimulatedPlayer2 extends ComputerPlayer { logger.debug("simulating -- attack:" + sim.getCombat().getGroups().size()); } } - List list = new ArrayList(engagements.values()); + List list = new ArrayList<>(engagements.values()); Collections.sort(list, new Comparator() { @Override public int compare(Combat o1, Combat o2) { @@ -359,9 +368,11 @@ public class SimulatedPlayer2 extends ComputerPlayer { } public List addBlockers(Game game) { - Map engagements = new HashMap(); + Map engagements = new HashMap<>(); int numGroups = game.getCombat().getGroups().size(); - if (numGroups == 0) return new ArrayList(); + if (numGroups == 0) { + return new ArrayList<>(); + } //add a node with no blockers Game sim = game.copy(); @@ -371,12 +382,13 @@ public class SimulatedPlayer2 extends ComputerPlayer { List blockers = getAvailableBlockers(game); addBlocker(game, blockers, engagements); - return new ArrayList(engagements.values()); + return new ArrayList<>(engagements.values()); } protected void addBlocker(Game game, List blockers, Map engagements) { - if (blockers.isEmpty()) + if (blockers.isEmpty()) { return; + } int numGroups = game.getCombat().getGroups().size(); //try to block each attacker with each potential blocker Permanent blocker = blockers.get(0); @@ -386,8 +398,9 @@ public class SimulatedPlayer2 extends ComputerPlayer { if (game.getCombat().getGroups().get(i).canBlock(blocker, game)) { Game sim = game.copy(); sim.getCombat().getGroups().get(i).addBlocker(blocker.getId(), playerId, sim); - if (engagements.put(sim.getCombat().getValue().hashCode(), sim.getCombat()) != null) + if (engagements.put(sim.getCombat().getValue().hashCode(), sim.getCombat()) != null) { logger.debug("simulating -- found redundant block combination"); + } addBlocker(sim, remaining, engagements); // and recurse minus the used blocker } } @@ -408,7 +421,9 @@ public class SimulatedPlayer2 extends ComputerPlayer { else { SimulationNode2 parent = (SimulationNode2) game.getCustomData(); int depth = parent.getDepth() - 1; - if (depth == 0) return true; + if (depth == 0) { + return true; + } logger.debug("simulating -- triggered ability - adding children:" + options.size()); for (Ability option: options) { addAbilityNode(parent, option, depth, game);