diff --git a/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer4.java b/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer4.java index 8e606aed33..52b80e504f 100644 --- a/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer4.java +++ b/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer4.java @@ -48,6 +48,7 @@ import mage.abilities.Ability; import mage.abilities.ActivatedAbility; import mage.abilities.effects.Effect; import mage.abilities.effects.SearchEffect; +import mage.cards.Card; import mage.cards.Cards; import mage.choices.Choice; import mage.filter.FilterAbility; @@ -55,6 +56,7 @@ import mage.game.Game; import mage.game.combat.Combat; import mage.game.combat.CombatGroup; import mage.game.events.GameEvent; +import mage.game.permanent.Permanent; import mage.game.stack.StackAbility; import mage.game.stack.StackObject; import mage.game.turn.BeginCombatStep; @@ -136,18 +138,39 @@ public class ComputerPlayer4 extends ComputerPlayer implements pass(); break; case PRECOMBAT_MAIN: - case BEGIN_COMBAT: - case DECLARE_ATTACKERS: - case DECLARE_BLOCKERS: - case COMBAT_DAMAGE: - case END_COMBAT: case POSTCOMBAT_MAIN: + if (game.getActivePlayerId().equals(playerId)) { + Player player = game.getPlayer(playerId); + System.out.println("Turn::"+game.getTurnNum()); + System.out.println("[" + game.getPlayer(playerId).getName() + "] " + game.getTurn().getStepType().name() +", life=" + player.getLife()); + String s = "["; + for (Card card : player.getHand().getCards(game)) { + s += card.getName() + ";"; + } + s += "]"; + System.out.println("Hand: " + s); + s = "["; + for (Permanent permanent : game.getBattlefield().getAllPermanents()) { + if (permanent.getOwnerId().equals(player.getId())) { + s += permanent.getName() + ";"; + } + } + s += "]"; + System.out.println("Permanents: " + s); + } if (actions.size() == 0) { calculateActions(game); } act(game); break; + case BEGIN_COMBAT: + case DECLARE_ATTACKERS: + case DECLARE_BLOCKERS: + case COMBAT_DAMAGE: + case END_COMBAT: case END_TURN: + pass(); + break; case CLEANUP: pass(); break; @@ -181,8 +204,11 @@ public class ComputerPlayer4 extends ComputerPlayer implements addActionsTimed(new FilterAbility()); if (root.children.size() > 0) { root = root.children.get(0); - actions = new LinkedList(root.abilities); - combat = root.combat; + int bestScore = GameStateEvaluator2.evaluate(playerId, root.getGame()); + if (bestScore > currentScore) { + actions = new LinkedList(root.abilities); + combat = root.combat; + } } } } @@ -243,11 +269,11 @@ public class ComputerPlayer4 extends ComputerPlayer implements if (bestChild != null) node.children.add(bestChild); if (!currentPlayerId.equals(playerId)) { - logger.info("returning minimax beta: " + beta); + //logger.info("returning minimax beta: " + beta); return beta; } else { - logger.info("returning minimax alpha: " + alpha); + //logger.info("returning minimax alpha: " + alpha); return alpha; } } @@ -311,7 +337,7 @@ public class ComputerPlayer4 extends ComputerPlayer implements } protected int addActions(SimulationNode2 node, FilterAbility filter, int depth, int alpha, int beta) { - logger.info("addActions: " + depth + ", alpha=" + alpha + ", beta=" + beta); + logger.fine("addActions: " + depth + ", alpha=" + alpha + ", beta=" + beta); Game game = node.getGame(); int val; if (Thread.interrupted()) { @@ -320,16 +346,16 @@ public class ComputerPlayer4 extends ComputerPlayer implements return GameStateEvaluator2.evaluate(playerId, game); } if (depth <= 0 || SimulationNode2.nodeCount > maxNodes || game.isGameOver()) { - logger.info("simulating -- reached end state, node count="+ SimulationNode2.nodeCount + ", depth="+depth); + logger.fine("simulating -- reached end state, node count="+ SimulationNode2.nodeCount + ", depth="+depth); val = GameStateEvaluator2.evaluate(playerId, game); } else if (node.getChildren().size() > 0) { - logger.info("simulating -- somthing added children:" + node.getChildren().size()); + logger.fine("simulating -- somthing added children:" + node.getChildren().size()); val = minimaxAB(node, filter, depth-1, alpha, beta); } else { if (logger.isLoggable(Level.FINE)) - logger.info("simulating -- alpha: " + alpha + " beta: " + beta + " depth:" + depth + " step:" + game.getTurn().getStepType() + " for player:" + (node.getPlayerId().equals(playerId)?"yes":"no")); + logger.fine("simulating -- alpha: " + alpha + " beta: " + beta + " depth:" + depth + " step:" + game.getTurn().getStepType() + " for player:" + (node.getPlayerId().equals(playerId)?"yes":"no")); if (allPassed(game)) { if (!game.getStack().isEmpty()) { resolve(node, depth, game); @@ -350,10 +376,9 @@ public class ComputerPlayer4 extends ComputerPlayer implements val = GameStateEvaluator2.evaluate(playerId, game); } else if (node.getChildren().size() > 0) { - throw new RuntimeException("This shouldn't happen."); //declared attackers or blockers or triggered abilities - ///logger.info("simulating -- attack/block/trigger added children:" + node.getChildren().size()); - ///val = minimaxAB(node, filter, depth-1, alpha, beta); + logger.fine("simulating -- attack/block/trigger added children:" + node.getChildren().size()); + val = minimaxAB(node, filter, depth-1, alpha, beta); } else { val = simulatePriority(node, game, filter, depth, alpha, beta); @@ -361,7 +386,7 @@ public class ComputerPlayer4 extends ComputerPlayer implements } if (logger.isLoggable(Level.FINE)) - logger.info("returning -- score: " + val + " depth:" + depth + " step:" + game.getTurn().getStepType() + " for player:" + game.getPlayer(node.getPlayerId()).getName()); + logger.fine("returning -- score: " + val + " depth:" + depth + " step:" + game.getTurn().getStepType() + " for player:" + game.getPlayer(node.getPlayerId()).getName()); return val; } @@ -378,7 +403,7 @@ public class ComputerPlayer4 extends ComputerPlayer implements SimulationNode2 bestNode = null; List allActions = currentPlayer.simulatePriority(game, filter); if (logger.isLoggable(Level.FINE)) - logger.info("simulating -- adding " + allActions.size() + " children:" + allActions); + logger.fine("simulating -- adding " + allActions.size() + " children:" + allActions); for (Ability action: allActions) { Game sim = game.copy(); if (sim.getPlayer(currentPlayer.getId()).activateAbility((ActivatedAbility) action.copy(), sim)) { @@ -390,7 +415,7 @@ public class ComputerPlayer4 extends ComputerPlayer implements } SimulationNode2 newNode = new SimulationNode2(sim, action, depth, currentPlayer.getId()); if (logger.isLoggable(Level.FINE)) - logger.info("simulating -- node #:" + SimulationNode2.getCount() + " actions:" + action); + logger.fine("simulating -- node #:" + SimulationNode2.getCount() + " actions:" + action); sim.checkStateAndTriggered(); int val = addActions(newNode, filter, depth-1, alpha, beta); if (!currentPlayer.getId().equals(playerId)) { @@ -416,7 +441,7 @@ public class ComputerPlayer4 extends ComputerPlayer implements break; } if (SimulationNode2.nodeCount > maxNodes) { - logger.info("simulating -- reached end-state"); + logger.fine("simulating -- reached end-state"); break; } } diff --git a/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer5.java b/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer5.java index 9ab60808bd..f320a1da3d 100644 --- a/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer5.java +++ b/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer5.java @@ -112,6 +112,7 @@ public class ComputerPlayer5 extends ComputerPlayer4 implements Player { case PRECOMBAT_MAIN: if (game.getActivePlayerId().equals(playerId)) { Player player = game.getPlayer(playerId); + System.out.println("Turn:"+game.getTurnNum()); System.out.println("[" + game.getPlayer(playerId).getName() + "] Precombat Main, life=" + player.getLife()); String s = "["; for (Card card : player.getHand().getCards(game)) { @@ -181,8 +182,11 @@ public class ComputerPlayer5 extends ComputerPlayer4 implements Player { addActionsTimed(new FilterAbility()); if (root.children.size() > 0) { root = root.children.get(0); - actions = new LinkedList(root.abilities); - combat = root.combat; + int bestScore = GameStateEvaluator2.evaluate(playerId, root.getGame()); + if (bestScore > currentScore) { + actions = new LinkedList(root.abilities); + combat = root.combat; + } } //} } @@ -197,8 +201,11 @@ public class ComputerPlayer5 extends ComputerPlayer4 implements Player { addActionsTimed(new FilterAbility()); if (root.children.size() > 0) { root = root.children.get(0); - actions = new LinkedList(root.abilities); - combat = root.combat; + int bestScore = GameStateEvaluator2.evaluate(playerId, root.getGame()); + if (bestScore > currentScore) { + actions = new LinkedList(root.abilities); + combat = root.combat; + } } } } @@ -240,7 +247,7 @@ public class ComputerPlayer5 extends ComputerPlayer4 implements Player { logger.fine("step finished"); int testScore = GameStateEvaluator2.evaluate(playerId, game); if (game.getActivePlayerId().equals(playerId)) { - if (testScore < currentScore) { + if (testScore <= currentScore) { // if score at end of step is worse than original score don't check further logger.fine("simulating -- abandoning check, no immediate benefit"); val = testScore; 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 4f1a120d7f..358572660f 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 @@ -64,6 +64,7 @@ import mage.abilities.keyword.FirstStrikeAbility; import mage.abilities.keyword.TrampleAbility; import mage.abilities.mana.ManaAbility; import mage.abilities.mana.ManaOptions; +import mage.filter.common.*; import mage.game.draft.Draft; import mage.player.ai.simulators.CombatGroupSimulator; import mage.player.ai.simulators.CombatSimulator; @@ -73,10 +74,6 @@ import mage.cards.Cards; import mage.cards.decks.Deck; import mage.choices.Choice; import mage.filter.FilterPermanent; -import mage.filter.common.FilterCreatureForCombat; -import mage.filter.common.FilterCreaturePermanent; -import mage.filter.common.FilterLandCard; -import mage.filter.common.FilterNonlandCard; import mage.game.Game; import mage.game.Table; import mage.game.combat.CombatGroup; @@ -90,6 +87,7 @@ import mage.target.TargetAmount; import mage.target.TargetCard; import mage.target.TargetPermanent; import mage.target.TargetPlayer; +import mage.target.common.TargetCreatureOrPlayer; import mage.target.common.TargetDiscard; import mage.target.common.TargetControlledPermanent; import mage.target.common.TargetCreatureOrPlayerAmount; @@ -271,6 +269,34 @@ public class ComputerPlayer> extends PlayerImpl i } } } + if (target instanceof TargetCreatureOrPlayer) { + List targets; + TargetCreatureOrPlayer t = ((TargetCreatureOrPlayer)target); + if (outcome.isGood()) { + targets = threats(playerId, ((FilterCreatureOrPlayer)t.getFilter()).getCreatureFilter(), game); + } + else { + targets = threats(opponentId, ((FilterCreatureOrPlayer)t.getFilter()).getCreatureFilter(), game); + } + for (Permanent permanent: targets) { + if (((TargetPermanent)target).canTarget(playerId, permanent.getId(), source, game)) { + target.addTarget(permanent.getId(), source, game); + return true; + } + } + if (outcome.isGood()) { + if (target.canTarget(playerId, source, game)) { + target.addTarget(playerId, source, game); + return true; + } + } + else { + if (target.canTarget(playerId, source, game)) { + target.addTarget(opponentId, source, game); + return true; + } + } + } return false; } diff --git a/Mage.Tests/config/config.xml b/Mage.Tests/config/config.xml index b3ae1e8072..763e09187a 100644 --- a/Mage.Tests/config/config.xml +++ b/Mage.Tests/config/config.xml @@ -4,7 +4,7 @@ - + diff --git a/Mage.Tests/plugins/mage-player-ai-ma.jar b/Mage.Tests/plugins/mage-player-ai-ma.jar index a7d5b0a71d..8792f2746e 100644 Binary files a/Mage.Tests/plugins/mage-player-ai-ma.jar and b/Mage.Tests/plugins/mage-player-ai-ma.jar differ