From 497b97791175be4a287e8d8e753bcdff874baf1c Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Wed, 13 May 2015 15:04:42 +0200 Subject: [PATCH] * Fixed a bug that the AI did most of the time choose the wrong mana color if producing mana from any or multiple mana effects. --- .../java/mage/player/ai/ComputerPlayer.java | 35 ++++++++++++++++--- 1 file changed, 30 insertions(+), 5 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 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); } }