mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 20:58:03 +00:00
EncodeAi: should only use it when it has a target for that
This commit is contained in:
@@ -17,6 +17,8 @@
|
|||||||
*/
|
*/
|
||||||
package forge.ai.ability;
|
package forge.ai.ability;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
|
|
||||||
import forge.ai.ComputerUtilCard;
|
import forge.ai.ComputerUtilCard;
|
||||||
@@ -29,8 +31,6 @@ import forge.game.player.Player;
|
|||||||
import forge.game.player.PlayerActionConfirmMode;
|
import forge.game.player.PlayerActionConfirmMode;
|
||||||
import forge.game.spellability.SpellAbility;
|
import forge.game.spellability.SpellAbility;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* AbilityFactoryBond class.
|
* AbilityFactoryBond class.
|
||||||
@@ -63,20 +63,36 @@ public final class EncodeAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see forge.ai.SpellAbilityAi#confirmAction(forge.game.player.Player,
|
||||||
|
* forge.game.spellability.SpellAbility,
|
||||||
|
* forge.game.player.PlayerActionConfirmMode, java.lang.String)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean confirmAction(Player player, SpellAbility sa, PlayerActionConfirmMode mode, String message) {
|
public boolean confirmAction(Player player, SpellAbility sa, PlayerActionConfirmMode mode, String message) {
|
||||||
return true;
|
// only try to encode if there is a creature it can be used on
|
||||||
|
return chooseCard(player, player.getCreaturesInPlay(), true) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/*
|
||||||
* @see forge.card.ability.SpellAbilityAi#chooseSingleCard(forge.game.player.Player, forge.card.spellability.SpellAbility, java.util.List, boolean)
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see forge.ai.SpellAbilityAi#chooseSingleCard(forge.game.player.Player,
|
||||||
|
* forge.game.spellability.SpellAbility, java.lang.Iterable, boolean,
|
||||||
|
* forge.game.player.Player)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Card chooseSingleCard(final Player ai, SpellAbility sa, Iterable<Card> options, boolean isOptional, Player targetedPlayer) {
|
public Card chooseSingleCard(final Player ai, SpellAbility sa, Iterable<Card> options, boolean isOptional, Player targetedPlayer) {
|
||||||
|
return chooseCard(ai, options, isOptional);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Card chooseCard(final Player ai, Iterable<Card> list, boolean isOptional) {
|
||||||
Card choice = null;
|
Card choice = null;
|
||||||
// final String logic = sa.getParam("AILogic");
|
// final String logic = sa.getParam("AILogic");
|
||||||
// if (logic == null) {
|
// if (logic == null) {
|
||||||
final List<Card> attackers = CardLists.filter(options, new Predicate<Card>() {
|
final List<Card> attackers = CardLists.filter(list, new Predicate<Card>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(final Card c) {
|
public boolean apply(final Card c) {
|
||||||
return ComputerUtilCombat.canAttackNextTurn(c);
|
return ComputerUtilCombat.canAttackNextTurn(c);
|
||||||
@@ -85,17 +101,24 @@ public final class EncodeAi extends SpellAbilityAi {
|
|||||||
final List<Card> unblockables = CardLists.filter(attackers, new Predicate<Card>() {
|
final List<Card> unblockables = CardLists.filter(attackers, new Predicate<Card>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(final Card c) {
|
public boolean apply(final Card c) {
|
||||||
return !CombatUtil.canBeBlocked(c, ai.getOpponent());
|
boolean canAttackOpponent = false;
|
||||||
|
for (Player opp : ai.getOpponents()) {
|
||||||
|
if (CombatUtil.canAttack(c, opp) && !CombatUtil.canBeBlocked(c, opp)) {
|
||||||
|
canAttackOpponent = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return canAttackOpponent;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (!unblockables.isEmpty()) {
|
if (!unblockables.isEmpty()) {
|
||||||
choice = ComputerUtilCard.getBestAI(unblockables);
|
choice = ComputerUtilCard.getBestAI(unblockables);
|
||||||
} else if (!attackers.isEmpty()) {
|
} else if (!attackers.isEmpty()) {
|
||||||
choice = ComputerUtilCard.getBestAI(attackers);
|
choice = ComputerUtilCard.getBestAI(attackers);
|
||||||
} else {
|
} else if (!isOptional) {
|
||||||
choice = ComputerUtilCard.getBestAI(options);
|
choice = ComputerUtilCard.getBestAI(list);
|
||||||
}
|
}
|
||||||
// }
|
// }
|
||||||
return choice;
|
return choice;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user