mirror of
https://github.com/correl/mage.git
synced 2024-12-25 19:25:41 +00:00
added missing targeting cases
This commit is contained in:
parent
315fb7f24e
commit
86d2086b70
1 changed files with 98 additions and 33 deletions
|
@ -226,7 +226,17 @@ public class ComputerPlayer<T extends ComputerPlayer<T>> extends PlayerImpl<T> i
|
||||||
if (!target.isRequired())
|
if (!target.isRequired())
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (target instanceof TargetDiscard) {
|
if (target instanceof TargetDiscard || target instanceof TargetCardInHand) {
|
||||||
|
if (outcome.isGood()) {
|
||||||
|
Card card = pickBestCard(new ArrayList<Card>(hand.getCards(game)), null);
|
||||||
|
if (card != null) {
|
||||||
|
if (target.canTarget(card.getId(), source, game)) {
|
||||||
|
target.addTarget(card.getId(), source, game);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
findPlayables(game);
|
findPlayables(game);
|
||||||
if (unplayable.size() > 0) {
|
if (unplayable.size() > 0) {
|
||||||
for (int i = unplayable.size() - 1; i >= 0; i--) {
|
for (int i = unplayable.size() - 1; i >= 0; i--) {
|
||||||
|
@ -242,6 +252,7 @@ public class ComputerPlayer<T extends ComputerPlayer<T>> extends PlayerImpl<T> i
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (!target.isRequired())
|
if (!target.isRequired())
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -308,28 +319,57 @@ public class ComputerPlayer<T extends ComputerPlayer<T>> extends PlayerImpl<T> i
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (target instanceof TargetCardInGraveyard) {
|
if (target instanceof TargetCardInGraveyard) {
|
||||||
//TODO: implement
|
List<Card> cards = new ArrayList<Card>();
|
||||||
logger.error("Needs to be implemented");
|
for (Player player: game.getPlayers().values()) {
|
||||||
return false;
|
cards.addAll(player.getGraveyard().getCards(game));
|
||||||
}
|
}
|
||||||
if (target instanceof TargetCardInHand) {
|
Card card = pickTarget(cards, outcome, target, source, game);
|
||||||
//TODO: implement
|
if (card != null) {
|
||||||
logger.error("Needs to be implemented");
|
target.addTarget(card.getId(), source, game);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!target.isRequired())
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (target instanceof TargetCardInLibrary) {
|
if (target instanceof TargetCardInLibrary) {
|
||||||
//TODO: implement
|
List<Card> cards = new ArrayList<Card>(game.getPlayer(playerId).getLibrary().getCards(game));
|
||||||
logger.error("Needs to be implemented");
|
Card card = pickTarget(cards, outcome, target, source, game);
|
||||||
|
if (card != null) {
|
||||||
|
target.addTarget(card.getId(), source, game);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!target.isRequired())
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (target instanceof TargetCardInYourGraveyard) {
|
if (target instanceof TargetCardInYourGraveyard) {
|
||||||
//TODO: implement
|
List<Card> cards = new ArrayList<Card>(game.getPlayer(playerId).getGraveyard().getCards(game));
|
||||||
logger.error("Needs to be implemented");
|
Card card = pickTarget(cards, outcome, target, source, game);
|
||||||
|
if (card != null) {
|
||||||
|
target.addTarget(card.getId(), source, game);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!target.isRequired())
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
throw new IllegalStateException("Target wasn't handled. class:" + target.getClass().toString());
|
throw new IllegalStateException("Target wasn't handled. class:" + target.getClass().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected Card pickTarget(List<Card> cards, Outcome outcome, Target target, Ability source, Game game) {
|
||||||
|
Card card = null;
|
||||||
|
while (!cards.isEmpty()) {
|
||||||
|
if (outcome.isGood()) {
|
||||||
|
card = pickBestCard(cards, null);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
card = pickWorstCard(cards, null);
|
||||||
|
}
|
||||||
|
if (target.canTarget(card.getId(), source, game)) {
|
||||||
|
return card;
|
||||||
|
}
|
||||||
|
cards.remove(card);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public boolean chooseTargetAmount(Outcome outcome, TargetAmount target, Ability source, Game game) {
|
public boolean chooseTargetAmount(Outcome outcome, TargetAmount target, Ability source, Game game) {
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
|
@ -918,12 +958,10 @@ public class ComputerPlayer<T extends ComputerPlayer<T>> extends PlayerImpl<T> i
|
||||||
tournament.submitDeck(playerId, deck);
|
tournament.submitDeck(playerId, deck);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public Card pickBestCard(List<Card> cards, List<Constants.ColoredManaSymbol> chosenColors) {
|
||||||
public void pickCard(List<Card> cards, Deck deck, Draft draft) {
|
|
||||||
if (cards.size() == 0) {
|
if (cards.size() == 0) {
|
||||||
throw new IllegalArgumentException("No cards to pick from.");
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
Card bestCard = null;
|
Card bestCard = null;
|
||||||
int maxScore = 0;
|
int maxScore = 0;
|
||||||
for (Card card : cards) {
|
for (Card card : cards) {
|
||||||
|
@ -933,6 +971,33 @@ public class ComputerPlayer<T extends ComputerPlayer<T>> extends PlayerImpl<T> i
|
||||||
bestCard = card;
|
bestCard = card;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return bestCard;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Card pickWorstCard(List<Card> cards, List<Constants.ColoredManaSymbol> chosenColors) {
|
||||||
|
if (cards.size() == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Card worstCard = null;
|
||||||
|
int minScore = Integer.MAX_VALUE;
|
||||||
|
for (Card card : cards) {
|
||||||
|
int score = RateCard.rateCard(card, chosenColors);
|
||||||
|
if (worstCard == null || score < minScore) {
|
||||||
|
minScore = score;
|
||||||
|
worstCard = card;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return worstCard;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void pickCard(List<Card> cards, Deck deck, Draft draft) {
|
||||||
|
if (cards.size() == 0) {
|
||||||
|
throw new IllegalArgumentException("No cards to pick from.");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Card bestCard = pickBestCard(cards, chosenColors);
|
||||||
|
int maxScore = RateCard.rateCard(bestCard, chosenColors);
|
||||||
String colors = "not chosen yet";
|
String colors = "not chosen yet";
|
||||||
// remember card if colors are not chosen yet
|
// remember card if colors are not chosen yet
|
||||||
if (chosenColors == null) {
|
if (chosenColors == null) {
|
||||||
|
|
Loading…
Reference in a new issue