mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 19:28:01 +00:00
- Improved AI's first land drop decision.
This commit is contained in:
@@ -163,6 +163,14 @@ public final class CardPredicates {
|
|||||||
};
|
};
|
||||||
} // getColor()
|
} // getColor()
|
||||||
|
|
||||||
|
public static final Predicate<Card> hasCMC(final int cmc) {
|
||||||
|
return new Predicate<Card>() {
|
||||||
|
@Override
|
||||||
|
public boolean apply(final Card c) {
|
||||||
|
return c.getCMC() == cmc;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public static class Presets {
|
public static class Presets {
|
||||||
|
|
||||||
|
|||||||
@@ -35,10 +35,12 @@ import forge.CardPredicates;
|
|||||||
import forge.CardPredicates.Presets;
|
import forge.CardPredicates.Presets;
|
||||||
import forge.Constant;
|
import forge.Constant;
|
||||||
import forge.GameEntity;
|
import forge.GameEntity;
|
||||||
|
import forge.card.MagicColor;
|
||||||
import forge.card.ability.ApiType;
|
import forge.card.ability.ApiType;
|
||||||
import forge.card.cardfactory.CardFactoryUtil;
|
import forge.card.cardfactory.CardFactoryUtil;
|
||||||
import forge.card.cost.CostDiscard;
|
import forge.card.cost.CostDiscard;
|
||||||
import forge.card.cost.CostPart;
|
import forge.card.cost.CostPart;
|
||||||
|
import forge.card.spellability.AbilityManaPart;
|
||||||
import forge.card.spellability.Spell;
|
import forge.card.spellability.Spell;
|
||||||
import forge.card.spellability.SpellAbility;
|
import forge.card.spellability.SpellAbility;
|
||||||
import forge.card.spellability.SpellPermanent;
|
import forge.card.spellability.SpellPermanent;
|
||||||
@@ -324,15 +326,39 @@ public class AiController {
|
|||||||
if (landList.isEmpty())
|
if (landList.isEmpty())
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
// play as many lands as you can
|
//Skip reflected lands.
|
||||||
int ix = 0;
|
List<Card> unreflectedLands = new ArrayList<Card>(landList);
|
||||||
while (landList.get(ix).isReflectedLand() && ((ix + 1) < landList.size())) {
|
for (Card l : landList) {
|
||||||
// Skip through reflected lands. Choose last if they are all
|
if (l.isReflectedLand()) {
|
||||||
// reflected.
|
unreflectedLands.remove(l);
|
||||||
ix++;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!unreflectedLands.isEmpty()) {
|
||||||
|
landList = unreflectedLands;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Choose first land to be able to play a one drop
|
||||||
|
if (player.getLandsInPlay().isEmpty()) {
|
||||||
|
List<Card> oneDrops = CardLists.filter(player.getCardsIn(ZoneType.Hand), CardPredicates.hasCMC(1));
|
||||||
|
for (int i = 0; i < MagicColor.WUBRG.length; i++) {
|
||||||
|
byte color = MagicColor.WUBRG[i];
|
||||||
|
if (!CardLists.filter(oneDrops, CardPredicates.isColor(color)).isEmpty()) {
|
||||||
|
for (Card land : landList) {
|
||||||
|
if (land.isType(Constant.Color.BASIC_LANDS.get(i)))
|
||||||
|
return land;
|
||||||
|
|
||||||
|
for (final SpellAbility m : ComputerUtilMana.getAIPlayableMana(land)) {
|
||||||
|
AbilityManaPart mp = m.getManaPart();
|
||||||
|
if (mp.canProduce(MagicColor.toShortString(color))) {
|
||||||
|
return land;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Card land = landList.get(ix);
|
|
||||||
//play basic lands that are needed the most
|
//play basic lands that are needed the most
|
||||||
if (Iterables.any(landList, CardPredicates.Presets.BASIC_LANDS)) {
|
if (Iterables.any(landList, CardPredicates.Presets.BASIC_LANDS)) {
|
||||||
final List<Card> combined = player.getCardsIn(ZoneType.Battlefield);
|
final List<Card> combined = player.getCardsIn(ZoneType.Battlefield);
|
||||||
@@ -363,10 +389,8 @@ public class AiController {
|
|||||||
if (minType != null) {
|
if (minType != null) {
|
||||||
landList = CardLists.getType(landList, minType);
|
landList = CardLists.getType(landList, minType);
|
||||||
}
|
}
|
||||||
|
|
||||||
land = landList.get(0);
|
|
||||||
}
|
}
|
||||||
return land;
|
return landList.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if return true, go to next phase
|
// if return true, go to next phase
|
||||||
|
|||||||
@@ -697,7 +697,7 @@ public class ComputerUtilMana {
|
|||||||
*
|
*
|
||||||
* @return a {@link java.util.ArrayList} object.
|
* @return a {@link java.util.ArrayList} object.
|
||||||
*/
|
*/
|
||||||
private static final ArrayList<SpellAbility> getAIPlayableMana(Card c) {
|
public static final ArrayList<SpellAbility> getAIPlayableMana(Card c) {
|
||||||
final ArrayList<SpellAbility> res = new ArrayList<SpellAbility>();
|
final ArrayList<SpellAbility> res = new ArrayList<SpellAbility>();
|
||||||
for (final SpellAbility a : c.getManaAbility()) {
|
for (final SpellAbility a : c.getManaAbility()) {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user