* Fixed a bug of AI target card in hand selection leading to UI hang if AI had no valid targets in hand (e.g. Show and Tell or Hypergenesis).

This commit is contained in:
LevelX2 2015-08-16 17:59:14 +02:00
parent c6e08a8872
commit 5ee01868a9

View file

@ -74,6 +74,7 @@ import mage.abilities.mana.ManaAbility;
import mage.abilities.mana.ManaOptions;
import mage.cards.Card;
import mage.cards.Cards;
import mage.cards.CardsImpl;
import mage.cards.decks.Deck;
import mage.cards.repository.CardCriteria;
import mage.cards.repository.CardInfo;
@ -161,7 +162,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
private transient final static Logger log = Logger.getLogger(ComputerPlayer.class);
protected int PASSIVITY_PENALTY = 5; // Penalty value for doing nothing if some actions are availble
protected boolean ALLOW_INTERRUPT = true; // change this for test / debugging purposes to false to switch off interrupts while debugging
protected boolean ALLOW_INTERRUPT = true; // change this for test / debugging purposes to false to switch off interrupts while debugging
private transient Map<Mana, Card> unplayable = new TreeMap<>();
private transient List<Card> playableNonInstant = new ArrayList<>();
@ -522,8 +523,11 @@ public class ComputerPlayer extends PlayerImpl implements Player {
}
if (target instanceof TargetDiscard || target instanceof TargetCardInHand) {
if (outcome.isGood()) {
ArrayList<Card> cardsInHand = new ArrayList<>(hand.getCards(game));
while (!target.isChosen() && !cardsInHand.isEmpty() && target.getMaxNumberOfTargets() > target.getTargets().size()) {
Cards cards = new CardsImpl(target.possibleTargets(source.getSourceId(), getId(), game));
ArrayList<Card> cardsInHand = new ArrayList<>(cards.getCards(game));
while (!target.isChosen()
&& target.possibleTargets(source.getSourceId(), getId(), game).size() > 0
&& target.getMaxNumberOfTargets() > target.getTargets().size()) {
Card card = pickBestCard(cardsInHand, null, target, source, game);
if (card != null) {
if (target.canTarget(getId(), card.getId(), source, game)) {
@ -684,17 +688,6 @@ public class ComputerPlayer extends PlayerImpl implements Player {
}
return target.isChosen();
}
if (target instanceof TargetCardInHand) {
List<Card> cards = new ArrayList<>();
cards.addAll(this.hand.getCards(game));
while (!target.isChosen() && !cards.isEmpty()) {
Card pick = pickTarget(cards, outcome, target, source, game);
if (pick != null) {
target.addTarget(pick.getId(), source, game);
}
}
return target.isChosen();
}
if (target instanceof TargetSpell) {
if (game.getStack().size() > 0) {
Iterator<StackObject> it = game.getStack().iterator();