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,11 +196,15 @@ public class ComputerPlayer<T extends ComputerPlayer<T>> extends PlayerImpl<T> i
}
if (target instanceof TargetPermanent) {
List<Permanent> targets;
if (outcome.isCanTargetAll()) {
targets = threats(null, ((TargetPermanent)target).getFilter(), game, target.getTargets());
} else {
if (outcome.isGood()) {
targets = threats(playerId, ((TargetPermanent)target).getFilter(), game, target.getTargets());
}
else {
targets = threats(opponentId, ((TargetPermanent)target).getFilter(), game, target.getTargets());
}
}
for (Permanent permanent: targets) {
if (((TargetPermanent)target).canTarget(playerId, permanent.getId(), null, game) && !target.getTargets().contains(permanent.getId())) {
@ -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) {
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();
while (it.hasNext()) { // remove permanents already targetted
Permanent test = it.next();
@ -1494,6 +1501,7 @@ public class ComputerPlayer<T extends ComputerPlayer<T>> extends PlayerImpl<T> i
it.remove();
}
Collections.sort(threats, new PermanentComparator(game));
Collections.reverse(threats);
return threats;
}

View file

@ -341,22 +341,31 @@ public final class Constants {
Transform(true),
Untap(true),
Win(true),
Copy(true),
Copy(true, true),
Benefit(true),
Detriment(false),
Neutral(true),
Removal(true);
private boolean good;
private boolean canTargetAll;
Outcome(boolean good) {
this.good = good;
}
Outcome(boolean good, boolean canTargetAll) {
this.good = good;
this.canTargetAll = canTargetAll;
}
public boolean isGood() {
return good;
}
public boolean isCanTargetAll() {
return canTargetAll;
}
}
public enum Zone {