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 e99d22fea6..e036a3f820 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 @@ -82,6 +82,7 @@ import mage.cards.repository.CardRepository; import mage.cards.repository.ExpansionInfo; import mage.cards.repository.ExpansionRepository; import mage.choices.Choice; +import mage.choices.ChoiceColor; import mage.constants.CardType; import mage.constants.ColoredManaSymbol; import mage.constants.Outcome; @@ -166,6 +167,7 @@ public class ComputerPlayer extends PlayerImpl implements Player { private transient List pickedCards; private transient List chosenColors; + private transient ManaCost currentUnpaidMana; public ComputerPlayer(String name, RangeOfInfluence range) { super(name, range); human = false; @@ -1091,7 +1093,9 @@ public class ComputerPlayer extends PlayerImpl implements Player { @Override public boolean playMana(ManaCost unpaid, String promptText, Game game) { payManaMode = true; + currentUnpaidMana = unpaid; boolean result = playManaHandling(unpaid, game); + currentUnpaidMana = null; payManaMode = false; return result; } @@ -1275,6 +1279,30 @@ public class ComputerPlayer extends PlayerImpl implements Player { if (choice.getMessage() != null && choice.getMessage().equals("Choose creature type")) { chooseCreatureType(outcome, choice, game); } + // choose the correct color to pay a spell + if(outcome.equals(Outcome.PutManaInPool) && choice instanceof ChoiceColor && currentUnpaidMana != null) { + if (currentUnpaidMana.containsColor(ColoredManaSymbol.W) && choice.getChoices().contains("White")) { + choice.setChoice("White"); + return true; + } + if (currentUnpaidMana.containsColor(ColoredManaSymbol.R) && choice.getChoices().contains("Red")) { + choice.setChoice("Red"); + return true; + } + if (currentUnpaidMana.containsColor(ColoredManaSymbol.G) && choice.getChoices().contains("Green")) { + choice.setChoice("Green"); + return true; + } + if (currentUnpaidMana.containsColor(ColoredManaSymbol.U) && choice.getChoices().contains("Blue")) { + choice.setChoice("Blue"); + return true; + } + if (currentUnpaidMana.containsColor(ColoredManaSymbol.B) && choice.getChoices().contains("Black")) { + choice.setChoice("Black"); + return true; + } + } + // choose by random if (!choice.isChosen()) { int choiceIdx = (int) (Math.random()*choice.getChoices().size()+1); for (String next : choice.getChoices()) { @@ -1349,10 +1377,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(source)) { - return false; - } - return true; + return target.isRequired(source); } ArrayList cardChoices = new ArrayList<>(cards.getCards(target.getFilter(), game)); @@ -1812,7 +1837,7 @@ public class ComputerPlayer extends PlayerImpl implements Player { log.debug("[DEBUG] AI picked: " + bestCard.getName() + ", score=" + maxScore + ", deck colors=" + colors); draft.addPick(playerId, bestCard.getId(), null); } catch (Exception e) { - e.printStackTrace(); + log.debug("Exception during AI pick card for draft playerId= " +getId()); draft.addPick(playerId, cards.get(0).getId(), null); } }