This commit is contained in:
BetaSteward 2010-04-16 03:50:58 +00:00
parent 1e292afb69
commit 7e16c0ff81
2 changed files with 63 additions and 24 deletions

View file

@ -58,6 +58,8 @@ import mage.abilities.costs.mana.MonoHybridManaCost;
import mage.abilities.costs.mana.VariableManaCost; import mage.abilities.costs.mana.VariableManaCost;
import mage.abilities.effects.Effect; import mage.abilities.effects.Effect;
import mage.abilities.effects.ReplacementEffect; import mage.abilities.effects.ReplacementEffect;
import mage.abilities.effects.common.BecomesCreatureSourceEOTEffect;
import mage.abilities.effects.common.DamageTargetEffect;
import mage.abilities.keyword.DoubleStrikeAbility; import mage.abilities.keyword.DoubleStrikeAbility;
import mage.abilities.keyword.FirstStrikeAbility; import mage.abilities.keyword.FirstStrikeAbility;
import mage.abilities.keyword.TrampleAbility; import mage.abilities.keyword.TrampleAbility;
@ -84,6 +86,7 @@ import mage.target.TargetCard;
import mage.target.TargetPermanent; import mage.target.TargetPermanent;
import mage.target.TargetPlayer; import mage.target.TargetPlayer;
import mage.target.common.TargetDiscard; import mage.target.common.TargetDiscard;
import mage.target.common.TargetSacrificePermanent;
import mage.util.Copier; import mage.util.Copier;
import mage.util.Logging; import mage.util.Logging;
import mage.util.TreeNode; import mage.util.TreeNode;
@ -154,6 +157,17 @@ public class ComputerPlayer extends PlayerImpl implements Player {
} }
} }
} }
if (target instanceof TargetSacrificePermanent) {
List<Permanent> targets;
targets = threats(playerId, (TargetPermanent) target, game);
Collections.reverse(targets);
for (Permanent permanent: targets) {
if (target.canTarget(permanent.getId(), game)) {
target.addTarget(permanent.getId(), game);
return true;
}
}
}
if (target instanceof TargetPermanent) { if (target instanceof TargetPermanent) {
List<Permanent> targets; List<Permanent> targets;
if (outcome.isGood()) { if (outcome.isGood()) {
@ -175,6 +189,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
@Override @Override
public void priority(Game game) { public void priority(Game game) {
logger.fine("priority"); logger.fine("priority");
UUID opponentId = game.getOpponents(playerId).get(0);
if (game.getActivePlayerId().equals(playerId)) { if (game.getActivePlayerId().equals(playerId)) {
if (game.isMainPhase() && game.getStack().isEmpty()) { if (game.isMainPhase() && game.getStack().isEmpty()) {
playLand(game); playLand(game);
@ -185,8 +200,6 @@ public class ComputerPlayer extends PlayerImpl implements Player {
break; break;
case DRAW: case DRAW:
logState(game); logState(game);
case DECLARE_BLOCKERS:
playRemoval(game.getCombat().getAttackers(), game);
case PRECOMBAT_MAIN: case PRECOMBAT_MAIN:
findPlayables(game); findPlayables(game);
if (playableAbilities.size() > 0) { if (playableAbilities.size() > 0) {
@ -196,10 +209,20 @@ public class ComputerPlayer extends PlayerImpl implements Player {
if (this.activateAbility(ability, game)) if (this.activateAbility(ability, game))
return; return;
} }
if (ability.getEffects().hasOutcome(Outcome.PutCreatureInPlay)) {
if (getOpponentBlockers(opponentId, game).size() <= 1)
if (this.activateAbility(ability, game))
return;
}
} }
} }
} }
break; break;
case DECLARE_BLOCKERS:
playRemoval(game.getCombat().getBlockers(), game);
playDamage(game.getCombat().getBlockers(), game);
case END_COMBAT:
playDamage(game.getCombat().getBlockers(), game);
case POSTCOMBAT_MAIN: case POSTCOMBAT_MAIN:
findPlayables(game); findPlayables(game);
if (game.getStack().isEmpty()) { if (game.getStack().isEmpty()) {
@ -214,17 +237,26 @@ public class ComputerPlayer extends PlayerImpl implements Player {
if (playableAbilities.size() > 0) { if (playableAbilities.size() > 0) {
for (ActivatedAbility ability: playableAbilities) { for (ActivatedAbility ability: playableAbilities) {
if (ability.canActivate(playerId, game)) { if (ability.canActivate(playerId, game)) {
if (!(ability.getEffects().get(0) instanceof BecomesCreatureSourceEOTEffect)) {
if (this.activateAbility(ability, game)) if (this.activateAbility(ability, game))
return; return;
} }
} }
} }
} }
}
break; break;
} }
} }
else { else {
//respond to opponent events //respond to opponent events
switch (game.getTurn().getStep()) {
case DECLARE_ATTACKERS:
playRemoval(game.getCombat().getAttackers(), game);
playDamage(game.getCombat().getAttackers(), game);
case END_COMBAT:
playDamage(game.getCombat().getAttackers(), game);
}
} }
this.passed = true; this.passed = true;
} }
@ -481,7 +513,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
public void selectAttackers(Game game) { public void selectAttackers(Game game) {
logger.fine("selectAttackers"); logger.fine("selectAttackers");
UUID opponentId = game.getOpponents(playerId).get(0); UUID opponentId = game.getOpponents(playerId).get(0);
Attackers attackers = getAvailableAttackers(game); Attackers attackers = getPotentialAttackers(game);
List<Permanent> blockers = getOpponentBlockers(opponentId, game); List<Permanent> blockers = getOpponentBlockers(opponentId, game);
List<Permanent> actualAttackers = new ArrayList<Permanent>(); List<Permanent> actualAttackers = new ArrayList<Permanent>();
if (blockers.isEmpty()) { if (blockers.isEmpty()) {
@ -564,12 +596,10 @@ public class ComputerPlayer extends PlayerImpl implements Player {
return result; return result;
} }
protected Attackers getAvailableAttackers(Game game) { protected Attackers getPotentialAttackers(Game game) {
logger.fine("getAvailableAttackers"); logger.fine("getAvailableAttackers");
FilterCreatureForAttack attackFilter = new FilterCreatureForAttack();
attackFilter.getControllerId().add(playerId);
Attackers attackers = new Attackers(); Attackers attackers = new Attackers();
List<Permanent> creatures = game.getBattlefield().getActivePermanents(attackFilter); List<Permanent> creatures = super.getAvailableAttackers(game);
for (Permanent creature: creatures) { for (Permanent creature: creatures) {
int potential = combatPotential(creature, game); int potential = combatPotential(creature, game);
if (potential > 0) { if (potential > 0) {
@ -732,14 +762,15 @@ public class ComputerPlayer extends PlayerImpl implements Player {
logger.fine(sb.toString()); logger.fine(sb.toString());
} }
private void playRemoval(List<UUID> attackers, Game game) { private void playRemoval(List<UUID> creatures, Game game) {
for (UUID attackerId: attackers) { for (UUID creatureId: creatures) {
for (Card card: this.playableInstant) { for (Card card: this.playableInstant) {
if (card.getSpellAbility().canActivate(playerId, game)) { if (card.getSpellAbility().canActivate(playerId, game)) {
for (Effect effect: card.getSpellAbility().getEffects()) { for (Effect effect: card.getSpellAbility().getEffects()) {
if (effect.getOutcome().equals(Outcome.DestroyPermanent) || effect.getOutcome().equals(Outcome.Damage)) { if (effect.getOutcome().equals(Outcome.DestroyPermanent)) {
if (card.getSpellAbility().getTargets().get(0).canTarget(attackerId, game)) { if (card.getSpellAbility().getTargets().get(0).canTarget(creatureId, game)) {
if (this.activateAbility(card.getSpellAbility(), game))
return;
} }
} }
} }
@ -748,17 +779,24 @@ public class ComputerPlayer extends PlayerImpl implements Player {
} }
} }
protected int evaluateState(GameState state, Game game) { private void playDamage(List<UUID> creatures, Game game) {
int value = life; for (UUID creatureId: creatures) {
Player opponent = game.getPlayer(game.getOpponents(playerId).get(0)); Permanent creature = game.getPermanent(creatureId);
if (opponent.getLife() <= 0) for (Card card: this.playableInstant) {
return Integer.MAX_VALUE; if (card.getSpellAbility().canActivate(playerId, game)) {
value -= opponent.getLife(); for (Effect effect: card.getSpellAbility().getEffects()) {
for (Permanent permanent: state.getBattlefield().getAllPermanents()) { if (effect instanceof DamageTargetEffect) {
if (card.getSpellAbility().getTargets().get(0).canTarget(creatureId, game)) {
if (((DamageTargetEffect)effect).getAmount() > (creature.getPower().getValue() - creature.getDamage())) {
if (this.activateAbility(card.getSpellAbility(), game))
return;
}
}
}
}
}
}
}
} }
return value;
}
} }

View file

@ -45,6 +45,7 @@ public class PermanentComparator implements Comparator<Permanent> {
this.game = game; this.game = game;
} }
@Override
public int compare(Permanent o1, Permanent o2) { public int compare(Permanent o1, Permanent o2) {
return evaluator.evaluate(o1, game) - evaluator.evaluate(o2, game); return evaluator.evaluate(o1, game) - evaluator.evaluate(o2, game);
} }