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 661965db50..c818b917a6 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 @@ -89,6 +89,7 @@ public class ComputerPlayer6 extends ComputerPlayer implements private static final String FILE_WITH_INSTRUCTIONS = "config/ai.please.cast.this.txt"; private List suggested = new ArrayList(); + protected Set actionCache; private static final List optimizers = new ArrayList(); @@ -103,6 +104,7 @@ public class ComputerPlayer6 extends ComputerPlayer implements maxThink = skill * 300; maxNodes = Config2.maxNodes; getSuggestedActions(); + this.actionCache = new HashSet(); } public ComputerPlayer6(final ComputerPlayer6 player) { @@ -114,6 +116,7 @@ public class ComputerPlayer6 extends ComputerPlayer implements this.actions.addAll(player.actions); this.targets.addAll(player.targets); this.choices.addAll(player.choices); + this.actionCache = player.actionCache; } @Override @@ -512,6 +515,7 @@ public class ComputerPlayer6 extends ComputerPlayer implements sim.getPlayerList().getNext(); } SimulationNode2 newNode = new SimulationNode2(node, sim, action, depth, currentPlayer.getId()); + int testVal = GameStateEvaluator2.evaluate(currentPlayer.getId(), sim); logger.debug("simulating -- node #:" + SimulationNode2.getCount() + " actions:" + action); sim.checkStateAndTriggered(); int val = addActions(newNode, depth-1, alpha, beta); @@ -1243,15 +1247,25 @@ public class ComputerPlayer6 extends ComputerPlayer implements private boolean checkForRepeatedAction(Game sim, SimulationNode2 node, Ability action, UUID playerId) { if (action instanceof PassAbility) return false; - int val = GameStateEvaluator2.evaluate(playerId, sim); + int newVal = GameStateEvaluator2.evaluate(playerId, sim); SimulationNode2 test = node.getParent(); - while (test != null && !test.getPlayerId().equals(playerId)) { - test = test.getParent(); - } - if (test != null && test.getAbilities() != null && test.getAbilities().size() == 1) { - if (action.toString().equals(test.getAbilities().get(0).toString()) && GameStateEvaluator2.evaluate(playerId, test.getGame()) == val) { - return true; + while (test != null) { + if (test.getPlayerId().equals(playerId)) { + if (test.getAbilities() != null && test.getAbilities().size() == 1) { + if (action.toString().equals(test.getAbilities().get(0).toString())) { + if (test.getParent() != null) { + Game prevGame = node.getGame(); + if (prevGame != null) { + int oldVal = GameStateEvaluator2.evaluate(playerId, prevGame); + if (oldVal >= newVal) { + return true; + } + } + } + } + } } + test = test.getParent(); } return false; } diff --git a/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer7.java b/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer7.java index 7b6c02436f..9cefb922a1 100644 --- a/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer7.java +++ b/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer7.java @@ -39,9 +39,7 @@ import mage.game.turn.*; import mage.players.Player; import org.apache.log4j.Logger; -import java.util.LinkedList; -import java.util.List; -import java.util.UUID; +import java.util.*; /** * @@ -129,6 +127,7 @@ public class ComputerPlayer7 extends ComputerPlayer6 implements Player { return false; case END_TURN: case CLEANUP: + actionCache.clear(); pass(); return false; } @@ -148,11 +147,11 @@ public class ComputerPlayer7 extends ComputerPlayer6 implements Player { root = root.children.get(0); int bestScore = root.getScore(); //if (bestScore > currentScore || allowBadMoves) { - actions = new LinkedList(root.abilities); - combat = root.combat; - //} else { - //System.out.println("[" + game.getPlayer(playerId).getName() + "][pre] Action: not better score"); - //} + actions = new LinkedList(root.abilities); + combat = root.combat; + for (Ability ability : actions) { + actionCache.add(ability.getRule() + "_" + ability.getSourceId()); + } } else { System.out.println("[" + game.getPlayer(playerId).getName() + "][pre] Action: skip"); } diff --git a/Mage.Server/plugins/mage-player-ai-ma.jar b/Mage.Server/plugins/mage-player-ai-ma.jar index d8d96ca6da..2c678b13c2 100644 Binary files a/Mage.Server/plugins/mage-player-ai-ma.jar and b/Mage.Server/plugins/mage-player-ai-ma.jar differ