Added additional parameter for effect outcome. Updated choosing permanents for AI.

This commit is contained in:
magenoxx 2012-03-26 10:59:04 +04:00
parent 7ecf9f125d
commit 523481b5a2
9 changed files with 26 additions and 9 deletions

View file

@ -196,12 +196,16 @@ public class ComputerPlayer<T extends ComputerPlayer<T>> extends PlayerImpl<T> i
} }
if (target instanceof TargetPermanent) { if (target instanceof TargetPermanent) {
List<Permanent> targets; List<Permanent> targets;
if (outcome.isGood()) { if (outcome.isCanTargetAll()) {
targets = threats(playerId, ((TargetPermanent)target).getFilter(), game, target.getTargets()); targets = threats(null, ((TargetPermanent)target).getFilter(), game, target.getTargets());
} } else {
else { if (outcome.isGood()) {
targets = threats(opponentId, ((TargetPermanent)target).getFilter(), game, target.getTargets()); targets = threats(playerId, ((TargetPermanent)target).getFilter(), game, target.getTargets());
} }
else {
targets = threats(opponentId, ((TargetPermanent)target).getFilter(), game, target.getTargets());
}
}
for (Permanent permanent: targets) { for (Permanent permanent: targets) {
if (((TargetPermanent)target).canTarget(playerId, permanent.getId(), null, game) && !target.getTargets().contains(permanent.getId())) { if (((TargetPermanent)target).canTarget(playerId, permanent.getId(), null, game) && !target.getTargets().contains(permanent.getId())) {
target.add(permanent.getId(), game); target.add(permanent.getId(), game);
@ -1486,7 +1490,10 @@ public class ComputerPlayer<T extends ComputerPlayer<T>> extends PlayerImpl<T> i
} }
protected List<Permanent> threats(UUID playerId, FilterPermanent filter, Game game, List<UUID> targets) { protected List<Permanent> threats(UUID playerId, FilterPermanent filter, Game game, List<UUID> targets) {
List<Permanent> threats = game.getBattlefield().getAllActivePermanents(filter, playerId); List<Permanent> threats = playerId == null ?
game.getBattlefield().getAllActivePermanents(filter) :
game.getBattlefield().getAllActivePermanents(filter, playerId);
Iterator<Permanent> it = threats.iterator(); Iterator<Permanent> it = threats.iterator();
while (it.hasNext()) { // remove permanents already targetted while (it.hasNext()) { // remove permanents already targetted
Permanent test = it.next(); Permanent test = it.next();
@ -1494,6 +1501,7 @@ public class ComputerPlayer<T extends ComputerPlayer<T>> extends PlayerImpl<T> i
it.remove(); it.remove();
} }
Collections.sort(threats, new PermanentComparator(game)); Collections.sort(threats, new PermanentComparator(game));
Collections.reverse(threats);
return threats; return threats;
} }

View file

@ -341,23 +341,32 @@ public final class Constants {
Transform(true), Transform(true),
Untap(true), Untap(true),
Win(true), Win(true),
Copy(true), Copy(true, true),
Benefit(true), Benefit(true),
Detriment(false), Detriment(false),
Neutral(true), Neutral(true),
Removal(true); Removal(true);
private boolean good; private boolean good;
private boolean canTargetAll;
Outcome(boolean good) { Outcome(boolean good) {
this.good = good; this.good = good;
} }
Outcome(boolean good, boolean canTargetAll) {
this.good = good;
this.canTargetAll = canTargetAll;
}
public boolean isGood() { public boolean isGood() {
return good; return good;
} }
} public boolean isCanTargetAll() {
return canTargetAll;
}
}
public enum Zone { public enum Zone {
HAND, GRAVEYARD, LIBRARY, BATTLEFIELD, STACK, EXILED, ALL, OUTSIDE, PICK, COMMAND; HAND, GRAVEYARD, LIBRARY, BATTLEFIELD, STACK, EXILED, ALL, OUTSIDE, PICK, COMMAND;