mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 11:18:01 +00:00
- Expanded getCardPreference AI function.
This commit is contained in:
@@ -257,6 +257,7 @@ public class ComputerUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Card getCardPreference(final Player ai, final Card activate, final String pref, final CardCollection typeList) {
|
public static Card getCardPreference(final Player ai, final Card activate, final String pref, final CardCollection typeList) {
|
||||||
|
final Game game = ai.getGame();
|
||||||
if (activate != null) {
|
if (activate != null) {
|
||||||
final String[] prefValid = activate.getSVar("AIPreference").split("\\$");
|
final String[] prefValid = activate.getSVar("AIPreference").split("\\$");
|
||||||
if (prefValid[0].equals(pref)) {
|
if (prefValid[0].equals(pref)) {
|
||||||
@@ -271,6 +272,13 @@ public class ComputerUtil {
|
|||||||
// search for permanents with SacMe. priority 1 is the lowest, priority 5 the highest
|
// search for permanents with SacMe. priority 1 is the lowest, priority 5 the highest
|
||||||
for (int ip = 0; ip < 6; ip++) {
|
for (int ip = 0; ip < 6; ip++) {
|
||||||
final int priority = 6 - ip;
|
final int priority = 6 - ip;
|
||||||
|
if (priority == 2 && ai.isCardInPlay("Crucible of Worlds")) {
|
||||||
|
CardCollection landsInPlay = CardLists.getType(typeList, "Land");
|
||||||
|
if (!landsInPlay.isEmpty()) {
|
||||||
|
// Don't need more land.
|
||||||
|
return ComputerUtilCard.getWorstLand(landsInPlay);
|
||||||
|
}
|
||||||
|
}
|
||||||
final CardCollection sacMeList = CardLists.filter(typeList, new Predicate<Card>() {
|
final CardCollection sacMeList = CardLists.filter(typeList, new Predicate<Card>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(final Card c) {
|
public boolean apply(final Card c) {
|
||||||
@@ -295,13 +303,23 @@ public class ComputerUtil {
|
|||||||
return ComputerUtilCard.getWorstLand(landsInPlay);
|
return ComputerUtilCard.getWorstLand(landsInPlay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// try everything when about to die
|
||||||
|
if (game.getPhaseHandler().getPhase().equals(PhaseType.COMBAT_DECLARE_BLOCKERS)
|
||||||
|
&& ComputerUtilCombat.lifeInSeriousDanger(ai, game.getCombat())) {
|
||||||
|
final CardCollection nonCreatures = CardLists.getNotType(typeList, "Creature");
|
||||||
|
if (!nonCreatures.isEmpty()) {
|
||||||
|
return ComputerUtilCard.getWorstAI(nonCreatures);
|
||||||
|
} else if (!typeList.isEmpty()) {
|
||||||
|
return ComputerUtilCard.getWorstAI(typeList);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (pref.contains("DiscardCost")) { // search for permanents with DiscardMe
|
else if (pref.contains("DiscardCost")) { // search for permanents with DiscardMe
|
||||||
for (int ip = 0; ip < 6; ip++) { // priority 0 is the lowest, priority 5 the highest
|
for (int ip = 0; ip < 6; ip++) { // priority 0 is the lowest, priority 5 the highest
|
||||||
final int priority = 6 - ip;
|
final int priority = 6 - ip;
|
||||||
for (Card c : typeList) {
|
for (Card c : typeList) {
|
||||||
if (priority == 3 && c.isLand()
|
if (priority == 3 && c.isLand() && ai.isCardInPlay("Crucible of Worlds")) {
|
||||||
&& !ai.getCardsIn(ZoneType.Battlefield, "Crucible of Worlds").isEmpty()) {
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
if (c.hasSVar("DiscardMe") && Integer.parseInt(c.getSVar("DiscardMe")) == priority) {
|
if (c.hasSVar("DiscardMe") && Integer.parseInt(c.getSVar("DiscardMe")) == priority) {
|
||||||
@@ -322,6 +340,14 @@ public class ComputerUtil {
|
|||||||
return ComputerUtilCard.getWorstLand(landsInHand);
|
return ComputerUtilCard.getWorstLand(landsInHand);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// try everything when about to die
|
||||||
|
if (game.getPhaseHandler().getPhase().equals(PhaseType.COMBAT_DECLARE_BLOCKERS)
|
||||||
|
&& ComputerUtilCombat.lifeInSeriousDanger(ai, game.getCombat())) {
|
||||||
|
if (!typeList.isEmpty()) {
|
||||||
|
return ComputerUtilCard.getWorstAI(typeList);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user