use of mage.cards.Card in project mage by magefree.
the class ComputerPlayer method choose.
@Override
public boolean choose(Outcome outcome, Cards cards, TargetCard target, Game game) {
log.debug("choose 2");
if (cards == null || cards.isEmpty()) {
return true;
}
// sometimes a target selection can be made from a player that does not control the ability
UUID abilityControllerId = playerId;
if (target.getTargetController() != null && target.getAbilityController() != null) {
abilityControllerId = target.getAbilityController();
}
List<Card> cardChoices = new ArrayList<>(cards.getCards(target.getFilter(), game));
while (!target.doneChosing()) {
Card card = pickTarget(abilityControllerId, cardChoices, outcome, target, null, game);
if (card != null) {
target.add(card.getId(), game);
cardChoices.remove(card);
} else {
// We don't have any valid target to choose so stop choosing
return target.getTargets().size() >= target.getNumberOfTargets();
}
if (outcome == Outcome.Neutral && target.getTargets().size() > target.getNumberOfTargets() + (target.getMaxNumberOfTargets() - target.getNumberOfTargets()) / 2) {
return true;
}
}
return true;
}
use of mage.cards.Card in project mage by magefree.
the class MCTSNode method randomizePlayers.
/*
* Shuffles each players library so that there is no knowledge of its order
* Swaps all other players hands with random cards from the library so that
* there is no knowledge of what cards are in opponents hands
*/
protected void randomizePlayers(Game game, UUID playerId) {
for (Player player : game.getState().getPlayers().values()) {
if (!player.getId().equals(playerId)) {
int handSize = player.getHand().size();
player.getLibrary().addAll(player.getHand().getCards(game), game);
player.getHand().clear();
player.getLibrary().shuffle();
for (int i = 0; i < handSize; i++) {
Card card = player.getLibrary().removeFromTop(game);
card.setZone(Zone.HAND, game);
player.getHand().add(card);
}
} else {
player.getLibrary().shuffle();
}
}
}
use of mage.cards.Card in project mage by magefree.
the class ComputerPlayer method buildDeckWithNormalCards.
public static Deck buildDeckWithNormalCards(int deckMinSize, List<Card> cardPool, final List<ColoredManaSymbol> colors) {
// top 23 cards plus basic lands until 40 deck size
Deck deck = new Deck();
final int DECK_SIZE = deckMinSize != 0 ? deckMinSize : 40;
// 23 from 40
final int DECK_CARDS_COUNT = Math.floorDiv(deckMinSize * 23, 40);
final int DECK_LANDS_COUNT = DECK_SIZE - DECK_CARDS_COUNT;
// sort card pool by top score
List<Card> sortedCards = new ArrayList<>(cardPool);
Collections.sort(sortedCards, new Comparator<Card>() {
@Override
public int compare(Card o1, Card o2) {
Integer score1 = RateCard.rateCard(o1, colors);
Integer score2 = RateCard.rateCard(o2, colors);
return score2.compareTo(score1);
}
});
// get top cards
int cardNum = 0;
while (deck.getCards().size() < DECK_CARDS_COUNT && sortedCards.size() > cardNum) {
Card card = sortedCards.get(cardNum);
if (!card.isBasic()) {
deck.getCards().add(card);
deck.getSideboard().remove(card);
}
cardNum++;
}
// add basic lands by color percent
// TODO: compensate for non basic lands
Mana mana = new Mana();
for (Card card : deck.getCards()) {
mana.add(card.getManaCost().getMana());
}
double total = mana.getBlack() + mana.getBlue() + mana.getGreen() + mana.getRed() + mana.getWhite();
// most frequent land is forest by default
int mostLand = 0;
String mostLandName = "Forest";
if (mana.getGreen() > 0) {
int number = (int) Math.round(mana.getGreen() / total * DECK_LANDS_COUNT);
addBasicLands(deck, "Forest", number);
mostLand = number;
}
if (mana.getBlack() > 0) {
int number = (int) Math.round(mana.getBlack() / total * DECK_LANDS_COUNT);
addBasicLands(deck, "Swamp", number);
if (number > mostLand) {
mostLand = number;
mostLandName = "Swamp";
}
}
if (mana.getBlue() > 0) {
int number = (int) Math.round(mana.getBlue() / total * DECK_LANDS_COUNT);
addBasicLands(deck, "Island", number);
if (number > mostLand) {
mostLand = number;
mostLandName = "Island";
}
}
if (mana.getWhite() > 0) {
int number = (int) Math.round(mana.getWhite() / total * DECK_LANDS_COUNT);
addBasicLands(deck, "Plains", number);
if (number > mostLand) {
mostLand = number;
mostLandName = "Plains";
}
}
if (mana.getRed() > 0) {
int number = (int) Math.round(mana.getRed() / total * DECK_LANDS_COUNT);
addBasicLands(deck, "Mountain", number);
if (number > mostLand) {
mostLandName = "Plains";
}
}
// adds remaining lands (most popular name)
addBasicLands(deck, mostLandName, DECK_SIZE - deck.getCards().size());
return deck;
}
use of mage.cards.Card in project mage by magefree.
the class ComputerPlayer method pickBestCard.
public Card pickBestCard(List<Card> cards, List<ColoredManaSymbol> chosenColors) {
if (cards.isEmpty()) {
return null;
}
Card bestCard = null;
int maxScore = 0;
for (Card card : cards) {
int score = RateCard.rateCard(card, chosenColors);
if (bestCard == null || score > maxScore) {
maxScore = score;
bestCard = card;
}
}
return bestCard;
}
use of mage.cards.Card in project mage by magefree.
the class ComputerPlayer method buildDeckWithOnlyBasicLands.
public static Deck buildDeckWithOnlyBasicLands(int deckMinSize, List<Card> cardPool) {
// random cards from card pool
Deck deck = new Deck();
final int DECK_SIZE = deckMinSize != 0 ? deckMinSize : 40;
List<Card> sortedCards = new ArrayList<>(cardPool);
if (!sortedCards.isEmpty()) {
while (deck.getCards().size() < DECK_SIZE) {
deck.getCards().add(sortedCards.get(RandomUtil.nextInt(sortedCards.size())));
}
return deck;
} else {
addBasicLands(deck, "Forest", DECK_SIZE);
return deck;
}
}
Aggregations