mirror of
https://github.com/correl/mage.git
synced 2024-12-24 11:50:45 +00:00
[ai-ma] renamed classes (otherwise classloader uses another classes), added additional logging.
This commit is contained in:
parent
f7ffbb4773
commit
f36254445a
13 changed files with 166 additions and 157 deletions
|
@ -4,4 +4,4 @@ evaluatorLifeFactor=2
|
||||||
evaluatorPermanentFactor=1
|
evaluatorPermanentFactor=1
|
||||||
evaluatorCreatureFactor=1
|
evaluatorCreatureFactor=1
|
||||||
evaluatorHandFactor=1
|
evaluatorHandFactor=1
|
||||||
maxThinkSeconds=30
|
maxThinkSeconds=10
|
|
@ -37,7 +37,7 @@ import mage.game.permanent.Permanent;
|
||||||
*
|
*
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
*/
|
*/
|
||||||
public class Attackers extends TreeMap<Integer, List<Permanent>> {
|
public class Attackers2 extends TreeMap<Integer, List<Permanent>> {
|
||||||
|
|
||||||
public List<Permanent> getAttackers() {
|
public List<Permanent> getAttackers() {
|
||||||
List<Permanent> attackers = new ArrayList<Permanent>();
|
List<Permanent> attackers = new ArrayList<Permanent>();
|
|
@ -96,12 +96,12 @@ public class ComputerPlayer4 extends ComputerPlayer<ComputerPlayer4> implements
|
||||||
protected List<String> choices = new ArrayList<String>();
|
protected List<String> choices = new ArrayList<String>();
|
||||||
protected Combat combat;
|
protected Combat combat;
|
||||||
protected int currentScore;
|
protected int currentScore;
|
||||||
protected SimulationNode root;
|
protected SimulationNode2 root;
|
||||||
|
|
||||||
public ComputerPlayer4(String name, RangeOfInfluence range) {
|
public ComputerPlayer4(String name, RangeOfInfluence range) {
|
||||||
super(name, range);
|
super(name, range);
|
||||||
maxDepth = Config.maxDepth;
|
maxDepth = Config2.maxDepth;
|
||||||
maxNodes = Config.maxNodes;
|
maxNodes = Config2.maxNodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ComputerPlayer4(final ComputerPlayer4 player) {
|
public ComputerPlayer4(final ComputerPlayer4 player) {
|
||||||
|
@ -172,12 +172,12 @@ public class ComputerPlayer4 extends ComputerPlayer<ComputerPlayer4> implements
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void calculateActions(Game game) {
|
protected void calculateActions(Game game) {
|
||||||
currentScore = GameStateEvaluator.evaluate(playerId, game);
|
currentScore = GameStateEvaluator2.evaluate(playerId, game);
|
||||||
if (!getNextAction(game)) {
|
if (!getNextAction(game)) {
|
||||||
Game sim = createSimulation(game);
|
Game sim = createSimulation(game);
|
||||||
SimulationNode.resetCount();
|
SimulationNode2.resetCount();
|
||||||
root = new SimulationNode(sim, maxDepth, playerId);
|
root = new SimulationNode2(sim, maxDepth, playerId);
|
||||||
logger.fine("simulating actions");
|
logger.info("simulating actions");
|
||||||
addActionsTimed(new FilterAbility());
|
addActionsTimed(new FilterAbility());
|
||||||
if (root.children.size() > 0) {
|
if (root.children.size() > 0) {
|
||||||
root = root.children.get(0);
|
root = root.children.get(0);
|
||||||
|
@ -189,15 +189,15 @@ public class ComputerPlayer4 extends ComputerPlayer<ComputerPlayer4> implements
|
||||||
|
|
||||||
protected boolean getNextAction(Game game) {
|
protected boolean getNextAction(Game game) {
|
||||||
if (root != null && root.children.size() > 0) {
|
if (root != null && root.children.size() > 0) {
|
||||||
SimulationNode test = root;
|
SimulationNode2 test = root;
|
||||||
root = root.children.get(0);
|
root = root.children.get(0);
|
||||||
while (root.children.size() > 0 && !root.playerId.equals(playerId)) {
|
while (root.children.size() > 0 && !root.playerId.equals(playerId)) {
|
||||||
test = root;
|
test = root;
|
||||||
root = root.children.get(0);
|
root = root.children.get(0);
|
||||||
}
|
}
|
||||||
logger.fine("simlating -- game value:" + game.getState().getValue() + " test value:" + test.gameValue);
|
logger.info("simlating -- game value:" + game.getState().getValue() + " test value:" + test.gameValue);
|
||||||
if (root.playerId.equals(playerId) && root.abilities != null && game.getState().getValue() == test.gameValue) {
|
if (root.playerId.equals(playerId) && root.abilities != null && game.getState().getValue() == test.gameValue) {
|
||||||
logger.fine("simulating -- continuing previous action chain");
|
logger.info("simulating -- continuing previous action chain");
|
||||||
actions = new LinkedList<Ability>(root.abilities);
|
actions = new LinkedList<Ability>(root.abilities);
|
||||||
combat = root.combat;
|
combat = root.combat;
|
||||||
return true;
|
return true;
|
||||||
|
@ -209,16 +209,16 @@ public class ComputerPlayer4 extends ComputerPlayer<ComputerPlayer4> implements
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int minimaxAB(SimulationNode node, FilterAbility filter, int depth, int alpha, int beta) {
|
protected int minimaxAB(SimulationNode2 node, FilterAbility filter, int depth, int alpha, int beta) {
|
||||||
UUID currentPlayerId = node.getGame().getPlayerList().get();
|
UUID currentPlayerId = node.getGame().getPlayerList().get();
|
||||||
SimulationNode bestChild = null;
|
SimulationNode2 bestChild = null;
|
||||||
for (SimulationNode child: node.getChildren()) {
|
for (SimulationNode2 child: node.getChildren()) {
|
||||||
if (alpha >= beta) {
|
if (alpha >= beta) {
|
||||||
logger.fine("alpha beta pruning");
|
logger.info("alpha beta pruning");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (SimulationNode.nodeCount > maxNodes) {
|
if (SimulationNode2.nodeCount > maxNodes) {
|
||||||
logger.fine("simulating -- reached end-state");
|
logger.info("simulating -- reached end-state, count=" + SimulationNode2.nodeCount);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
int val = addActions(child, filter, depth-1, alpha, beta);
|
int val = addActions(child, filter, depth-1, alpha, beta);
|
||||||
|
@ -243,11 +243,11 @@ public class ComputerPlayer4 extends ComputerPlayer<ComputerPlayer4> implements
|
||||||
if (bestChild != null)
|
if (bestChild != null)
|
||||||
node.children.add(bestChild);
|
node.children.add(bestChild);
|
||||||
if (!currentPlayerId.equals(playerId)) {
|
if (!currentPlayerId.equals(playerId)) {
|
||||||
logger.fine("returning minimax beta: " + beta);
|
logger.info("returning minimax beta: " + beta);
|
||||||
return beta;
|
return beta;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
logger.fine("returning minimax alpha: " + alpha);
|
logger.info("returning minimax alpha: " + alpha);
|
||||||
return alpha;
|
return alpha;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -261,7 +261,7 @@ public class ComputerPlayer4 extends ComputerPlayer<ComputerPlayer4> implements
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void resolve(SimulationNode node, int depth, Game game) {
|
protected void resolve(SimulationNode2 node, int depth, Game game) {
|
||||||
StackObject ability = game.getStack().pop();
|
StackObject ability = game.getStack().pop();
|
||||||
if (ability instanceof StackAbility) {
|
if (ability instanceof StackAbility) {
|
||||||
SearchEffect effect = getSearchEffect((StackAbility) ability);
|
SearchEffect effect = getSearchEffect((StackAbility) ability);
|
||||||
|
@ -274,16 +274,16 @@ public class ComputerPlayer4 extends ComputerPlayer<ComputerPlayer4> implements
|
||||||
SearchEffect newEffect = getSearchEffect((StackAbility) newAbility);
|
SearchEffect newEffect = getSearchEffect((StackAbility) newAbility);
|
||||||
newEffect.getTarget().addTarget(targetId, newAbility, sim);
|
newEffect.getTarget().addTarget(targetId, newAbility, sim);
|
||||||
sim.getStack().push(newAbility);
|
sim.getStack().push(newAbility);
|
||||||
SimulationNode newNode = new SimulationNode(sim, depth, ability.getControllerId());
|
SimulationNode2 newNode = new SimulationNode2(sim, depth, ability.getControllerId());
|
||||||
node.children.add(newNode);
|
node.children.add(newNode);
|
||||||
newNode.getTargets().add(targetId);
|
newNode.getTargets().add(targetId);
|
||||||
logger.fine("simulating search -- node#: " + SimulationNode.getCount() + "for player: " + sim.getPlayer(ability.getControllerId()).getName());
|
logger.fine("simulating search -- node#: " + SimulationNode2.getCount() + "for player: " + sim.getPlayer(ability.getControllerId()).getName());
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logger.fine("simulating resolve ");
|
//logger.info("simulating resolve ");
|
||||||
ability.resolve(game);
|
ability.resolve(game);
|
||||||
game.applyEffects();
|
game.applyEffects();
|
||||||
game.getPlayers().resetPassed();
|
game.getPlayers().resetPassed();
|
||||||
|
@ -299,9 +299,9 @@ public class ComputerPlayer4 extends ComputerPlayer<ComputerPlayer4> implements
|
||||||
});
|
});
|
||||||
pool.execute(task);
|
pool.execute(task);
|
||||||
try {
|
try {
|
||||||
task.get(Config.maxThinkSeconds, TimeUnit.SECONDS);
|
task.get(Config2.maxThinkSeconds, TimeUnit.SECONDS);
|
||||||
} catch (TimeoutException e) {
|
} catch (TimeoutException e) {
|
||||||
logger.fine("simulating - timed out");
|
logger.info("simulating - timed out");
|
||||||
task.cancel(true);
|
task.cancel(true);
|
||||||
} catch (ExecutionException e) {
|
} catch (ExecutionException e) {
|
||||||
|
|
||||||
|
@ -310,25 +310,26 @@ public class ComputerPlayer4 extends ComputerPlayer<ComputerPlayer4> implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int addActions(SimulationNode node, FilterAbility filter, int depth, int alpha, int beta) {
|
protected int addActions(SimulationNode2 node, FilterAbility filter, int depth, int alpha, int beta) {
|
||||||
|
logger.info("addActions: " + depth + ", alpha=" + alpha + ", beta=" + beta);
|
||||||
Game game = node.getGame();
|
Game game = node.getGame();
|
||||||
int val;
|
int val;
|
||||||
if (Thread.interrupted()) {
|
if (Thread.interrupted()) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
logger.fine("interrupted");
|
logger.info("interrupted");
|
||||||
return GameStateEvaluator.evaluate(playerId, game);
|
return GameStateEvaluator2.evaluate(playerId, game);
|
||||||
}
|
}
|
||||||
if (depth <= 0 || SimulationNode.nodeCount > maxNodes || game.isGameOver()) {
|
if (depth <= 0 || SimulationNode2.nodeCount > maxNodes || game.isGameOver()) {
|
||||||
logger.fine("simulating -- reached end state");
|
logger.info("simulating -- reached end state, node count="+ SimulationNode2.nodeCount + ", depth="+depth);
|
||||||
val = GameStateEvaluator.evaluate(playerId, game);
|
val = GameStateEvaluator2.evaluate(playerId, game);
|
||||||
}
|
}
|
||||||
else if (node.getChildren().size() > 0) {
|
else if (node.getChildren().size() > 0) {
|
||||||
logger.fine("simulating -- somthing added children:" + node.getChildren().size());
|
logger.info("simulating -- somthing added children:" + node.getChildren().size());
|
||||||
val = minimaxAB(node, filter, depth-1, alpha, beta);
|
val = minimaxAB(node, filter, depth-1, alpha, beta);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (logger.isLoggable(Level.FINE))
|
if (logger.isLoggable(Level.FINE))
|
||||||
logger.fine("simulating -- alpha: " + alpha + " beta: " + beta + " depth:" + depth + " step:" + game.getTurn().getStepType() + " for player:" + (node.getPlayerId().equals(playerId)?"yes":"no"));
|
logger.info("simulating -- alpha: " + alpha + " beta: " + beta + " depth:" + depth + " step:" + game.getTurn().getStepType() + " for player:" + (node.getPlayerId().equals(playerId)?"yes":"no"));
|
||||||
if (allPassed(game)) {
|
if (allPassed(game)) {
|
||||||
if (!game.getStack().isEmpty()) {
|
if (!game.getStack().isEmpty()) {
|
||||||
resolve(node, depth, game);
|
resolve(node, depth, game);
|
||||||
|
@ -337,7 +338,7 @@ public class ComputerPlayer4 extends ComputerPlayer<ComputerPlayer4> implements
|
||||||
// int testScore = GameStateEvaluator.evaluate(playerId, game);
|
// int testScore = GameStateEvaluator.evaluate(playerId, game);
|
||||||
// if (testScore < currentScore) {
|
// if (testScore < currentScore) {
|
||||||
// // if score at end of step is worse than original score don't check any further
|
// // if score at end of step is worse than original score don't check any further
|
||||||
// logger.fine("simulating -- abandoning current check, no immediate benefit");
|
// logger.info("simulating -- abandoning current check, no immediate benefit");
|
||||||
// return testScore;
|
// return testScore;
|
||||||
// }
|
// }
|
||||||
game.getPlayers().resetPassed();
|
game.getPlayers().resetPassed();
|
||||||
|
@ -346,12 +347,13 @@ public class ComputerPlayer4 extends ComputerPlayer<ComputerPlayer4> implements
|
||||||
}
|
}
|
||||||
|
|
||||||
if (game.isGameOver()) {
|
if (game.isGameOver()) {
|
||||||
val = GameStateEvaluator.evaluate(playerId, game);
|
val = GameStateEvaluator2.evaluate(playerId, game);
|
||||||
}
|
}
|
||||||
else if (node.getChildren().size() > 0) {
|
else if (node.getChildren().size() > 0) {
|
||||||
|
throw new RuntimeException("This shouldn't happen.");
|
||||||
//declared attackers or blockers or triggered abilities
|
//declared attackers or blockers or triggered abilities
|
||||||
logger.fine("simulating -- attack/block/trigger added children:" + node.getChildren().size());
|
///logger.info("simulating -- attack/block/trigger added children:" + node.getChildren().size());
|
||||||
val = minimaxAB(node, filter, depth-1, alpha, beta);
|
///val = minimaxAB(node, filter, depth-1, alpha, beta);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
val = simulatePriority(node, game, filter, depth, alpha, beta);
|
val = simulatePriority(node, game, filter, depth, alpha, beta);
|
||||||
|
@ -359,24 +361,24 @@ public class ComputerPlayer4 extends ComputerPlayer<ComputerPlayer4> implements
|
||||||
}
|
}
|
||||||
|
|
||||||
if (logger.isLoggable(Level.FINE))
|
if (logger.isLoggable(Level.FINE))
|
||||||
logger.fine("returning -- score: " + val + " depth:" + depth + " step:" + game.getTurn().getStepType() + " for player:" + game.getPlayer(node.getPlayerId()).getName());
|
logger.info("returning -- score: " + val + " depth:" + depth + " step:" + game.getTurn().getStepType() + " for player:" + game.getPlayer(node.getPlayerId()).getName());
|
||||||
return val;
|
return val;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int simulatePriority(SimulationNode node, Game game, FilterAbility filter, int depth, int alpha, int beta) {
|
protected int simulatePriority(SimulationNode2 node, Game game, FilterAbility filter, int depth, int alpha, int beta) {
|
||||||
if (Thread.interrupted()) {
|
if (Thread.interrupted()) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
logger.fine("interrupted");
|
logger.info("interrupted");
|
||||||
return GameStateEvaluator.evaluate(playerId, game);
|
return GameStateEvaluator2.evaluate(playerId, game);
|
||||||
}
|
}
|
||||||
node.setGameValue(game.getState().getValue());
|
node.setGameValue(game.getState().getValue());
|
||||||
SimulatedPlayer currentPlayer = (SimulatedPlayer) game.getPlayer(game.getPlayerList().get());
|
SimulatedPlayer2 currentPlayer = (SimulatedPlayer2) game.getPlayer(game.getPlayerList().get());
|
||||||
logger.fine("simulating -- player " + currentPlayer.getName());
|
//logger.info("simulating -- player " + currentPlayer.getName());
|
||||||
SimulationNode bestNode = null;
|
SimulationNode2 bestNode = null;
|
||||||
List<Ability> allActions = currentPlayer.simulatePriority(game, filter);
|
List<Ability> allActions = currentPlayer.simulatePriority(game, filter);
|
||||||
if (logger.isLoggable(Level.FINE))
|
if (logger.isLoggable(Level.FINE))
|
||||||
logger.fine("simulating -- adding " + allActions.size() + " children:" + allActions);
|
logger.info("simulating -- adding " + allActions.size() + " children:" + allActions);
|
||||||
for (Ability action: allActions) {
|
for (Ability action: allActions) {
|
||||||
Game sim = game.copy();
|
Game sim = game.copy();
|
||||||
if (sim.getPlayer(currentPlayer.getId()).activateAbility((ActivatedAbility) action.copy(), sim)) {
|
if (sim.getPlayer(currentPlayer.getId()).activateAbility((ActivatedAbility) action.copy(), sim)) {
|
||||||
|
@ -386,9 +388,9 @@ public class ComputerPlayer4 extends ComputerPlayer<ComputerPlayer4> implements
|
||||||
sim.getPlayer(currentPlayer.getId()).pass();
|
sim.getPlayer(currentPlayer.getId()).pass();
|
||||||
sim.getPlayerList().getNext();
|
sim.getPlayerList().getNext();
|
||||||
}
|
}
|
||||||
SimulationNode newNode = new SimulationNode(sim, action, depth, currentPlayer.getId());
|
SimulationNode2 newNode = new SimulationNode2(sim, action, depth, currentPlayer.getId());
|
||||||
if (logger.isLoggable(Level.FINE))
|
if (logger.isLoggable(Level.FINE))
|
||||||
logger.fine("simulating -- node #:" + SimulationNode.getCount() + " actions:" + action);
|
logger.info("simulating -- node #:" + SimulationNode2.getCount() + " actions:" + action);
|
||||||
sim.checkStateAndTriggered();
|
sim.checkStateAndTriggered();
|
||||||
int val = addActions(newNode, filter, depth-1, alpha, beta);
|
int val = addActions(newNode, filter, depth-1, alpha, beta);
|
||||||
if (!currentPlayer.getId().equals(playerId)) {
|
if (!currentPlayer.getId().equals(playerId)) {
|
||||||
|
@ -410,11 +412,11 @@ public class ComputerPlayer4 extends ComputerPlayer<ComputerPlayer4> implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (alpha >= beta) {
|
if (alpha >= beta) {
|
||||||
logger.fine("simulating -- pruning");
|
//logger.info("simulating -- pruning");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (SimulationNode.nodeCount > maxNodes) {
|
if (SimulationNode2.nodeCount > maxNodes) {
|
||||||
logger.fine("simulating -- reached end-state");
|
logger.info("simulating -- reached end-state");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -424,11 +426,11 @@ public class ComputerPlayer4 extends ComputerPlayer<ComputerPlayer4> implements
|
||||||
node.children.add(bestNode);
|
node.children.add(bestNode);
|
||||||
}
|
}
|
||||||
if (!currentPlayer.getId().equals(playerId)) {
|
if (!currentPlayer.getId().equals(playerId)) {
|
||||||
logger.fine("returning priority beta: " + beta);
|
//logger.info("returning priority beta: " + beta);
|
||||||
return beta;
|
return beta;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
logger.fine("returning priority alpha: " + alpha);
|
//logger.info("returning priority alpha: " + alpha);
|
||||||
return alpha;
|
return alpha;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -492,7 +494,7 @@ public class ComputerPlayer4 extends ComputerPlayer<ComputerPlayer4> implements
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void playNext(Game game, UUID activePlayerId, SimulationNode node) {
|
public void playNext(Game game, UUID activePlayerId, SimulationNode2 node) {
|
||||||
boolean skip = false;
|
boolean skip = false;
|
||||||
while (true) {
|
while (true) {
|
||||||
Phase currentPhase = game.getPhase();
|
Phase currentPhase = game.getPhase();
|
||||||
|
@ -552,7 +554,7 @@ public class ComputerPlayer4 extends ComputerPlayer<ComputerPlayer4> implements
|
||||||
if (game.getTurn().getStepType() == PhaseStep.DECLARE_ATTACKERS) {
|
if (game.getTurn().getStepType() == PhaseStep.DECLARE_ATTACKERS) {
|
||||||
game.fireEvent(new GameEvent(GameEvent.EventType.DECLARE_ATTACKERS_STEP_PRE, null, null, activePlayerId));
|
game.fireEvent(new GameEvent(GameEvent.EventType.DECLARE_ATTACKERS_STEP_PRE, null, null, activePlayerId));
|
||||||
if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.DECLARING_ATTACKERS, activePlayerId, activePlayerId))) {
|
if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.DECLARING_ATTACKERS, activePlayerId, activePlayerId))) {
|
||||||
for (Combat engagement: ((SimulatedPlayer)game.getPlayer(activePlayerId)).addAttackers(game)) {
|
for (Combat engagement: ((SimulatedPlayer2)game.getPlayer(activePlayerId)).addAttackers(game)) {
|
||||||
Game sim = game.copy();
|
Game sim = game.copy();
|
||||||
UUID defenderId = game.getOpponents(playerId).iterator().next();
|
UUID defenderId = game.getOpponents(playerId).iterator().next();
|
||||||
for (CombatGroup group: engagement.getGroups()) {
|
for (CombatGroup group: engagement.getGroups()) {
|
||||||
|
@ -561,8 +563,8 @@ public class ComputerPlayer4 extends ComputerPlayer<ComputerPlayer4> implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARED_ATTACKERS, playerId, playerId));
|
sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARED_ATTACKERS, playerId, playerId));
|
||||||
SimulationNode newNode = new SimulationNode(sim, node.getDepth()-1, activePlayerId);
|
SimulationNode2 newNode = new SimulationNode2(sim, node.getDepth()-1, activePlayerId);
|
||||||
logger.fine("simulating -- node #:" + SimulationNode.getCount() + " declare attakers");
|
logger.info("simulating -- node #:" + SimulationNode2.getCount() + " declare attakers");
|
||||||
newNode.setCombat(sim.getCombat());
|
newNode.setCombat(sim.getCombat());
|
||||||
node.children.add(newNode);
|
node.children.add(newNode);
|
||||||
}
|
}
|
||||||
|
@ -574,7 +576,7 @@ public class ComputerPlayer4 extends ComputerPlayer<ComputerPlayer4> implements
|
||||||
for (UUID defenderId: game.getCombat().getDefenders()) {
|
for (UUID defenderId: game.getCombat().getDefenders()) {
|
||||||
//check if defender is being attacked
|
//check if defender is being attacked
|
||||||
if (game.getCombat().isAttacked(defenderId, game)) {
|
if (game.getCombat().isAttacked(defenderId, game)) {
|
||||||
for (Combat engagement: ((SimulatedPlayer)game.getPlayer(defenderId)).addBlockers(game)) {
|
for (Combat engagement: ((SimulatedPlayer2)game.getPlayer(defenderId)).addBlockers(game)) {
|
||||||
Game sim = game.copy();
|
Game sim = game.copy();
|
||||||
for (CombatGroup group: engagement.getGroups()) {
|
for (CombatGroup group: engagement.getGroups()) {
|
||||||
for (UUID blockerId: group.getBlockers()) {
|
for (UUID blockerId: group.getBlockers()) {
|
||||||
|
@ -582,8 +584,8 @@ public class ComputerPlayer4 extends ComputerPlayer<ComputerPlayer4> implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARED_BLOCKERS, playerId, playerId));
|
sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARED_BLOCKERS, playerId, playerId));
|
||||||
SimulationNode newNode = new SimulationNode(sim, node.getDepth()-1, defenderId);
|
SimulationNode2 newNode = new SimulationNode2(sim, node.getDepth()-1, defenderId);
|
||||||
logger.fine("simulating -- node #:" + SimulationNode.getCount() + " declare blockers");
|
logger.info("simulating -- node #:" + SimulationNode2.getCount() + " declare blockers");
|
||||||
newNode.setCombat(sim.getCombat());
|
newNode.setCombat(sim.getCombat());
|
||||||
node.children.add(newNode);
|
node.children.add(newNode);
|
||||||
}
|
}
|
||||||
|
@ -606,10 +608,11 @@ public class ComputerPlayer4 extends ComputerPlayer<ComputerPlayer4> implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void selectAttackers(Game game) {
|
public void selectAttackers(Game game) {
|
||||||
logger.fine("selectAttackers");
|
logger.info("selectAttackers");
|
||||||
if (combat != null) {
|
if (combat != null) {
|
||||||
UUID opponentId = game.getCombat().getDefenders().iterator().next();
|
UUID opponentId = game.getCombat().getDefenders().iterator().next();
|
||||||
for (UUID attackerId: combat.getAttackers()) {
|
for (UUID attackerId: combat.getAttackers()) {
|
||||||
|
logger.info("declare attacker: " + game.getCard(attackerId).getName());
|
||||||
this.declareAttacker(attackerId, opponentId, game);
|
this.declareAttacker(attackerId, opponentId, game);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -617,7 +620,7 @@ public class ComputerPlayer4 extends ComputerPlayer<ComputerPlayer4> implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void selectBlockers(Game game) {
|
public void selectBlockers(Game game) {
|
||||||
logger.fine("selectBlockers");
|
logger.info("selectBlockers");
|
||||||
if (combat != null && combat.getGroups().size() > 0) {
|
if (combat != null && combat.getGroups().size() > 0) {
|
||||||
List<CombatGroup> groups = game.getCombat().getGroups();
|
List<CombatGroup> groups = game.getCombat().getGroups();
|
||||||
for (int i = 0; i < groups.size(); i++) {
|
for (int i = 0; i < groups.size(); i++) {
|
||||||
|
@ -641,7 +644,7 @@ public class ComputerPlayer4 extends ComputerPlayer<ComputerPlayer4> implements
|
||||||
|
|
||||||
for (Player copyPlayer: sim.getState().getPlayers().values()) {
|
for (Player copyPlayer: sim.getState().getPlayers().values()) {
|
||||||
Player origPlayer = game.getState().getPlayers().get(copyPlayer.getId());
|
Player origPlayer = game.getState().getPlayers().get(copyPlayer.getId());
|
||||||
SimulatedPlayer newPlayer = new SimulatedPlayer(copyPlayer.getId(), copyPlayer.getId().equals(playerId));
|
SimulatedPlayer2 newPlayer = new SimulatedPlayer2(copyPlayer.getId(), copyPlayer.getId().equals(playerId));
|
||||||
newPlayer.restore(origPlayer);
|
newPlayer.restore(origPlayer);
|
||||||
sim.getState().getPlayers().put(copyPlayer.getId(), newPlayer);
|
sim.getState().getPlayers().put(copyPlayer.getId(), newPlayer);
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,11 +37,13 @@ import mage.Constants.PhaseStep;
|
||||||
import mage.Constants.RangeOfInfluence;
|
import mage.Constants.RangeOfInfluence;
|
||||||
import mage.Constants.Zone;
|
import mage.Constants.Zone;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
|
import mage.cards.Card;
|
||||||
import mage.filter.FilterAbility;
|
import mage.filter.FilterAbility;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.combat.Combat;
|
import mage.game.combat.Combat;
|
||||||
import mage.game.combat.CombatGroup;
|
import mage.game.combat.CombatGroup;
|
||||||
import mage.game.events.GameEvent;
|
import mage.game.events.GameEvent;
|
||||||
|
import mage.game.permanent.Permanent;
|
||||||
import mage.game.turn.BeginCombatStep;
|
import mage.game.turn.BeginCombatStep;
|
||||||
import mage.game.turn.BeginningPhase;
|
import mage.game.turn.BeginningPhase;
|
||||||
import mage.game.turn.CleanupStep;
|
import mage.game.turn.CleanupStep;
|
||||||
|
@ -80,12 +82,13 @@ public class ComputerPlayer5 extends ComputerPlayer4 implements Player {
|
||||||
filterNotLand.setZone(Zone.HAND);
|
filterNotLand.setZone(Zone.HAND);
|
||||||
filterNotLand.setNotFilter(true);
|
filterNotLand.setNotFilter(true);
|
||||||
|
|
||||||
|
logger.setLevel(Level.ALL);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ComputerPlayer5(String name, RangeOfInfluence range) {
|
public ComputerPlayer5(String name, RangeOfInfluence range) {
|
||||||
super(name, range);
|
super(name, range);
|
||||||
maxDepth = Config.maxDepth;
|
maxDepth = Config2.maxDepth;
|
||||||
maxNodes = Config.maxNodes;
|
maxNodes = Config2.maxNodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ComputerPlayer5(final ComputerPlayer5 player) {
|
public ComputerPlayer5(final ComputerPlayer5 player) {
|
||||||
|
@ -108,7 +111,22 @@ public class ComputerPlayer5 extends ComputerPlayer4 implements Player {
|
||||||
break;
|
break;
|
||||||
case PRECOMBAT_MAIN:
|
case PRECOMBAT_MAIN:
|
||||||
if (game.getActivePlayerId().equals(playerId)) {
|
if (game.getActivePlayerId().equals(playerId)) {
|
||||||
System.out.println("["+ game.getPlayer(playerId).getName() + "] Precombat Main, life=" + game.getPlayer(playerId).getLife());
|
Player player = game.getPlayer(playerId);
|
||||||
|
System.out.println("[" + game.getPlayer(playerId).getName() + "] Precombat Main, life=" + player.getLife());
|
||||||
|
String s = "[";
|
||||||
|
for (Card card : player.getHand().getCards(game)) {
|
||||||
|
s += card.getName() + ";";
|
||||||
|
}
|
||||||
|
s += "]";
|
||||||
|
System.out.println("Hand: " + s);
|
||||||
|
s = "[";
|
||||||
|
for (Permanent permanent : game.getBattlefield().getAllPermanents()) {
|
||||||
|
if (permanent.getOwnerId().equals(player.getId())) {
|
||||||
|
s += permanent.getName() + ";";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
s += "]";
|
||||||
|
System.out.println("Permanents: " + s);
|
||||||
if (actions.size() == 0) {
|
if (actions.size() == 0) {
|
||||||
calculatePreCombatActions(game);
|
calculatePreCombatActions(game);
|
||||||
}
|
}
|
||||||
|
@ -154,10 +172,10 @@ public class ComputerPlayer5 extends ComputerPlayer4 implements Player {
|
||||||
|
|
||||||
protected void calculatePreCombatActions(Game game) {
|
protected void calculatePreCombatActions(Game game) {
|
||||||
if (!getNextAction(game)) {
|
if (!getNextAction(game)) {
|
||||||
currentScore = GameStateEvaluator.evaluate(playerId, game);
|
currentScore = GameStateEvaluator2.evaluate(playerId, game);
|
||||||
Game sim = createSimulation(game);
|
Game sim = createSimulation(game);
|
||||||
SimulationNode.resetCount();
|
SimulationNode2.resetCount();
|
||||||
root = new SimulationNode(sim, maxDepth, playerId);
|
root = new SimulationNode2(sim, maxDepth, playerId);
|
||||||
logger.fine("simulating pre combat actions -----------------------------------------------------------------------------------------");
|
logger.fine("simulating pre combat actions -----------------------------------------------------------------------------------------");
|
||||||
|
|
||||||
addActionsTimed(new FilterAbility());
|
addActionsTimed(new FilterAbility());
|
||||||
|
@ -171,10 +189,10 @@ public class ComputerPlayer5 extends ComputerPlayer4 implements Player {
|
||||||
|
|
||||||
protected void calculatePostCombatActions(Game game) {
|
protected void calculatePostCombatActions(Game game) {
|
||||||
if (!getNextAction(game)) {
|
if (!getNextAction(game)) {
|
||||||
currentScore = GameStateEvaluator.evaluate(playerId, game);
|
currentScore = GameStateEvaluator2.evaluate(playerId, game);
|
||||||
Game sim = createSimulation(game);
|
Game sim = createSimulation(game);
|
||||||
SimulationNode.resetCount();
|
SimulationNode2.resetCount();
|
||||||
root = new SimulationNode(sim, maxDepth, playerId);
|
root = new SimulationNode2(sim, maxDepth, playerId);
|
||||||
logger.fine("simulating post combat actions ----------------------------------------------------------------------------------------");
|
logger.fine("simulating post combat actions ----------------------------------------------------------------------------------------");
|
||||||
addActionsTimed(new FilterAbility());
|
addActionsTimed(new FilterAbility());
|
||||||
if (root.children.size() > 0) {
|
if (root.children.size() > 0) {
|
||||||
|
@ -186,18 +204,18 @@ public class ComputerPlayer5 extends ComputerPlayer4 implements Player {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int addActions(SimulationNode node, FilterAbility filter, int depth, int alpha, int beta) {
|
protected int addActions(SimulationNode2 node, FilterAbility filter, int depth, int alpha, int beta) {
|
||||||
boolean stepFinished = false;
|
boolean stepFinished = false;
|
||||||
int val;
|
int val;
|
||||||
Game game = node.getGame();
|
Game game = node.getGame();
|
||||||
if (Thread.interrupted()) {
|
if (Thread.interrupted()) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
logger.fine("interrupted");
|
logger.fine("interrupted");
|
||||||
return GameStateEvaluator.evaluate(playerId, game);
|
return GameStateEvaluator2.evaluate(playerId, game);
|
||||||
}
|
}
|
||||||
if (depth <= 0 || SimulationNode.nodeCount > maxNodes || game.isGameOver()) {
|
if (depth <= 0 || SimulationNode2.nodeCount > maxNodes || game.isGameOver()) {
|
||||||
logger.fine("simulating -- reached end state");
|
logger.fine("simulating -- reached end state");
|
||||||
val = GameStateEvaluator.evaluate(playerId, game);
|
val = GameStateEvaluator2.evaluate(playerId, game);
|
||||||
}
|
}
|
||||||
else if (node.getChildren().size() > 0) {
|
else if (node.getChildren().size() > 0) {
|
||||||
logger.fine("simulating -- somthing added children:" + node.getChildren().size());
|
logger.fine("simulating -- somthing added children:" + node.getChildren().size());
|
||||||
|
@ -216,11 +234,11 @@ public class ComputerPlayer5 extends ComputerPlayer4 implements Player {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (game.isGameOver()) {
|
if (game.isGameOver()) {
|
||||||
val = GameStateEvaluator.evaluate(playerId, game);
|
val = GameStateEvaluator2.evaluate(playerId, game);
|
||||||
}
|
}
|
||||||
else if (stepFinished) {
|
else if (stepFinished) {
|
||||||
logger.fine("step finished");
|
logger.fine("step finished");
|
||||||
int testScore = GameStateEvaluator.evaluate(playerId, game);
|
int testScore = GameStateEvaluator2.evaluate(playerId, game);
|
||||||
if (game.getActivePlayerId().equals(playerId)) {
|
if (game.getActivePlayerId().equals(playerId)) {
|
||||||
if (testScore < currentScore) {
|
if (testScore < currentScore) {
|
||||||
// if score at end of step is worse than original score don't check further
|
// if score at end of step is worse than original score don't check further
|
||||||
|
@ -236,7 +254,7 @@ public class ComputerPlayer5 extends ComputerPlayer4 implements Player {
|
||||||
val = -simulateCounterAttack(game, node, depth-1, alpha, beta);
|
val = -simulateCounterAttack(game, node, depth-1, alpha, beta);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
val = -GameStateEvaluator.evaluate(playerId, game);
|
val = -GameStateEvaluator2.evaluate(playerId, game);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -245,7 +263,7 @@ public class ComputerPlayer5 extends ComputerPlayer4 implements Player {
|
||||||
if (game.getTurn().getStepType() == PhaseStep.DECLARE_ATTACKERS)
|
if (game.getTurn().getStepType() == PhaseStep.DECLARE_ATTACKERS)
|
||||||
val = simulateBlockers(game, node, playerId, depth-1, alpha, beta, true);
|
val = simulateBlockers(game, node, playerId, depth-1, alpha, beta, true);
|
||||||
else
|
else
|
||||||
val = GameStateEvaluator.evaluate(playerId, game);
|
val = GameStateEvaluator2.evaluate(playerId, game);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (node.getChildren().size() > 0) {
|
else if (node.getChildren().size() > 0) {
|
||||||
|
@ -263,12 +281,12 @@ public class ComputerPlayer5 extends ComputerPlayer4 implements Player {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int simulateCombat(Game game, SimulationNode node, int depth, int alpha, int beta, boolean counter) {
|
protected int simulateCombat(Game game, SimulationNode2 node, int depth, int alpha, int beta, boolean counter) {
|
||||||
Integer val = null;
|
Integer val = null;
|
||||||
if (Thread.interrupted()) {
|
if (Thread.interrupted()) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
logger.fine("interrupted");
|
logger.fine("interrupted");
|
||||||
return GameStateEvaluator.evaluate(playerId, game);
|
return GameStateEvaluator2.evaluate(playerId, game);
|
||||||
}
|
}
|
||||||
if (game.getTurn().getStepType() != PhaseStep.DECLARE_BLOCKERS) {
|
if (game.getTurn().getStepType() != PhaseStep.DECLARE_BLOCKERS) {
|
||||||
game.getTurn().setPhase(new CombatPhase());
|
game.getTurn().setPhase(new CombatPhase());
|
||||||
|
@ -297,31 +315,31 @@ public class ComputerPlayer5 extends ComputerPlayer4 implements Player {
|
||||||
}
|
}
|
||||||
else if (!counter) {
|
else if (!counter) {
|
||||||
finishCombat(game);
|
finishCombat(game);
|
||||||
val = GameStateEvaluator.evaluate(playerId, game);
|
val = GameStateEvaluator2.evaluate(playerId, game);
|
||||||
// val = simulateCounterAttack(game, node, depth, alpha, beta);
|
// val = simulateCounterAttack(game, node, depth, alpha, beta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (val == null)
|
if (val == null)
|
||||||
val = GameStateEvaluator.evaluate(playerId, game);
|
val = GameStateEvaluator2.evaluate(playerId, game);
|
||||||
if (logger.isLoggable(Level.FINE))
|
if (logger.isLoggable(Level.FINE))
|
||||||
logger.fine("returning -- combat score: " + val + " depth:" + depth + " for player:" + game.getPlayer(node.getPlayerId()).getName());
|
logger.fine("returning -- combat score: " + val + " depth:" + depth + " for player:" + game.getPlayer(node.getPlayerId()).getName());
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected int simulateAttackers(Game game, SimulationNode node, UUID attackerId, int depth, int alpha, int beta, boolean counter) {
|
protected int simulateAttackers(Game game, SimulationNode2 node, UUID attackerId, int depth, int alpha, int beta, boolean counter) {
|
||||||
if (Thread.interrupted()) {
|
if (Thread.interrupted()) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
logger.fine("interrupted");
|
logger.fine("interrupted");
|
||||||
return GameStateEvaluator.evaluate(playerId, game);
|
return GameStateEvaluator2.evaluate(playerId, game);
|
||||||
}
|
}
|
||||||
Integer val = null;
|
Integer val = null;
|
||||||
SimulationNode bestNode = null;
|
SimulationNode2 bestNode = null;
|
||||||
SimulatedPlayer attacker = (SimulatedPlayer) game.getPlayer(attackerId);
|
SimulatedPlayer2 attacker = (SimulatedPlayer2) game.getPlayer(attackerId);
|
||||||
|
|
||||||
for (Combat engagement: attacker.addAttackers(game)) {
|
for (Combat engagement: attacker.addAttackers(game)) {
|
||||||
if (alpha >= beta) {
|
if (alpha >= beta) {
|
||||||
logger.fine("simulating -- pruning attackers");
|
//logger.fine("simulating -- pruning attackers");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Game sim = game.copy();
|
Game sim = game.copy();
|
||||||
|
@ -332,9 +350,9 @@ public class ComputerPlayer5 extends ComputerPlayer4 implements Player {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARED_ATTACKERS, playerId, playerId));
|
sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARED_ATTACKERS, playerId, playerId));
|
||||||
SimulationNode newNode = new SimulationNode(sim, depth, game.getActivePlayerId());
|
SimulationNode2 newNode = new SimulationNode2(sim, depth, game.getActivePlayerId());
|
||||||
if (logger.isLoggable(Level.FINE))
|
if (logger.isLoggable(Level.FINE))
|
||||||
logger.fine("simulating attack -- node#: " + SimulationNode.getCount());
|
logger.fine("simulating attack -- node#: " + SimulationNode2.getCount());
|
||||||
sim.checkStateAndTriggered();
|
sim.checkStateAndTriggered();
|
||||||
while (!sim.getStack().isEmpty()) {
|
while (!sim.getStack().isEmpty()) {
|
||||||
sim.getStack().resolve(sim);
|
sim.getStack().resolve(sim);
|
||||||
|
@ -361,7 +379,7 @@ public class ComputerPlayer5 extends ComputerPlayer4 implements Player {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (val == null)
|
if (val == null)
|
||||||
val = GameStateEvaluator.evaluate(playerId, game);
|
val = GameStateEvaluator2.evaluate(playerId, game);
|
||||||
if (bestNode != null) {
|
if (bestNode != null) {
|
||||||
node.children.clear();
|
node.children.clear();
|
||||||
node.children.add(bestNode);
|
node.children.add(bestNode);
|
||||||
|
@ -371,17 +389,17 @@ public class ComputerPlayer5 extends ComputerPlayer4 implements Player {
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int simulateBlockers(Game game, SimulationNode node, UUID defenderId, int depth, int alpha, int beta, boolean counter) {
|
protected int simulateBlockers(Game game, SimulationNode2 node, UUID defenderId, int depth, int alpha, int beta, boolean counter) {
|
||||||
if (Thread.interrupted()) {
|
if (Thread.interrupted()) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
logger.fine("interrupted");
|
logger.fine("interrupted");
|
||||||
return GameStateEvaluator.evaluate(playerId, game);
|
return GameStateEvaluator2.evaluate(playerId, game);
|
||||||
}
|
}
|
||||||
Integer val = null;
|
Integer val = null;
|
||||||
SimulationNode bestNode = null;
|
SimulationNode2 bestNode = null;
|
||||||
//check if defender is being attacked
|
//check if defender is being attacked
|
||||||
if (game.getCombat().isAttacked(defenderId, game)) {
|
if (game.getCombat().isAttacked(defenderId, game)) {
|
||||||
SimulatedPlayer defender = (SimulatedPlayer) game.getPlayer(defenderId);
|
SimulatedPlayer2 defender = (SimulatedPlayer2) game.getPlayer(defenderId);
|
||||||
for (Combat engagement: defender.addBlockers(game)) {
|
for (Combat engagement: defender.addBlockers(game)) {
|
||||||
if (alpha >= beta) {
|
if (alpha >= beta) {
|
||||||
logger.fine("simulating -- pruning blockers");
|
logger.fine("simulating -- pruning blockers");
|
||||||
|
@ -395,9 +413,9 @@ public class ComputerPlayer5 extends ComputerPlayer4 implements Player {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARED_BLOCKERS, playerId, playerId));
|
sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARED_BLOCKERS, playerId, playerId));
|
||||||
SimulationNode newNode = new SimulationNode(sim, depth, defenderId);
|
SimulationNode2 newNode = new SimulationNode2(sim, depth, defenderId);
|
||||||
if (logger.isLoggable(Level.FINE))
|
if (logger.isLoggable(Level.FINE))
|
||||||
logger.fine("simulating block -- node#: " + SimulationNode.getCount());
|
logger.fine("simulating block -- node#: " + SimulationNode2.getCount());
|
||||||
sim.checkStateAndTriggered();
|
sim.checkStateAndTriggered();
|
||||||
while (!sim.getStack().isEmpty()) {
|
while (!sim.getStack().isEmpty()) {
|
||||||
sim.getStack().resolve(sim);
|
sim.getStack().resolve(sim);
|
||||||
|
@ -408,13 +426,13 @@ public class ComputerPlayer5 extends ComputerPlayer4 implements Player {
|
||||||
Combat simCombat = sim.getCombat().copy();
|
Combat simCombat = sim.getCombat().copy();
|
||||||
finishCombat(sim);
|
finishCombat(sim);
|
||||||
if (sim.isGameOver()) {
|
if (sim.isGameOver()) {
|
||||||
val = GameStateEvaluator.evaluate(playerId, sim);
|
val = GameStateEvaluator2.evaluate(playerId, sim);
|
||||||
}
|
}
|
||||||
else if (!counter) {
|
else if (!counter) {
|
||||||
val = simulatePostCombatMain(sim, newNode, depth-1, alpha, beta);
|
val = simulatePostCombatMain(sim, newNode, depth-1, alpha, beta);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
val = GameStateEvaluator.evaluate(playerId, sim);
|
val = GameStateEvaluator2.evaluate(playerId, sim);
|
||||||
if (!defenderId.equals(playerId)) {
|
if (!defenderId.equals(playerId)) {
|
||||||
if (val < beta) {
|
if (val < beta) {
|
||||||
beta = val;
|
beta = val;
|
||||||
|
@ -432,7 +450,7 @@ public class ComputerPlayer5 extends ComputerPlayer4 implements Player {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (val == null)
|
if (val == null)
|
||||||
val = GameStateEvaluator.evaluate(playerId, game);
|
val = GameStateEvaluator2.evaluate(playerId, game);
|
||||||
if (bestNode != null) {
|
if (bestNode != null) {
|
||||||
node.children.clear();
|
node.children.clear();
|
||||||
node.children.add(bestNode);
|
node.children.add(bestNode);
|
||||||
|
@ -442,11 +460,11 @@ public class ComputerPlayer5 extends ComputerPlayer4 implements Player {
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int simulateCounterAttack(Game game, SimulationNode node, int depth, int alpha, int beta) {
|
protected int simulateCounterAttack(Game game, SimulationNode2 node, int depth, int alpha, int beta) {
|
||||||
if (Thread.interrupted()) {
|
if (Thread.interrupted()) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
logger.fine("interrupted");
|
logger.fine("interrupted");
|
||||||
return GameStateEvaluator.evaluate(playerId, game);
|
return GameStateEvaluator2.evaluate(playerId, game);
|
||||||
}
|
}
|
||||||
Integer val = null;
|
Integer val = null;
|
||||||
if (!game.isGameOver()) {
|
if (!game.isGameOver()) {
|
||||||
|
@ -465,7 +483,7 @@ public class ComputerPlayer5 extends ComputerPlayer4 implements Player {
|
||||||
logger.fine("returning -- counter attack score: " + val + " depth:" + depth + " for player:" + game.getPlayer(node.getPlayerId()).getName());
|
logger.fine("returning -- counter attack score: " + val + " depth:" + depth + " for player:" + game.getPlayer(node.getPlayerId()).getName());
|
||||||
}
|
}
|
||||||
if (val == null)
|
if (val == null)
|
||||||
val = GameStateEvaluator.evaluate(playerId, game);
|
val = GameStateEvaluator2.evaluate(playerId, game);
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -500,11 +518,11 @@ public class ComputerPlayer5 extends ComputerPlayer4 implements Player {
|
||||||
simulateStep(game, new EndOfCombatStep());
|
simulateStep(game, new EndOfCombatStep());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int simulatePostCombatMain(Game game, SimulationNode node, int depth, int alpha, int beta) {
|
protected int simulatePostCombatMain(Game game, SimulationNode2 node, int depth, int alpha, int beta) {
|
||||||
if (Thread.interrupted()) {
|
if (Thread.interrupted()) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
logger.fine("interrupted");
|
logger.fine("interrupted");
|
||||||
return GameStateEvaluator.evaluate(playerId, game);
|
return GameStateEvaluator2.evaluate(playerId, game);
|
||||||
}
|
}
|
||||||
logger.fine("simulating -- post combat main");
|
logger.fine("simulating -- post combat main");
|
||||||
game.getTurn().setPhase(new PostCombatMainPhase());
|
game.getTurn().setPhase(new PostCombatMainPhase());
|
||||||
|
|
|
@ -41,9 +41,9 @@ import mage.util.Logging;
|
||||||
*
|
*
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
*/
|
*/
|
||||||
public class Config {
|
public class Config2 {
|
||||||
|
|
||||||
private final static Logger logger = Logging.getLogger(Config.class.getName());
|
private final static Logger logger = Logging.getLogger(Config2.class.getName());
|
||||||
|
|
||||||
public static final int maxDepth;
|
public static final int maxDepth;
|
||||||
public static final int maxNodes;
|
public static final int maxNodes;
|
||||||
|
@ -56,12 +56,12 @@ public class Config {
|
||||||
static {
|
static {
|
||||||
Properties p = new Properties();
|
Properties p = new Properties();
|
||||||
try {
|
try {
|
||||||
File file = new File(Config.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
|
File file = new File(Config2.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
|
||||||
p.load(new FileInputStream(new File(file.getParent() + File.separator + "AIMinimax.properties")));
|
p.load(new FileInputStream(new File(file.getParent() + File.separator + "AIMinimax.properties")));
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
logger.log(Level.SEVERE, null, ex);
|
logger.log(Level.SEVERE, null, ex);
|
||||||
} catch (URISyntaxException ex) {
|
} catch (URISyntaxException ex) {
|
||||||
Logger.getLogger(Config.class.getName()).log(Level.SEVERE, null, ex);
|
Logger.getLogger(Config2.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
}
|
}
|
||||||
maxDepth = Integer.parseInt(p.getProperty("maxDepth"));
|
maxDepth = Integer.parseInt(p.getProperty("maxDepth"));
|
||||||
maxNodes = Integer.parseInt(p.getProperty("maxNodes"));
|
maxNodes = Integer.parseInt(p.getProperty("maxNodes"));
|
|
@ -8,13 +8,7 @@ package mage.player.ai;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import mage.Constants.CardType;
|
|
||||||
import mage.Constants.Zone;
|
|
||||||
import mage.abilities.ActivatedAbility;
|
|
||||||
import mage.abilities.keyword.DoubleStrikeAbility;
|
|
||||||
import mage.abilities.keyword.FirstStrikeAbility;
|
|
||||||
import mage.abilities.keyword.TrampleAbility;
|
|
||||||
import mage.abilities.mana.ManaAbility;
|
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.permanent.Permanent;
|
import mage.game.permanent.Permanent;
|
||||||
import mage.player.ai.ma.ArtificialScoringSystem;
|
import mage.player.ai.ma.ArtificialScoringSystem;
|
||||||
|
@ -28,9 +22,9 @@ import mage.util.Logging;
|
||||||
* this evaluator is only good for two player games
|
* this evaluator is only good for two player games
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class GameStateEvaluator {
|
public class GameStateEvaluator2 {
|
||||||
|
|
||||||
private final static transient Logger logger = Logging.getLogger(GameStateEvaluator.class.getName());
|
private final static transient Logger logger = Logging.getLogger(GameStateEvaluator2.class.getName());
|
||||||
|
|
||||||
static {
|
static {
|
||||||
logger.setLevel(Level.ALL);
|
logger.setLevel(Level.ALL);
|
||||||
|
@ -40,10 +34,10 @@ public class GameStateEvaluator {
|
||||||
public static final int LOSE_GAME_SCORE = -WIN_GAME_SCORE;
|
public static final int LOSE_GAME_SCORE = -WIN_GAME_SCORE;
|
||||||
|
|
||||||
|
|
||||||
private static final int LIFE_FACTOR = Config.evaluatorLifeFactor;
|
private static final int LIFE_FACTOR = Config2.evaluatorLifeFactor;
|
||||||
private static final int PERMANENT_FACTOR = Config.evaluatorPermanentFactor;
|
private static final int PERMANENT_FACTOR = Config2.evaluatorPermanentFactor;
|
||||||
private static final int CREATURE_FACTOR = Config.evaluatorCreatureFactor;
|
private static final int CREATURE_FACTOR = Config2.evaluatorCreatureFactor;
|
||||||
private static final int HAND_FACTOR = Config.evaluatorHandFactor;
|
private static final int HAND_FACTOR = Config2.evaluatorHandFactor;
|
||||||
|
|
||||||
public static int evaluate(UUID playerId, Game game) {
|
public static int evaluate(UUID playerId, Game game) {
|
||||||
Player player = game.getPlayer(playerId);
|
Player player = game.getPlayer(playerId);
|
|
@ -38,14 +38,14 @@ import mage.util.Logging;
|
||||||
*
|
*
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
*/
|
*/
|
||||||
public class SimulateBlockWorker implements Callable {
|
public class SimulateBlockWorker2 implements Callable {
|
||||||
|
|
||||||
private final static Logger logger = Logging.getLogger(SimulationWorker.class.getName());
|
private final static Logger logger = Logging.getLogger(SimulationWorker2.class.getName());
|
||||||
|
|
||||||
private SimulationNode node;
|
private SimulationNode2 node;
|
||||||
private ComputerPlayer5 player;
|
private ComputerPlayer5 player;
|
||||||
|
|
||||||
public SimulateBlockWorker(ComputerPlayer5 player, SimulationNode node) {
|
public SimulateBlockWorker2(ComputerPlayer5 player, SimulationNode2 node) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.node = node;
|
this.node = node;
|
||||||
}
|
}
|
|
@ -36,12 +36,12 @@ import mage.game.Game;
|
||||||
*
|
*
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
*/
|
*/
|
||||||
public class SimulatedAction {
|
public class SimulatedAction2 {
|
||||||
|
|
||||||
private Game game;
|
private Game game;
|
||||||
private List<Ability> abilities;
|
private List<Ability> abilities;
|
||||||
|
|
||||||
public SimulatedAction(Game game, List<Ability> abilities) {
|
public SimulatedAction2(Game game, List<Ability> abilities) {
|
||||||
this.game = game;
|
this.game = game;
|
||||||
this.abilities = abilities;
|
this.abilities = abilities;
|
||||||
}
|
}
|
|
@ -31,18 +31,13 @@ package mage.player.ai;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
import java.util.concurrent.ExecutorService;
|
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.abilities.ActivatedAbility;
|
|
||||||
import mage.abilities.TriggeredAbility;
|
import mage.abilities.TriggeredAbility;
|
||||||
import mage.abilities.common.PassAbility;
|
import mage.abilities.common.PassAbility;
|
||||||
import mage.abilities.mana.ManaOptions;
|
import mage.abilities.mana.ManaOptions;
|
||||||
|
@ -54,28 +49,27 @@ import mage.game.events.GameEvent;
|
||||||
import mage.game.permanent.Permanent;
|
import mage.game.permanent.Permanent;
|
||||||
import mage.game.stack.StackAbility;
|
import mage.game.stack.StackAbility;
|
||||||
import mage.target.Target;
|
import mage.target.Target;
|
||||||
import mage.util.Copier;
|
|
||||||
import mage.util.Logging;
|
import mage.util.Logging;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
*/
|
*/
|
||||||
public class SimulatedPlayer extends ComputerPlayer<SimulatedPlayer> {
|
public class SimulatedPlayer2 extends ComputerPlayer<SimulatedPlayer2> {
|
||||||
|
|
||||||
private final static transient Logger logger = Logging.getLogger(SimulatedPlayer.class.getName());
|
private final static transient Logger logger = Logging.getLogger(SimulatedPlayer2.class.getName());
|
||||||
private boolean isSimulatedPlayer;
|
private boolean isSimulatedPlayer;
|
||||||
private FilterAbility filter;
|
private FilterAbility filter;
|
||||||
private transient ConcurrentLinkedQueue<Ability> allActions;
|
private transient ConcurrentLinkedQueue<Ability> allActions;
|
||||||
private static PassAbility pass = new PassAbility();
|
private static PassAbility pass = new PassAbility();
|
||||||
|
|
||||||
public SimulatedPlayer(UUID id, boolean isSimulatedPlayer) {
|
public SimulatedPlayer2(UUID id, boolean isSimulatedPlayer) {
|
||||||
super(id);
|
super(id);
|
||||||
pass.setControllerId(playerId);
|
pass.setControllerId(playerId);
|
||||||
this.isSimulatedPlayer = isSimulatedPlayer;
|
this.isSimulatedPlayer = isSimulatedPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SimulatedPlayer(final SimulatedPlayer player) {
|
public SimulatedPlayer2(final SimulatedPlayer2 player) {
|
||||||
super(player);
|
super(player);
|
||||||
this.isSimulatedPlayer = player.isSimulatedPlayer;
|
this.isSimulatedPlayer = player.isSimulatedPlayer;
|
||||||
if (player.filter != null)
|
if (player.filter != null)
|
||||||
|
@ -83,8 +77,8 @@ public class SimulatedPlayer extends ComputerPlayer<SimulatedPlayer> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SimulatedPlayer copy() {
|
public SimulatedPlayer2 copy() {
|
||||||
return new SimulatedPlayer(this);
|
return new SimulatedPlayer2(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Ability> simulatePriority(Game game, FilterAbility filter) {
|
public List<Ability> simulatePriority(Game game, FilterAbility filter) {
|
||||||
|
@ -213,7 +207,7 @@ public class SimulatedPlayer extends ComputerPlayer<SimulatedPlayer> {
|
||||||
game.getPlayers().resetPassed();
|
game.getPlayers().resetPassed();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
SimulationNode parent = (SimulationNode) game.getCustomData();
|
SimulationNode2 parent = (SimulationNode2) game.getCustomData();
|
||||||
int depth = parent.getDepth() - 1;
|
int depth = parent.getDepth() - 1;
|
||||||
if (depth == 0) return true;
|
if (depth == 0) return true;
|
||||||
logger.fine("simulating -- triggered ability - adding children:" + options.size());
|
logger.fine("simulating -- triggered ability - adding children:" + options.size());
|
||||||
|
@ -224,13 +218,13 @@ public class SimulatedPlayer extends ComputerPlayer<SimulatedPlayer> {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void addAbilityNode(SimulationNode parent, Ability ability, int depth, Game game) {
|
protected void addAbilityNode(SimulationNode2 parent, Ability ability, int depth, Game game) {
|
||||||
Game sim = game.copy();
|
Game sim = game.copy();
|
||||||
sim.getStack().push(new StackAbility(ability, playerId));
|
sim.getStack().push(new StackAbility(ability, playerId));
|
||||||
ability.activate(sim, false);
|
ability.activate(sim, false);
|
||||||
sim.applyEffects();
|
sim.applyEffects();
|
||||||
SimulationNode newNode = new SimulationNode(sim, depth, playerId);
|
SimulationNode2 newNode = new SimulationNode2(sim, depth, playerId);
|
||||||
logger.fine("simulating -- node #:" + SimulationNode.getCount() + " triggered ability option");
|
logger.fine("simulating -- node #:" + SimulationNode2.getCount() + " triggered ability option");
|
||||||
for (Target target: ability.getTargets()) {
|
for (Target target: ability.getTargets()) {
|
||||||
for (UUID targetId: target.getTargets()) {
|
for (UUID targetId: target.getTargets()) {
|
||||||
newNode.getTargets().add(targetId);
|
newNode.getTargets().add(targetId);
|
|
@ -40,7 +40,7 @@ import mage.game.combat.Combat;
|
||||||
*
|
*
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
*/
|
*/
|
||||||
public class SimulationNode implements Serializable {
|
public class SimulationNode2 implements Serializable {
|
||||||
|
|
||||||
protected static int nodeCount;
|
protected static int nodeCount;
|
||||||
|
|
||||||
|
@ -48,13 +48,13 @@ public class SimulationNode implements Serializable {
|
||||||
protected int gameValue;
|
protected int gameValue;
|
||||||
protected List<Ability> abilities;
|
protected List<Ability> abilities;
|
||||||
protected int depth;
|
protected int depth;
|
||||||
protected List<SimulationNode> children = new ArrayList<SimulationNode>();
|
protected List<SimulationNode2> children = new ArrayList<SimulationNode2>();
|
||||||
protected List<UUID> targets = new ArrayList<UUID>();
|
protected List<UUID> targets = new ArrayList<UUID>();
|
||||||
protected List<String> choices = new ArrayList<String>();
|
protected List<String> choices = new ArrayList<String>();
|
||||||
protected UUID playerId;
|
protected UUID playerId;
|
||||||
protected Combat combat;
|
protected Combat combat;
|
||||||
|
|
||||||
public SimulationNode(Game game, int depth, UUID playerId) {
|
public SimulationNode2(Game game, int depth, UUID playerId) {
|
||||||
this.game = game;
|
this.game = game;
|
||||||
this.depth = depth;
|
this.depth = depth;
|
||||||
this.playerId = playerId;
|
this.playerId = playerId;
|
||||||
|
@ -62,12 +62,12 @@ public class SimulationNode implements Serializable {
|
||||||
nodeCount++;
|
nodeCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SimulationNode(Game game, List<Ability> abilities, int depth, UUID playerId) {
|
public SimulationNode2(Game game, List<Ability> abilities, int depth, UUID playerId) {
|
||||||
this(game, depth, playerId);
|
this(game, depth, playerId);
|
||||||
this.abilities = abilities;
|
this.abilities = abilities;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SimulationNode(Game game, Ability ability, int depth, UUID playerId) {
|
public SimulationNode2(Game game, Ability ability, int depth, UUID playerId) {
|
||||||
this(game, depth, playerId);
|
this(game, depth, playerId);
|
||||||
this.abilities = new ArrayList<Ability>();
|
this.abilities = new ArrayList<Ability>();
|
||||||
abilities.add(ability);
|
abilities.add(ability);
|
||||||
|
@ -97,7 +97,7 @@ public class SimulationNode implements Serializable {
|
||||||
return this.abilities;
|
return this.abilities;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SimulationNode> getChildren() {
|
public List<SimulationNode2> getChildren() {
|
||||||
return this.children;
|
return this.children;
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,16 +39,16 @@ import mage.util.Logging;
|
||||||
*
|
*
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
*/
|
*/
|
||||||
public class SimulationWorker implements Callable {
|
public class SimulationWorker2 implements Callable {
|
||||||
|
|
||||||
private final static Logger logger = Logging.getLogger(SimulationWorker.class.getName());
|
private final static Logger logger = Logging.getLogger(SimulationWorker2.class.getName());
|
||||||
|
|
||||||
private Game game;
|
private Game game;
|
||||||
private SimulatedAction previousActions;
|
private SimulatedAction2 previousActions;
|
||||||
private Ability action;
|
private Ability action;
|
||||||
private SimulatedPlayer player;
|
private SimulatedPlayer2 player;
|
||||||
|
|
||||||
public SimulationWorker(Game game, SimulatedPlayer player, SimulatedAction previousActions, Ability action) {
|
public SimulationWorker2(Game game, SimulatedPlayer2 player, SimulatedAction2 previousActions, Ability action) {
|
||||||
this.game = game;
|
this.game = game;
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.previousActions = previousActions;
|
this.previousActions = previousActions;
|
|
@ -1,5 +1,5 @@
|
||||||
# Default global logging level.
|
# Default global logging level.
|
||||||
.level=FINER
|
.level=ALL
|
||||||
|
|
||||||
# Set the default logging level for new ConsoleHandler instances
|
# Set the default logging level for new ConsoleHandler instances
|
||||||
java.util.logging.ConsoleHandler.level = ALL
|
java.util.logging.ConsoleHandler.level = ALL
|
Binary file not shown.
Loading…
Reference in a new issue