From 176210dc8d175dda2428e815a78dfc68810f0840 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Wed, 16 Jan 2013 23:42:37 +0100 Subject: [PATCH] Added some simple logic for AI to choose a creature type. --- .../java/mage/player/ai/ComputerPlayer.java | 69 ++++++++++++++++++- .../sets/magic2012/AdaptiveAutomaton.java | 1 + .../src/mage/sets/newphyrexia/Xenograft.java | 1 + 3 files changed, 70 insertions(+), 1 deletion(-) 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 765ffc7f043..ea9e40d76a6 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 @@ -935,10 +935,77 @@ public class ComputerPlayer> extends PlayerImpl i public boolean choose(Outcome outcome, Choice choice, Game game) { log.debug("choose 3"); //TODO: improve this - choice.setChoice(choice.getChoices().iterator().next()); + if (choice.getMessage().equals("Choose creature type")) { + chooseCreatureType(outcome, choice, game); + } + if (!choice.isChosen()) { + Iterator iterator = choice.getChoices().iterator(); + while (iterator.hasNext()) { + String next = (String) iterator.next(); + if (!next.isEmpty()) { + choice.setChoice(next); + break; + } + } + } return true; } + protected boolean chooseCreatureType(Outcome outcome, Choice choice, Game game) { + if (outcome.equals(Outcome.Detriment)) { + // choose a creature type of opponent on battlefield or graveyard + for (Permanent permanent :game.getBattlefield().getActivePermanents(this.getId(), game)) { + if(game.getOpponents(this.getId()).contains(permanent.getControllerId()) + && permanent.getCardType().contains(CardType.CREATURE) + && permanent.getSubtype().size() > 0) { + if (choice.getChoices().contains(permanent.getSubtype().get(0))) { + choice.setChoice(permanent.getSubtype().get(0)); + break; + } + } + } + // or in opponent graveyard + if (!choice.isChosen()) { + for (UUID opponentId :game.getOpponents(this.getId())) { + Player opponent = game.getPlayer(opponentId); + for (Card card : opponent.getGraveyard().getCards(game)) { + if (card != null && card.getCardType().contains(CardType.CREATURE) && card.getSubtype().size() > 0) { + if (choice.getChoices().contains(card.getSubtype().get(0))) { + choice.setChoice(card.getSubtype().get(0)); + break; + } + } + } + if (choice.isChosen()) { + break; + } + } + } + } else { + // choose a creature type of hand or library + for (UUID cardId :this.getHand()) { + Card card = game.getCard(cardId); + if (card != null && card.getCardType().contains(CardType.CREATURE) && card.getSubtype().size() > 0) { + if (choice.getChoices().contains(card.getSubtype().get(0))) { + choice.setChoice(card.getSubtype().get(0)); + break; + } + } + } + if (!choice.isChosen()) { + for (UUID cardId : this.getLibrary().getCardList()) { + Card card = game.getCard(cardId); + if (card != null && card.getCardType().contains(CardType.CREATURE) && card.getSubtype().size() > 0) { + if (choice.getChoices().contains(card.getSubtype().get(0))) { + choice.setChoice(card.getSubtype().get(0)); + break; + } + } + } + } + } + return choice.isChosen(); + } @Override public boolean chooseTarget(Outcome outcome, Cards cards, TargetCard target, Ability source, Game game) { log.debug("chooseTarget"); diff --git a/Mage.Sets/src/mage/sets/magic2012/AdaptiveAutomaton.java b/Mage.Sets/src/mage/sets/magic2012/AdaptiveAutomaton.java index d63678941c7..c1dbff32c54 100644 --- a/Mage.Sets/src/mage/sets/magic2012/AdaptiveAutomaton.java +++ b/Mage.Sets/src/mage/sets/magic2012/AdaptiveAutomaton.java @@ -96,6 +96,7 @@ class AdaptiveAutomatonEffect extends OneShotEffect { Permanent permanent = game.getPermanent(source.getSourceId()); if (player != null && permanent != null) { Choice typeChoice = new ChoiceImpl(true); + typeChoice.setMessage("Choose creature type"); typeChoice.setChoices(CardRepository.instance.getCreatureTypes()); while (!player.choose(Constants.Outcome.BoostCreature, typeChoice, game)) { game.debugMessage("player canceled choosing type. retrying."); diff --git a/Mage.Sets/src/mage/sets/newphyrexia/Xenograft.java b/Mage.Sets/src/mage/sets/newphyrexia/Xenograft.java index bf24a1f64fe..08327bd9c1f 100644 --- a/Mage.Sets/src/mage/sets/newphyrexia/Xenograft.java +++ b/Mage.Sets/src/mage/sets/newphyrexia/Xenograft.java @@ -95,6 +95,7 @@ class XenograftEffect extends OneShotEffect { Permanent permanent = game.getPermanent(source.getSourceId()); if (player != null && permanent != null) { Choice typeChoice = new ChoiceImpl(true); + typeChoice.setMessage("Choose creature type"); typeChoice.setChoices(CardRepository.instance.getCreatureTypes()); while (!player.choose(Outcome.BoostCreature, typeChoice, game)) { game.debugMessage("player canceled choosing type. retrying.");