* 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.

This commit is contained in:
LevelX2 2015-05-13 15:04:42 +02:00
parent bc61ef6fb8
commit 497b977911

View file

@ -82,6 +82,7 @@ import mage.cards.repository.CardRepository;
import mage.cards.repository.ExpansionInfo; import mage.cards.repository.ExpansionInfo;
import mage.cards.repository.ExpansionRepository; import mage.cards.repository.ExpansionRepository;
import mage.choices.Choice; import mage.choices.Choice;
import mage.choices.ChoiceColor;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.ColoredManaSymbol; import mage.constants.ColoredManaSymbol;
import mage.constants.Outcome; import mage.constants.Outcome;
@ -166,6 +167,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
private transient List<PickedCard> pickedCards; private transient List<PickedCard> pickedCards;
private transient List<ColoredManaSymbol> chosenColors; private transient List<ColoredManaSymbol> chosenColors;
private transient ManaCost currentUnpaidMana;
public ComputerPlayer(String name, RangeOfInfluence range) { public ComputerPlayer(String name, RangeOfInfluence range) {
super(name, range); super(name, range);
human = false; human = false;
@ -1091,7 +1093,9 @@ public class ComputerPlayer extends PlayerImpl implements Player {
@Override @Override
public boolean playMana(ManaCost unpaid, String promptText, Game game) { public boolean playMana(ManaCost unpaid, String promptText, Game game) {
payManaMode = true; payManaMode = true;
currentUnpaidMana = unpaid;
boolean result = playManaHandling(unpaid, game); boolean result = playManaHandling(unpaid, game);
currentUnpaidMana = null;
payManaMode = false; payManaMode = false;
return result; return result;
} }
@ -1275,6 +1279,30 @@ public class ComputerPlayer extends PlayerImpl implements Player {
if (choice.getMessage() != null && choice.getMessage().equals("Choose creature type")) { if (choice.getMessage() != null && choice.getMessage().equals("Choose creature type")) {
chooseCreatureType(outcome, choice, game); 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()) { if (!choice.isChosen()) {
int choiceIdx = (int) (Math.random()*choice.getChoices().size()+1); int choiceIdx = (int) (Math.random()*choice.getChoices().size()+1);
for (String next : choice.getChoices()) { 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) { public boolean chooseTarget(Outcome outcome, Cards cards, TargetCard target, Ability source, Game game) {
log.debug("chooseTarget"); log.debug("chooseTarget");
if (cards == null || cards.isEmpty()) { if (cards == null || cards.isEmpty()) {
if (!target.isRequired(source)) { return target.isRequired(source);
return false;
}
return true;
} }
ArrayList<Card> cardChoices = new ArrayList<>(cards.getCards(target.getFilter(), game)); ArrayList<Card> 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); log.debug("[DEBUG] AI picked: " + bestCard.getName() + ", score=" + maxScore + ", deck colors=" + colors);
draft.addPick(playerId, bestCard.getId(), null); draft.addPick(playerId, bestCard.getId(), null);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); log.debug("Exception during AI pick card for draft playerId= " +getId());
draft.addPick(playerId, cards.get(0).getId(), null); draft.addPick(playerId, cards.get(0).getId(), null);
} }
} }