From f2114f470184ceafa080877f615ba074f91df900 Mon Sep 17 00:00:00 2001 From: Quercitron Date: Fri, 13 Jun 2014 20:21:07 +0400 Subject: [PATCH] Fix build for Player AI projects --- .../java/mage/player/ai/ComputerPlayer.java | 23 +++++++-------- .../mage/player/ai/SimulatedPlayerMCTS.java | 26 ++++++++--------- .../org/mage/test/player/RandomPlayer.java | 29 +++++++++---------- 3 files changed, 36 insertions(+), 42 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 8e61a8e42d..58d7fa0e51 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 @@ -148,7 +148,7 @@ public class ComputerPlayer extends PlayerImpl implements Player { target.add(playerId, game); return true; } - if (target.isRequired()) { + if (target.isRequired(sourceId, game)) { if (target.canTarget(opponentId, game)) { target.add(opponentId, game); return true; @@ -159,7 +159,7 @@ public class ComputerPlayer extends PlayerImpl implements Player { target.add(opponentId, game); return true; } - if (target.isRequired()) { + if (target.isRequired(sourceId, game)) { if (target.canTarget(playerId, game)) { target.add(playerId, game); return true; @@ -266,7 +266,7 @@ public class ComputerPlayer extends PlayerImpl implements Player { return true; } } - if (!target.isRequired()) { + if (!target.isRequired(sourceId, game)) { return false; } } @@ -299,7 +299,7 @@ public class ComputerPlayer extends PlayerImpl implements Player { return true; } } - if (!target.isRequired()) { + if (!target.isRequired(sourceId, game)) { return false; } throw new IllegalStateException("TargetPermanentOrPlayer wasn't handled. class:" + target.getClass().toString()); @@ -350,7 +350,7 @@ public class ComputerPlayer extends PlayerImpl implements Player { target.addTarget(playerId, source, game); return true; } - if (target.isRequired()) { + if (target.isRequired(source)) { if (target.canTarget(opponentId, source, game)) { target.addTarget(opponentId, source, game); return true; @@ -362,7 +362,7 @@ public class ComputerPlayer extends PlayerImpl implements Player { target.addTarget(opponentId, source, game); return true; } - if (target.isRequired()) { + if (target.isRequired(source)) { if (target.canTarget(playerId, source, game)) { target.addTarget(playerId, source, game); return true; @@ -438,7 +438,7 @@ public class ComputerPlayer extends PlayerImpl implements Player { else { targets = threats(opponentId, source == null?null:source.getSourceId(), ((TargetPermanent)target).getFilter(), game, target.getTargets()); } - if (targets.isEmpty() && target.isRequired()) { + if (targets.isEmpty() && target.isRequired(source)) { targets = threats(null, source == null?null:source.getSourceId(), ((TargetPermanent)target).getFilter(), game, target.getTargets()); Collections.reverse(targets); outcomeTargets = false; @@ -479,7 +479,7 @@ public class ComputerPlayer extends PlayerImpl implements Player { } } - if (targets.isEmpty() && target.isRequired()) { + if (targets.isEmpty() && target.isRequired(source)) { targets = game.getBattlefield().getActivePermanents(((FilterCreatureOrPlayer)t.getFilter()).getCreatureFilter(), playerId, game); } for (Permanent permanent : targets) { @@ -573,7 +573,7 @@ public class ComputerPlayer extends PlayerImpl implements Player { else { targets = threats(opponentId, source == null?null:source.getSourceId(), ((TargetPermanent)target).getFilter(), game, target.getTargets()); } - if (targets.isEmpty() && target.isRequired()) { + if (targets.isEmpty() && target.isRequired(source)) { targets = threats(null, source == null?null:source.getSourceId(), ((TargetPermanent)target).getFilter(), game, target.getTargets()); Collections.reverse(targets); outcomeTargets = false; @@ -1187,7 +1187,7 @@ public class ComputerPlayer extends PlayerImpl implements Player { public boolean chooseTarget(Outcome outcome, Cards cards, TargetCard target, Ability source, Game game) { log.debug("chooseTarget"); if (cards == null || cards.isEmpty()) { - if (!target.isRequired()) { + if (!target.isRequired(source)) { return false; } return true; @@ -1211,9 +1211,6 @@ public class ComputerPlayer extends PlayerImpl implements Player { public boolean choose(Outcome outcome, Cards cards, TargetCard target, Game game) { log.debug("choose 2"); if (cards == null || cards.isEmpty()) { - if (!target.isRequired()) { - return false; - } return true; } diff --git a/Mage.Server.Plugins/Mage.Player.AIMCTS/src/mage/player/ai/SimulatedPlayerMCTS.java b/Mage.Server.Plugins/Mage.Player.AIMCTS/src/mage/player/ai/SimulatedPlayerMCTS.java index bcc24d5d7e..97fe05bced 100644 --- a/Mage.Server.Plugins/Mage.Player.AIMCTS/src/mage/player/ai/SimulatedPlayerMCTS.java +++ b/Mage.Server.Plugins/Mage.Player.AIMCTS/src/mage/player/ai/SimulatedPlayerMCTS.java @@ -220,12 +220,8 @@ public class SimulatedPlayerMCTS extends MCTSPlayer { protected boolean chooseRandom(Target target, Game game) { Set possibleTargets = target.possibleTargets(playerId, game); - if (possibleTargets.isEmpty()) - return !target.isRequired(); - if (!target.isRequired()) { - if (rnd.nextInt(possibleTargets.size() + 1) == 0) { - return false; - } + if (possibleTargets.isEmpty()) { + return false; } if (possibleTargets.size() == 1) { target.add(possibleTargets.iterator().next(), game); @@ -245,7 +241,7 @@ public class SimulatedPlayerMCTS extends MCTSPlayer { Set possibleTargets = target.possibleTargets(source==null?null:source.getSourceId(), playerId, game); if (possibleTargets.isEmpty()) return false; - if (!target.isRequired()) { + if (!target.isRequired(source)) { if (rnd.nextInt(possibleTargets.size() + 1) == 0) { return false; } @@ -281,11 +277,13 @@ public class SimulatedPlayerMCTS extends MCTSPlayer { @Override public boolean choose(Outcome outcome, Cards cards, TargetCard target, Game game) { if (this.isHuman()) { - if (cards.isEmpty()) - return !target.isRequired(); + if (cards.isEmpty()) { + return false; + } Set possibleTargets = target.possibleTargets(playerId, cards, game); - if (possibleTargets.isEmpty()) - return !target.isRequired(); + if (possibleTargets.isEmpty()) { + return false; + } Iterator it = possibleTargets.iterator(); int targetNum = rnd.nextInt(possibleTargets.size()); UUID targetId = it.next(); @@ -306,7 +304,7 @@ public class SimulatedPlayerMCTS extends MCTSPlayer { @Override public boolean chooseTarget(Outcome outcome, Cards cards, TargetCard target, Ability source, Game game) { if (cards.isEmpty()) - return !target.isRequired(); + return !target.isRequired(source); Card card = cards.getRandom(game); target.addTarget(card.getId(), source, game); return true; @@ -316,8 +314,8 @@ public class SimulatedPlayerMCTS extends MCTSPlayer { public boolean chooseTargetAmount(Outcome outcome, TargetAmount target, Ability source, Game game) { Set possibleTargets = target.possibleTargets(source==null?null:source.getSourceId(), playerId, game); if (possibleTargets.isEmpty()) - return !target.isRequired(); - if (!target.isRequired()) { + return !target.isRequired(source); + if (!target.isRequired(source)) { if (rnd.nextInt(possibleTargets.size() + 1) == 0) { return false; } diff --git a/Mage.Tests/src/test/java/org/mage/test/player/RandomPlayer.java b/Mage.Tests/src/test/java/org/mage/test/player/RandomPlayer.java index 496cdb05b7..a9b2187dc7 100644 --- a/Mage.Tests/src/test/java/org/mage/test/player/RandomPlayer.java +++ b/Mage.Tests/src/test/java/org/mage/test/player/RandomPlayer.java @@ -220,12 +220,8 @@ public class RandomPlayer extends ComputerPlayer { protected boolean chooseRandom(Target target, Game game) { Set possibleTargets = target.possibleTargets(playerId, game); - if (possibleTargets.isEmpty()) - return !target.isRequired(); - if (!target.isRequired()) { - if (rnd.nextInt(possibleTargets.size() + 1) == 0) { - return false; - } + if (possibleTargets.isEmpty()) { + return false; } if (possibleTargets.size() == 1) { target.add(possibleTargets.iterator().next(), game); @@ -245,7 +241,7 @@ public class RandomPlayer extends ComputerPlayer { Set possibleTargets = target.possibleTargets(source==null?null:source.getSourceId(), playerId, game); if (possibleTargets.isEmpty()) return false; - if (!target.isRequired()) { + if (!target.isRequired(source)) { if (rnd.nextInt(possibleTargets.size() + 1) == 0) { return false; } @@ -276,11 +272,13 @@ public class RandomPlayer extends ComputerPlayer { @Override public boolean choose(Outcome outcome, Cards cards, TargetCard target, Game game) { - if (cards.isEmpty()) - return !target.isRequired(); + if (cards.isEmpty()) { + return false; + } Set possibleTargets = target.possibleTargets(playerId, cards, game); - if (possibleTargets.isEmpty()) - return !target.isRequired(); + if (possibleTargets.isEmpty()) { + return !false; + } Iterator it = possibleTargets.iterator(); int targetNum = rnd.nextInt(possibleTargets.size()); UUID targetId = it.next(); @@ -299,7 +297,7 @@ public class RandomPlayer extends ComputerPlayer { @Override public boolean chooseTarget(Outcome outcome, Cards cards, TargetCard target, Ability source, Game game) { if (cards.isEmpty()) - return !target.isRequired(); + return !target.isRequired(source); Card card = cards.getRandom(game); target.addTarget(card.getId(), source, game); return true; @@ -308,9 +306,10 @@ public class RandomPlayer extends ComputerPlayer { @Override public boolean chooseTargetAmount(Outcome outcome, TargetAmount target, Ability source, Game game) { Set possibleTargets = target.possibleTargets(source==null?null:source.getSourceId(), playerId, game); - if (possibleTargets.isEmpty()) - return !target.isRequired(); - if (!target.isRequired()) { + if (possibleTargets.isEmpty()) { + return !target.isRequired(source); + } + if (!target.isRequired(source)) { if (rnd.nextInt(possibleTargets.size() + 1) == 0) { return false; }