Fix build for Player AI projects

This commit is contained in:
Quercitron 2014-06-13 20:21:07 +04:00
parent a0fb5bfe22
commit f2114f4701
3 changed files with 36 additions and 42 deletions

View file

@ -148,7 +148,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
target.add(playerId, game); target.add(playerId, game);
return true; return true;
} }
if (target.isRequired()) { if (target.isRequired(sourceId, game)) {
if (target.canTarget(opponentId, game)) { if (target.canTarget(opponentId, game)) {
target.add(opponentId, game); target.add(opponentId, game);
return true; return true;
@ -159,7 +159,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
target.add(opponentId, game); target.add(opponentId, game);
return true; return true;
} }
if (target.isRequired()) { if (target.isRequired(sourceId, game)) {
if (target.canTarget(playerId, game)) { if (target.canTarget(playerId, game)) {
target.add(playerId, game); target.add(playerId, game);
return true; return true;
@ -266,7 +266,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
return true; return true;
} }
} }
if (!target.isRequired()) { if (!target.isRequired(sourceId, game)) {
return false; return false;
} }
} }
@ -299,7 +299,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
return true; return true;
} }
} }
if (!target.isRequired()) { if (!target.isRequired(sourceId, game)) {
return false; return false;
} }
throw new IllegalStateException("TargetPermanentOrPlayer wasn't handled. class:" + target.getClass().toString()); throw new IllegalStateException("TargetPermanentOrPlayer wasn't handled. class:" + target.getClass().toString());
@ -350,7 +350,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
target.addTarget(playerId, source, game); target.addTarget(playerId, source, game);
return true; return true;
} }
if (target.isRequired()) { if (target.isRequired(source)) {
if (target.canTarget(opponentId, source, game)) { if (target.canTarget(opponentId, source, game)) {
target.addTarget(opponentId, source, game); target.addTarget(opponentId, source, game);
return true; return true;
@ -362,7 +362,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
target.addTarget(opponentId, source, game); target.addTarget(opponentId, source, game);
return true; return true;
} }
if (target.isRequired()) { if (target.isRequired(source)) {
if (target.canTarget(playerId, source, game)) { if (target.canTarget(playerId, source, game)) {
target.addTarget(playerId, source, game); target.addTarget(playerId, source, game);
return true; return true;
@ -438,7 +438,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
else { else {
targets = threats(opponentId, source == null?null:source.getSourceId(), ((TargetPermanent)target).getFilter(), game, target.getTargets()); targets = threats(opponentId, source == null?null:source.getSourceId(), ((TargetPermanent)target).getFilter(), game, target.getTargets());
} }
if (targets.isEmpty() && target.isRequired()) { if (targets.isEmpty() && target.isRequired(source)) {
targets = threats(null, source == null?null:source.getSourceId(), ((TargetPermanent)target).getFilter(), game, target.getTargets()); targets = threats(null, source == null?null:source.getSourceId(), ((TargetPermanent)target).getFilter(), game, target.getTargets());
Collections.reverse(targets); Collections.reverse(targets);
outcomeTargets = false; outcomeTargets = false;
@ -479,7 +479,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
} }
} }
if (targets.isEmpty() && target.isRequired()) { if (targets.isEmpty() && target.isRequired(source)) {
targets = game.getBattlefield().getActivePermanents(((FilterCreatureOrPlayer)t.getFilter()).getCreatureFilter(), playerId, game); targets = game.getBattlefield().getActivePermanents(((FilterCreatureOrPlayer)t.getFilter()).getCreatureFilter(), playerId, game);
} }
for (Permanent permanent : targets) { for (Permanent permanent : targets) {
@ -573,7 +573,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
else { else {
targets = threats(opponentId, source == null?null:source.getSourceId(), ((TargetPermanent)target).getFilter(), game, target.getTargets()); targets = threats(opponentId, source == null?null:source.getSourceId(), ((TargetPermanent)target).getFilter(), game, target.getTargets());
} }
if (targets.isEmpty() && target.isRequired()) { if (targets.isEmpty() && target.isRequired(source)) {
targets = threats(null, source == null?null:source.getSourceId(), ((TargetPermanent)target).getFilter(), game, target.getTargets()); targets = threats(null, source == null?null:source.getSourceId(), ((TargetPermanent)target).getFilter(), game, target.getTargets());
Collections.reverse(targets); Collections.reverse(targets);
outcomeTargets = false; outcomeTargets = false;
@ -1187,7 +1187,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
public boolean chooseTarget(Outcome outcome, Cards cards, TargetCard target, Ability source, Game game) { public boolean chooseTarget(Outcome outcome, Cards cards, TargetCard target, Ability source, Game game) {
log.debug("chooseTarget"); log.debug("chooseTarget");
if (cards == null || cards.isEmpty()) { if (cards == null || cards.isEmpty()) {
if (!target.isRequired()) { if (!target.isRequired(source)) {
return false; return false;
} }
return true; return true;
@ -1211,9 +1211,6 @@ public class ComputerPlayer extends PlayerImpl implements Player {
public boolean choose(Outcome outcome, Cards cards, TargetCard target, Game game) { public boolean choose(Outcome outcome, Cards cards, TargetCard target, Game game) {
log.debug("choose 2"); log.debug("choose 2");
if (cards == null || cards.isEmpty()) { if (cards == null || cards.isEmpty()) {
if (!target.isRequired()) {
return false;
}
return true; return true;
} }

View file

@ -220,13 +220,9 @@ public class SimulatedPlayerMCTS extends MCTSPlayer {
protected boolean chooseRandom(Target target, Game game) { protected boolean chooseRandom(Target target, Game game) {
Set<UUID> possibleTargets = target.possibleTargets(playerId, game); Set<UUID> possibleTargets = target.possibleTargets(playerId, game);
if (possibleTargets.isEmpty()) if (possibleTargets.isEmpty()) {
return !target.isRequired();
if (!target.isRequired()) {
if (rnd.nextInt(possibleTargets.size() + 1) == 0) {
return false; return false;
} }
}
if (possibleTargets.size() == 1) { if (possibleTargets.size() == 1) {
target.add(possibleTargets.iterator().next(), game); target.add(possibleTargets.iterator().next(), game);
return true; return true;
@ -245,7 +241,7 @@ public class SimulatedPlayerMCTS extends MCTSPlayer {
Set<UUID> possibleTargets = target.possibleTargets(source==null?null:source.getSourceId(), playerId, game); Set<UUID> possibleTargets = target.possibleTargets(source==null?null:source.getSourceId(), playerId, game);
if (possibleTargets.isEmpty()) if (possibleTargets.isEmpty())
return false; return false;
if (!target.isRequired()) { if (!target.isRequired(source)) {
if (rnd.nextInt(possibleTargets.size() + 1) == 0) { if (rnd.nextInt(possibleTargets.size() + 1) == 0) {
return false; return false;
} }
@ -281,11 +277,13 @@ public class SimulatedPlayerMCTS extends MCTSPlayer {
@Override @Override
public boolean choose(Outcome outcome, Cards cards, TargetCard target, Game game) { public boolean choose(Outcome outcome, Cards cards, TargetCard target, Game game) {
if (this.isHuman()) { if (this.isHuman()) {
if (cards.isEmpty()) if (cards.isEmpty()) {
return !target.isRequired(); return false;
}
Set<UUID> possibleTargets = target.possibleTargets(playerId, cards, game); Set<UUID> possibleTargets = target.possibleTargets(playerId, cards, game);
if (possibleTargets.isEmpty()) if (possibleTargets.isEmpty()) {
return !target.isRequired(); return false;
}
Iterator<UUID> it = possibleTargets.iterator(); Iterator<UUID> it = possibleTargets.iterator();
int targetNum = rnd.nextInt(possibleTargets.size()); int targetNum = rnd.nextInt(possibleTargets.size());
UUID targetId = it.next(); UUID targetId = it.next();
@ -306,7 +304,7 @@ public class SimulatedPlayerMCTS extends MCTSPlayer {
@Override @Override
public boolean chooseTarget(Outcome outcome, Cards cards, TargetCard target, Ability source, Game game) { public boolean chooseTarget(Outcome outcome, Cards cards, TargetCard target, Ability source, Game game) {
if (cards.isEmpty()) if (cards.isEmpty())
return !target.isRequired(); return !target.isRequired(source);
Card card = cards.getRandom(game); Card card = cards.getRandom(game);
target.addTarget(card.getId(), source, game); target.addTarget(card.getId(), source, game);
return true; return true;
@ -316,8 +314,8 @@ public class SimulatedPlayerMCTS extends MCTSPlayer {
public boolean chooseTargetAmount(Outcome outcome, TargetAmount target, Ability source, Game game) { public boolean chooseTargetAmount(Outcome outcome, TargetAmount target, Ability source, Game game) {
Set<UUID> possibleTargets = target.possibleTargets(source==null?null:source.getSourceId(), playerId, game); Set<UUID> possibleTargets = target.possibleTargets(source==null?null:source.getSourceId(), playerId, game);
if (possibleTargets.isEmpty()) if (possibleTargets.isEmpty())
return !target.isRequired(); return !target.isRequired(source);
if (!target.isRequired()) { if (!target.isRequired(source)) {
if (rnd.nextInt(possibleTargets.size() + 1) == 0) { if (rnd.nextInt(possibleTargets.size() + 1) == 0) {
return false; return false;
} }

View file

@ -220,13 +220,9 @@ public class RandomPlayer extends ComputerPlayer {
protected boolean chooseRandom(Target target, Game game) { protected boolean chooseRandom(Target target, Game game) {
Set<UUID> possibleTargets = target.possibleTargets(playerId, game); Set<UUID> possibleTargets = target.possibleTargets(playerId, game);
if (possibleTargets.isEmpty()) if (possibleTargets.isEmpty()) {
return !target.isRequired();
if (!target.isRequired()) {
if (rnd.nextInt(possibleTargets.size() + 1) == 0) {
return false; return false;
} }
}
if (possibleTargets.size() == 1) { if (possibleTargets.size() == 1) {
target.add(possibleTargets.iterator().next(), game); target.add(possibleTargets.iterator().next(), game);
return true; return true;
@ -245,7 +241,7 @@ public class RandomPlayer extends ComputerPlayer {
Set<UUID> possibleTargets = target.possibleTargets(source==null?null:source.getSourceId(), playerId, game); Set<UUID> possibleTargets = target.possibleTargets(source==null?null:source.getSourceId(), playerId, game);
if (possibleTargets.isEmpty()) if (possibleTargets.isEmpty())
return false; return false;
if (!target.isRequired()) { if (!target.isRequired(source)) {
if (rnd.nextInt(possibleTargets.size() + 1) == 0) { if (rnd.nextInt(possibleTargets.size() + 1) == 0) {
return false; return false;
} }
@ -276,11 +272,13 @@ public class RandomPlayer extends ComputerPlayer {
@Override @Override
public boolean choose(Outcome outcome, Cards cards, TargetCard target, Game game) { public boolean choose(Outcome outcome, Cards cards, TargetCard target, Game game) {
if (cards.isEmpty()) if (cards.isEmpty()) {
return !target.isRequired(); return false;
}
Set<UUID> possibleTargets = target.possibleTargets(playerId, cards, game); Set<UUID> possibleTargets = target.possibleTargets(playerId, cards, game);
if (possibleTargets.isEmpty()) if (possibleTargets.isEmpty()) {
return !target.isRequired(); return !false;
}
Iterator<UUID> it = possibleTargets.iterator(); Iterator<UUID> it = possibleTargets.iterator();
int targetNum = rnd.nextInt(possibleTargets.size()); int targetNum = rnd.nextInt(possibleTargets.size());
UUID targetId = it.next(); UUID targetId = it.next();
@ -299,7 +297,7 @@ public class RandomPlayer extends ComputerPlayer {
@Override @Override
public boolean chooseTarget(Outcome outcome, Cards cards, TargetCard target, Ability source, Game game) { public boolean chooseTarget(Outcome outcome, Cards cards, TargetCard target, Ability source, Game game) {
if (cards.isEmpty()) if (cards.isEmpty())
return !target.isRequired(); return !target.isRequired(source);
Card card = cards.getRandom(game); Card card = cards.getRandom(game);
target.addTarget(card.getId(), source, game); target.addTarget(card.getId(), source, game);
return true; return true;
@ -308,9 +306,10 @@ public class RandomPlayer extends ComputerPlayer {
@Override @Override
public boolean chooseTargetAmount(Outcome outcome, TargetAmount target, Ability source, Game game) { public boolean chooseTargetAmount(Outcome outcome, TargetAmount target, Ability source, Game game) {
Set<UUID> possibleTargets = target.possibleTargets(source==null?null:source.getSourceId(), playerId, game); Set<UUID> possibleTargets = target.possibleTargets(source==null?null:source.getSourceId(), playerId, game);
if (possibleTargets.isEmpty()) if (possibleTargets.isEmpty()) {
return !target.isRequired(); return !target.isRequired(source);
if (!target.isRequired()) { }
if (!target.isRequired(source)) {
if (rnd.nextInt(possibleTargets.size() + 1) == 0) { if (rnd.nextInt(possibleTargets.size() + 1) == 0) {
return false; return false;
} }