mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 19:58:00 +00:00
a few minor optimizations
This commit is contained in:
@@ -237,9 +237,7 @@ public class CardLists {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static List<Card> createCardList(Card c) {
|
public static List<Card> createCardList(Card c) {
|
||||||
List<Card> res = new ArrayList<Card>();
|
return Lists.newArrayList(c);
|
||||||
res.add(c);
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -212,30 +212,6 @@ public class ComputerUtilCard {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// for Sarkhan the Mad
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* getCheapestCreatureAI.
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @param list
|
|
||||||
* a {@link forge.CardList} object.
|
|
||||||
* @param spell
|
|
||||||
* a {@link forge.Card} object.
|
|
||||||
* @param targeted
|
|
||||||
* a boolean.
|
|
||||||
* @return a {@link forge.Card} object.
|
|
||||||
*/
|
|
||||||
public static Card getCheapestCreatureAI(List<Card> list, final SpellAbility spell, final boolean targeted) {
|
|
||||||
list = CardLists.filter(list, new Predicate<Card>() {
|
|
||||||
@Override
|
|
||||||
public boolean apply(final Card c) {
|
|
||||||
return c.isCreature();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return getCheapestPermanentAI(list, spell, targeted);
|
|
||||||
}
|
|
||||||
|
|
||||||
// returns null if list.size() == 0
|
// returns null if list.size() == 0
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@@ -268,8 +244,20 @@ public class ComputerUtilCard {
|
|||||||
* @return the card
|
* @return the card
|
||||||
*/
|
*/
|
||||||
public static Card getBestCreatureAI(final List<Card> list) {
|
public static Card getBestCreatureAI(final List<Card> list) {
|
||||||
List<Card> all = CardLists.filter(list, CardPredicates.Presets.CREATURES);
|
return Aggregates.itemWithMax(Iterables.filter(list, CardPredicates.Presets.CREATURES), ComputerUtilCard.fnEvaluateCreature);
|
||||||
return Aggregates.itemWithMax(all, ComputerUtilCard.fnEvaluateCreature);
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* getWorstCreatureAI.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param list
|
||||||
|
* a {@link forge.CardList} object.
|
||||||
|
* @return a {@link forge.Card} object.
|
||||||
|
*/
|
||||||
|
public static Card getWorstCreatureAI(final List<Card> list) {
|
||||||
|
return Aggregates.itemWithMin(Iterables.filter(list, CardPredicates.Presets.CREATURES), ComputerUtilCard.fnEvaluateCreature);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This selection rates tokens higher
|
// This selection rates tokens higher
|
||||||
@@ -312,22 +300,6 @@ public class ComputerUtilCard {
|
|||||||
return ComputerUtilCard.getWorstPermanentAI(list, false, false, false, false);
|
return ComputerUtilCard.getWorstPermanentAI(list, false, false, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns null if list.size() == 0
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* getWorstCreatureAI.
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @param list
|
|
||||||
* a {@link forge.CardList} object.
|
|
||||||
* @return a {@link forge.Card} object.
|
|
||||||
*/
|
|
||||||
public static Card getWorstCreatureAI(final List<Card> list) {
|
|
||||||
List<Card> all = CardLists.filter(list, CardPredicates.Presets.CREATURES);
|
|
||||||
// get smallest creature
|
|
||||||
return Aggregates.itemWithMin(all, ComputerUtilCard.fnEvaluateCreature);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* getWorstPermanentAI.
|
* getWorstPermanentAI.
|
||||||
@@ -350,20 +322,23 @@ public class ComputerUtilCard {
|
|||||||
if (list.size() == 0) {
|
if (list.size() == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (biasEnch && Iterables.any(list, CardPredicates.Presets.ENCHANTMENTS)) {
|
final boolean hasEnchantmants = Iterables.any(list, CardPredicates.Presets.ENCHANTMENTS);
|
||||||
|
if (biasEnch && hasEnchantmants) {
|
||||||
return getCheapestPermanentAI(CardLists.filter(list, CardPredicates.Presets.ENCHANTMENTS), null, false);
|
return getCheapestPermanentAI(CardLists.filter(list, CardPredicates.Presets.ENCHANTMENTS), null, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (biasArt && Iterables.any(list, CardPredicates.Presets.ARTIFACTS)) {
|
final boolean hasArtifacts = Iterables.any(list, CardPredicates.Presets.ARTIFACTS);
|
||||||
|
if (biasArt && hasArtifacts) {
|
||||||
return getCheapestPermanentAI(CardLists.filter(list, CardPredicates.Presets.ARTIFACTS), null, false);
|
return getCheapestPermanentAI(CardLists.filter(list, CardPredicates.Presets.ARTIFACTS), null, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (biasLand && Iterables.any(list, CardPredicates.Presets.LANDS)) {
|
if (biasLand && Iterables.any(list, CardPredicates.Presets.LANDS)) {
|
||||||
return ComputerUtilCard.getWorstLand(CardLists.filter(list, CardPredicates.Presets.LANDS));
|
return ComputerUtilCard.getWorstLand(CardLists.filter(list, CardPredicates.Presets.LANDS));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (biasCreature && Iterables.any(list, CardPredicates.Presets.CREATURES)) {
|
final boolean hasCreatures = Iterables.any(list, CardPredicates.Presets.CREATURES);
|
||||||
|
if (biasCreature && hasCreatures) {
|
||||||
return getWorstCreatureAI(CardLists.filter(list, CardPredicates.Presets.CREATURES));
|
return getWorstCreatureAI(CardLists.filter(list, CardPredicates.Presets.CREATURES));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -372,17 +347,13 @@ public class ComputerUtilCard {
|
|||||||
return ComputerUtilCard.getWorstLand(lands);
|
return ComputerUtilCard.getWorstLand(lands);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((CardLists.getType(list, "Artifact").size() > 0) || (CardLists.getType(list, "Enchantment").size() > 0)) {
|
if (hasEnchantmants || hasArtifacts) {
|
||||||
return getCheapestPermanentAI(CardLists.filter(list, new Predicate<Card>() {
|
final List<Card> ae = CardLists.filter(list, Predicates.<Card>or(CardPredicates.Presets.ARTIFACTS, CardPredicates.Presets.ENCHANTMENTS));
|
||||||
@Override
|
return getCheapestPermanentAI(ae, null, false);
|
||||||
public boolean apply(final Card c) {
|
|
||||||
return c.isArtifact() || c.isEnchantment();
|
|
||||||
}
|
|
||||||
}), null, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CardLists.getType(list, "Creature").size() > 0) {
|
if (hasCreatures) {
|
||||||
return getWorstCreatureAI(CardLists.getType(list, "Creature"));
|
return getWorstCreatureAI(CardLists.filter(list, CardPredicates.Presets.CREATURES));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Planeswalkers fall through to here, lands will fall through if there
|
// Planeswalkers fall through to here, lands will fall through if there
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ import java.util.Map.Entry;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
import forge.Card;
|
import forge.Card;
|
||||||
import forge.CardLists;
|
import forge.CardLists;
|
||||||
import forge.CardPredicates;
|
import forge.CardPredicates;
|
||||||
@@ -368,9 +370,8 @@ public class Combat {
|
|||||||
this.blocked.add(attacker);
|
this.blocked.add(attacker);
|
||||||
this.attackerMap.get(attacker).add(blocker);
|
this.attackerMap.get(attacker).add(blocker);
|
||||||
if (!this.blockerMap.containsKey(blocker)) {
|
if (!this.blockerMap.containsKey(blocker)) {
|
||||||
this.blockerMap.put(blocker, CardLists.createCardList(attacker));
|
this.blockerMap.put(blocker, Lists.newArrayList(attacker));
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
this.blockerMap.get(blocker).add(attacker);
|
this.blockerMap.get(blocker).add(attacker);
|
||||||
}
|
}
|
||||||
attacker.getGame().getEvents().post(new BlockerAssignedEvent());
|
attacker.getGame().getEvents().post(new BlockerAssignedEvent());
|
||||||
|
|||||||
Reference in New Issue
Block a user