mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +00:00
fixed canTarget error and started to convert logging to log4j
This commit is contained in:
parent
c8fcc25ba2
commit
0c5261ce88
10 changed files with 137 additions and 141 deletions
|
@ -280,7 +280,7 @@ public class ComputerPlayer<T extends ComputerPlayer<T>> extends PlayerImpl<T> i
|
||||||
targets = threats(opponentId, ((FilterCreatureOrPlayer)t.getFilter()).getCreatureFilter(), game);
|
targets = threats(opponentId, ((FilterCreatureOrPlayer)t.getFilter()).getCreatureFilter(), game);
|
||||||
}
|
}
|
||||||
for (Permanent permanent: targets) {
|
for (Permanent permanent: targets) {
|
||||||
if (((TargetPermanent)target).canTarget(playerId, permanent.getId(), source, game)) {
|
if (t.canTarget(playerId, permanent.getId(), source, game)) {
|
||||||
target.addTarget(permanent.getId(), source, game);
|
target.addTarget(permanent.getId(), source, game);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,12 @@
|
||||||
<name>Mage Player AI Minimax</name>
|
<name>Mage Player AI Minimax</name>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>log4j</groupId>
|
||||||
|
<artifactId>log4j</artifactId>
|
||||||
|
<version>1.2.14</version>
|
||||||
|
<type>jar</type>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>${project.groupId}</groupId>
|
<groupId>${project.groupId}</groupId>
|
||||||
<artifactId>Mage</artifactId>
|
<artifactId>Mage</artifactId>
|
||||||
|
|
|
@ -39,8 +39,6 @@ import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.FutureTask;
|
import java.util.concurrent.FutureTask;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
import mage.Constants.Outcome;
|
import mage.Constants.Outcome;
|
||||||
import mage.Constants.PhaseStep;
|
import mage.Constants.PhaseStep;
|
||||||
import mage.Constants.RangeOfInfluence;
|
import mage.Constants.RangeOfInfluence;
|
||||||
|
@ -79,7 +77,7 @@ import mage.game.turn.UpkeepStep;
|
||||||
import mage.players.Player;
|
import mage.players.Player;
|
||||||
import mage.target.Target;
|
import mage.target.Target;
|
||||||
import mage.target.TargetCard;
|
import mage.target.TargetCard;
|
||||||
import mage.util.Logging;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -87,7 +85,7 @@ import mage.util.Logging;
|
||||||
*/
|
*/
|
||||||
public class ComputerPlayer2 extends ComputerPlayer<ComputerPlayer2> implements Player {
|
public class ComputerPlayer2 extends ComputerPlayer<ComputerPlayer2> implements Player {
|
||||||
|
|
||||||
private static final transient Logger logger = Logging.getLogger(ComputerPlayer2.class.getName());
|
private static final transient Logger logger = Logger.getLogger(ComputerPlayer2.class);
|
||||||
private static final ExecutorService pool = Executors.newFixedThreadPool(1);
|
private static final ExecutorService pool = Executors.newFixedThreadPool(1);
|
||||||
|
|
||||||
protected int maxDepth;
|
protected int maxDepth;
|
||||||
|
@ -177,7 +175,7 @@ public class ComputerPlayer2 extends ComputerPlayer<ComputerPlayer2> implements
|
||||||
Game sim = createSimulation(game);
|
Game sim = createSimulation(game);
|
||||||
SimulationNode.resetCount();
|
SimulationNode.resetCount();
|
||||||
root = new SimulationNode(sim, maxDepth, playerId);
|
root = new SimulationNode(sim, maxDepth, playerId);
|
||||||
logger.fine("simulating actions");
|
logger.debug("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);
|
||||||
|
@ -195,9 +193,9 @@ public class ComputerPlayer2 extends ComputerPlayer<ComputerPlayer2> implements
|
||||||
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.debug("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.debug("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;
|
||||||
|
@ -214,11 +212,11 @@ public class ComputerPlayer2 extends ComputerPlayer<ComputerPlayer2> implements
|
||||||
SimulationNode bestChild = null;
|
SimulationNode bestChild = null;
|
||||||
for (SimulationNode child: node.getChildren()) {
|
for (SimulationNode child: node.getChildren()) {
|
||||||
if (alpha >= beta) {
|
if (alpha >= beta) {
|
||||||
logger.fine("alpha beta pruning");
|
logger.debug("alpha beta pruning");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (SimulationNode.nodeCount > maxNodes) {
|
if (SimulationNode.nodeCount > maxNodes) {
|
||||||
logger.fine("simulating -- reached end-state");
|
logger.debug("simulating -- reached end-state");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
int val = addActions(child, filter, depth-1, alpha, beta);
|
int val = addActions(child, filter, depth-1, alpha, beta);
|
||||||
|
@ -243,11 +241,11 @@ public class ComputerPlayer2 extends ComputerPlayer<ComputerPlayer2> 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.debug("returning minimax beta: " + beta);
|
||||||
return beta;
|
return beta;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
logger.fine("returning minimax alpha: " + alpha);
|
logger.debug("returning minimax alpha: " + alpha);
|
||||||
return alpha;
|
return alpha;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -277,13 +275,13 @@ public class ComputerPlayer2 extends ComputerPlayer<ComputerPlayer2> implements
|
||||||
SimulationNode newNode = new SimulationNode(sim, depth, ability.getControllerId());
|
SimulationNode newNode = new SimulationNode(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.debug("simulating search -- node#: " + SimulationNode.getCount() + "for player: " + sim.getPlayer(ability.getControllerId()).getName());
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logger.fine("simulating resolve ");
|
logger.debug("simulating resolve ");
|
||||||
ability.resolve(game);
|
ability.resolve(game);
|
||||||
game.applyEffects();
|
game.applyEffects();
|
||||||
game.getPlayers().resetPassed();
|
game.getPlayers().resetPassed();
|
||||||
|
@ -301,13 +299,13 @@ public class ComputerPlayer2 extends ComputerPlayer<ComputerPlayer2> implements
|
||||||
try {
|
try {
|
||||||
task.get(Config.maxThinkSeconds, TimeUnit.SECONDS);
|
task.get(Config.maxThinkSeconds, TimeUnit.SECONDS);
|
||||||
} catch (TimeoutException e) {
|
} catch (TimeoutException e) {
|
||||||
logger.fine("simulating - timed out");
|
logger.debug("simulating - timed out");
|
||||||
task.cancel(true);
|
task.cancel(true);
|
||||||
} catch (ExecutionException e) {
|
} catch (ExecutionException e) {
|
||||||
logger.log(Level.SEVERE, "Simulation error", e);
|
logger.fatal("Simulation error", e);
|
||||||
task.cancel(true);
|
task.cancel(true);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
logger.log(Level.SEVERE, "Simulation interrupted", e);
|
logger.fatal("Simulation interrupted", e);
|
||||||
task.cancel(true);
|
task.cancel(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -317,20 +315,20 @@ public class ComputerPlayer2 extends ComputerPlayer<ComputerPlayer2> implements
|
||||||
int val;
|
int val;
|
||||||
if (Thread.interrupted()) {
|
if (Thread.interrupted()) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
logger.fine("interrupted");
|
logger.debug("interrupted");
|
||||||
return GameStateEvaluator.evaluate(playerId, game);
|
return GameStateEvaluator.evaluate(playerId, game);
|
||||||
}
|
}
|
||||||
if (depth <= 0 || SimulationNode.nodeCount > maxNodes || game.isGameOver()) {
|
if (depth <= 0 || SimulationNode.nodeCount > maxNodes || game.isGameOver()) {
|
||||||
logger.fine("simulating -- reached end state");
|
logger.debug("simulating -- reached end state");
|
||||||
val = GameStateEvaluator.evaluate(playerId, game);
|
val = GameStateEvaluator.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.debug("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.isDebugEnabled())
|
||||||
logger.fine("simulating -- alpha: " + alpha + " beta: " + beta + " depth:" + depth + " step:" + game.getTurn().getStepType() + " for player:" + (node.getPlayerId().equals(playerId)?"yes":"no"));
|
logger.debug("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);
|
||||||
|
@ -339,7 +337,7 @@ public class ComputerPlayer2 extends ComputerPlayer<ComputerPlayer2> 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.debug("simulating -- abandoning current check, no immediate benefit");
|
||||||
// return testScore;
|
// return testScore;
|
||||||
// }
|
// }
|
||||||
game.getPlayers().resetPassed();
|
game.getPlayers().resetPassed();
|
||||||
|
@ -352,7 +350,7 @@ public class ComputerPlayer2 extends ComputerPlayer<ComputerPlayer2> implements
|
||||||
}
|
}
|
||||||
else if (node.getChildren().size() > 0) {
|
else if (node.getChildren().size() > 0) {
|
||||||
//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.debug("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 {
|
||||||
|
@ -360,8 +358,8 @@ public class ComputerPlayer2 extends ComputerPlayer<ComputerPlayer2> implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (logger.isLoggable(Level.FINE))
|
if (logger.isDebugEnabled())
|
||||||
logger.fine("returning -- score: " + val + " depth:" + depth + " step:" + game.getTurn().getStepType() + " for player:" + game.getPlayer(node.getPlayerId()).getName());
|
logger.debug("returning -- score: " + val + " depth:" + depth + " step:" + game.getTurn().getStepType() + " for player:" + game.getPlayer(node.getPlayerId()).getName());
|
||||||
return val;
|
return val;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -369,16 +367,16 @@ public class ComputerPlayer2 extends ComputerPlayer<ComputerPlayer2> implements
|
||||||
protected int simulatePriority(SimulationNode node, Game game, FilterAbility filter, int depth, int alpha, int beta) {
|
protected int simulatePriority(SimulationNode 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.debug("interrupted");
|
||||||
return GameStateEvaluator.evaluate(playerId, game);
|
return GameStateEvaluator.evaluate(playerId, game);
|
||||||
}
|
}
|
||||||
node.setGameValue(game.getState().getValue());
|
node.setGameValue(game.getState().getValue());
|
||||||
SimulatedPlayer currentPlayer = (SimulatedPlayer) game.getPlayer(game.getPlayerList().get());
|
SimulatedPlayer currentPlayer = (SimulatedPlayer) game.getPlayer(game.getPlayerList().get());
|
||||||
logger.fine("simulating -- player " + currentPlayer.getName());
|
logger.debug("simulating -- player " + currentPlayer.getName());
|
||||||
SimulationNode bestNode = null;
|
SimulationNode bestNode = null;
|
||||||
List<Ability> allActions = currentPlayer.simulatePriority(game, filter);
|
List<Ability> allActions = currentPlayer.simulatePriority(game, filter);
|
||||||
if (logger.isLoggable(Level.FINE))
|
if (logger.isDebugEnabled())
|
||||||
logger.fine("simulating -- adding " + allActions.size() + " children:" + allActions);
|
logger.debug("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)) {
|
||||||
|
@ -389,8 +387,8 @@ public class ComputerPlayer2 extends ComputerPlayer<ComputerPlayer2> implements
|
||||||
sim.getPlayerList().getNext();
|
sim.getPlayerList().getNext();
|
||||||
}
|
}
|
||||||
SimulationNode newNode = new SimulationNode(sim, action, depth, currentPlayer.getId());
|
SimulationNode newNode = new SimulationNode(sim, action, depth, currentPlayer.getId());
|
||||||
if (logger.isLoggable(Level.FINE))
|
if (logger.isDebugEnabled())
|
||||||
logger.fine("simulating -- node #:" + SimulationNode.getCount() + " actions:" + action);
|
logger.debug("simulating -- node #:" + SimulationNode.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)) {
|
||||||
|
@ -412,11 +410,11 @@ public class ComputerPlayer2 extends ComputerPlayer<ComputerPlayer2> implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (alpha >= beta) {
|
if (alpha >= beta) {
|
||||||
logger.fine("simulating -- pruning");
|
logger.debug("simulating -- pruning");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (SimulationNode.nodeCount > maxNodes) {
|
if (SimulationNode.nodeCount > maxNodes) {
|
||||||
logger.fine("simulating -- reached end-state");
|
logger.debug("simulating -- reached end-state");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -426,11 +424,11 @@ public class ComputerPlayer2 extends ComputerPlayer<ComputerPlayer2> 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.debug("returning priority beta: " + beta);
|
||||||
return beta;
|
return beta;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
logger.fine("returning priority alpha: " + alpha);
|
logger.debug("returning priority alpha: " + alpha);
|
||||||
return alpha;
|
return alpha;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -564,7 +562,7 @@ public class ComputerPlayer2 extends ComputerPlayer<ComputerPlayer2> 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);
|
SimulationNode newNode = new SimulationNode(sim, node.getDepth()-1, activePlayerId);
|
||||||
logger.fine("simulating -- node #:" + SimulationNode.getCount() + " declare attakers");
|
logger.debug("simulating -- node #:" + SimulationNode.getCount() + " declare attakers");
|
||||||
newNode.setCombat(sim.getCombat());
|
newNode.setCombat(sim.getCombat());
|
||||||
node.children.add(newNode);
|
node.children.add(newNode);
|
||||||
}
|
}
|
||||||
|
@ -585,7 +583,7 @@ public class ComputerPlayer2 extends ComputerPlayer<ComputerPlayer2> 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);
|
SimulationNode newNode = new SimulationNode(sim, node.getDepth()-1, defenderId);
|
||||||
logger.fine("simulating -- node #:" + SimulationNode.getCount() + " declare blockers");
|
logger.debug("simulating -- node #:" + SimulationNode.getCount() + " declare blockers");
|
||||||
newNode.setCombat(sim.getCombat());
|
newNode.setCombat(sim.getCombat());
|
||||||
node.children.add(newNode);
|
node.children.add(newNode);
|
||||||
}
|
}
|
||||||
|
@ -608,7 +606,7 @@ public class ComputerPlayer2 extends ComputerPlayer<ComputerPlayer2> implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void selectAttackers(Game game) {
|
public void selectAttackers(Game game) {
|
||||||
logger.fine("selectAttackers");
|
logger.debug("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()) {
|
||||||
|
@ -619,7 +617,7 @@ public class ComputerPlayer2 extends ComputerPlayer<ComputerPlayer2> implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void selectBlockers(Game game) {
|
public void selectBlockers(Game game) {
|
||||||
logger.fine("selectBlockers");
|
logger.debug("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++) {
|
||||||
|
|
|
@ -30,14 +30,11 @@ package mage.player.ai;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
import mage.Constants.AbilityType;
|
import mage.Constants.AbilityType;
|
||||||
import mage.Constants.PhaseStep;
|
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.decks.Deck;
|
|
||||||
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;
|
||||||
|
@ -60,7 +57,7 @@ import mage.game.turn.Step;
|
||||||
import mage.game.turn.UntapStep;
|
import mage.game.turn.UntapStep;
|
||||||
import mage.game.turn.UpkeepStep;
|
import mage.game.turn.UpkeepStep;
|
||||||
import mage.players.Player;
|
import mage.players.Player;
|
||||||
import mage.util.Logging;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -68,7 +65,7 @@ import mage.util.Logging;
|
||||||
*/
|
*/
|
||||||
public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
|
public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
|
||||||
|
|
||||||
private static final transient Logger logger = Logging.getLogger(ComputerPlayer3.class.getName());
|
private static final transient Logger logger = Logger.getLogger(ComputerPlayer3.class);
|
||||||
|
|
||||||
private static FilterAbility filterLand = new FilterAbility();
|
private static FilterAbility filterLand = new FilterAbility();
|
||||||
private static FilterAbility filterNotLand = new FilterAbility();
|
private static FilterAbility filterNotLand = new FilterAbility();
|
||||||
|
@ -158,7 +155,7 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
|
||||||
Game sim = createSimulation(game);
|
Game sim = createSimulation(game);
|
||||||
SimulationNode.resetCount();
|
SimulationNode.resetCount();
|
||||||
root = new SimulationNode(sim, maxDepth, playerId);
|
root = new SimulationNode(sim, maxDepth, playerId);
|
||||||
logger.fine("simulating pre combat actions -----------------------------------------------------------------------------------------");
|
logger.debug("simulating pre combat actions -----------------------------------------------------------------------------------------");
|
||||||
|
|
||||||
addActionsTimed(new FilterAbility());
|
addActionsTimed(new FilterAbility());
|
||||||
if (root.children.size() > 0) {
|
if (root.children.size() > 0) {
|
||||||
|
@ -175,7 +172,7 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
|
||||||
Game sim = createSimulation(game);
|
Game sim = createSimulation(game);
|
||||||
SimulationNode.resetCount();
|
SimulationNode.resetCount();
|
||||||
root = new SimulationNode(sim, maxDepth, playerId);
|
root = new SimulationNode(sim, maxDepth, playerId);
|
||||||
logger.fine("simulating post combat actions ----------------------------------------------------------------------------------------");
|
logger.debug("simulating post combat 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);
|
||||||
|
@ -192,20 +189,20 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
|
||||||
Game game = node.getGame();
|
Game game = node.getGame();
|
||||||
if (Thread.interrupted()) {
|
if (Thread.interrupted()) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
logger.fine("interrupted");
|
logger.debug("interrupted");
|
||||||
return GameStateEvaluator.evaluate(playerId, game);
|
return GameStateEvaluator.evaluate(playerId, game);
|
||||||
}
|
}
|
||||||
if (depth <= 0 || SimulationNode.nodeCount > maxNodes || game.isGameOver()) {
|
if (depth <= 0 || SimulationNode.nodeCount > maxNodes || game.isGameOver()) {
|
||||||
logger.fine("simulating -- reached end state");
|
logger.debug("simulating -- reached end state");
|
||||||
val = GameStateEvaluator.evaluate(playerId, game);
|
val = GameStateEvaluator.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.debug("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.isDebugEnabled())
|
||||||
logger.fine("simulating -- alpha: " + alpha + " beta: " + beta + " depth:" + depth + " step:" + game.getTurn().getStepType() + " for player:" + game.getPlayer(game.getPlayerList().get()).getName());
|
logger.debug("simulating -- alpha: " + alpha + " beta: " + beta + " depth:" + depth + " step:" + game.getTurn().getStepType() + " for player:" + game.getPlayer(game.getPlayerList().get()).getName());
|
||||||
if (allPassed(game)) {
|
if (allPassed(game)) {
|
||||||
if (!game.getStack().isEmpty()) {
|
if (!game.getStack().isEmpty()) {
|
||||||
resolve(node, depth, game);
|
resolve(node, depth, game);
|
||||||
|
@ -219,12 +216,12 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
|
||||||
val = GameStateEvaluator.evaluate(playerId, game);
|
val = GameStateEvaluator.evaluate(playerId, game);
|
||||||
}
|
}
|
||||||
else if (stepFinished) {
|
else if (stepFinished) {
|
||||||
logger.fine("step finished");
|
logger.debug("step finished");
|
||||||
int testScore = GameStateEvaluator.evaluate(playerId, game);
|
int testScore = GameStateEvaluator.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
|
||||||
logger.fine("simulating -- abandoning check, no immediate benefit");
|
logger.debug("simulating -- abandoning check, no immediate benefit");
|
||||||
val = testScore;
|
val = testScore;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -249,7 +246,7 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (node.getChildren().size() > 0) {
|
else if (node.getChildren().size() > 0) {
|
||||||
logger.fine("simulating -- trigger added children:" + node.getChildren().size());
|
logger.debug("simulating -- trigger added children:" + node.getChildren().size());
|
||||||
val = minimaxAB(node, filter, depth, alpha, beta);
|
val = minimaxAB(node, filter, depth, alpha, beta);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -257,8 +254,8 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (logger.isLoggable(Level.FINE))
|
if (logger.isDebugEnabled())
|
||||||
logger.fine("returning -- score: " + val + " depth:" + depth + " step:" + game.getTurn().getStepType() + " for player:" + game.getPlayer(node.getPlayerId()).getName());
|
logger.debug("returning -- score: " + val + " depth:" + depth + " step:" + game.getTurn().getStepType() + " for player:" + game.getPlayer(node.getPlayerId()).getName());
|
||||||
return val;
|
return val;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -267,7 +264,7 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
|
||||||
Integer val = null;
|
Integer val = null;
|
||||||
if (Thread.interrupted()) {
|
if (Thread.interrupted()) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
logger.fine("interrupted");
|
logger.debug("interrupted");
|
||||||
return GameStateEvaluator.evaluate(playerId, game);
|
return GameStateEvaluator.evaluate(playerId, game);
|
||||||
}
|
}
|
||||||
if (game.getTurn().getStepType() != PhaseStep.DECLARE_BLOCKERS) {
|
if (game.getTurn().getStepType() != PhaseStep.DECLARE_BLOCKERS) {
|
||||||
|
@ -303,8 +300,8 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
|
||||||
}
|
}
|
||||||
if (val == null)
|
if (val == null)
|
||||||
val = GameStateEvaluator.evaluate(playerId, game);
|
val = GameStateEvaluator.evaluate(playerId, game);
|
||||||
if (logger.isLoggable(Level.FINE))
|
if (logger.isDebugEnabled())
|
||||||
logger.fine("returning -- combat score: " + val + " depth:" + depth + " for player:" + game.getPlayer(node.getPlayerId()).getName());
|
logger.debug("returning -- combat score: " + val + " depth:" + depth + " for player:" + game.getPlayer(node.getPlayerId()).getName());
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -312,7 +309,7 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
|
||||||
protected int simulateAttackers(Game game, SimulationNode node, UUID attackerId, int depth, int alpha, int beta, boolean counter) {
|
protected int simulateAttackers(Game game, SimulationNode 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.debug("interrupted");
|
||||||
return GameStateEvaluator.evaluate(playerId, game);
|
return GameStateEvaluator.evaluate(playerId, game);
|
||||||
}
|
}
|
||||||
Integer val = null;
|
Integer val = null;
|
||||||
|
@ -321,7 +318,7 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
|
||||||
|
|
||||||
for (Combat engagement: attacker.addAttackers(game)) {
|
for (Combat engagement: attacker.addAttackers(game)) {
|
||||||
if (alpha >= beta) {
|
if (alpha >= beta) {
|
||||||
logger.fine("simulating -- pruning attackers");
|
logger.debug("simulating -- pruning attackers");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Game sim = game.copy();
|
Game sim = game.copy();
|
||||||
|
@ -333,12 +330,12 @@ public class ComputerPlayer3 extends ComputerPlayer2 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());
|
SimulationNode newNode = new SimulationNode(sim, depth, game.getActivePlayerId());
|
||||||
if (logger.isLoggable(Level.FINE))
|
if (logger.isDebugEnabled())
|
||||||
logger.fine("simulating attack -- node#: " + SimulationNode.getCount());
|
logger.debug("simulating attack -- node#: " + SimulationNode.getCount());
|
||||||
sim.checkStateAndTriggered();
|
sim.checkStateAndTriggered();
|
||||||
while (!sim.getStack().isEmpty()) {
|
while (!sim.getStack().isEmpty()) {
|
||||||
sim.getStack().resolve(sim);
|
sim.getStack().resolve(sim);
|
||||||
logger.fine("resolving triggered abilities");
|
logger.debug("resolving triggered abilities");
|
||||||
sim.applyEffects();
|
sim.applyEffects();
|
||||||
}
|
}
|
||||||
sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARE_ATTACKERS_STEP_POST, sim.getActivePlayerId(), sim.getActivePlayerId()));
|
sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARE_ATTACKERS_STEP_POST, sim.getActivePlayerId(), sim.getActivePlayerId()));
|
||||||
|
@ -366,15 +363,15 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
|
||||||
node.children.clear();
|
node.children.clear();
|
||||||
node.children.add(bestNode);
|
node.children.add(bestNode);
|
||||||
}
|
}
|
||||||
if (logger.isLoggable(Level.FINE))
|
if (logger.isDebugEnabled())
|
||||||
logger.fine("returning -- combat attacker score: " + val + " depth:" + depth + " for player:" + game.getPlayer(node.getPlayerId()).getName());
|
logger.debug("returning -- combat attacker score: " + val + " depth:" + depth + " for player:" + game.getPlayer(node.getPlayerId()).getName());
|
||||||
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, SimulationNode 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.debug("interrupted");
|
||||||
return GameStateEvaluator.evaluate(playerId, game);
|
return GameStateEvaluator.evaluate(playerId, game);
|
||||||
}
|
}
|
||||||
Integer val = null;
|
Integer val = null;
|
||||||
|
@ -384,24 +381,26 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
|
||||||
SimulatedPlayer defender = (SimulatedPlayer) game.getPlayer(defenderId);
|
SimulatedPlayer defender = (SimulatedPlayer) 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.debug("simulating -- pruning blockers");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Game sim = game.copy();
|
Game sim = game.copy();
|
||||||
for (CombatGroup group: engagement.getGroups()) {
|
for (CombatGroup group: engagement.getGroups()) {
|
||||||
UUID attackerId = group.getAttackers().get(0);
|
if (group.getAttackers().size() > 0) {
|
||||||
for (UUID blockerId: group.getBlockers()) {
|
UUID attackerId = group.getAttackers().get(0);
|
||||||
sim.getPlayer(defenderId).declareBlocker(blockerId, attackerId, sim);
|
for (UUID blockerId: group.getBlockers()) {
|
||||||
|
sim.getPlayer(defenderId).declareBlocker(blockerId, attackerId, sim);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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);
|
SimulationNode newNode = new SimulationNode(sim, depth, defenderId);
|
||||||
if (logger.isLoggable(Level.FINE))
|
if (logger.isDebugEnabled())
|
||||||
logger.fine("simulating block -- node#: " + SimulationNode.getCount());
|
logger.debug("simulating block -- node#: " + SimulationNode.getCount());
|
||||||
sim.checkStateAndTriggered();
|
sim.checkStateAndTriggered();
|
||||||
while (!sim.getStack().isEmpty()) {
|
while (!sim.getStack().isEmpty()) {
|
||||||
sim.getStack().resolve(sim);
|
sim.getStack().resolve(sim);
|
||||||
logger.fine("resolving triggered abilities");
|
logger.debug("resolving triggered abilities");
|
||||||
sim.applyEffects();
|
sim.applyEffects();
|
||||||
}
|
}
|
||||||
sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARE_BLOCKERS_STEP_POST, sim.getActivePlayerId(), sim.getActivePlayerId()));
|
sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARE_BLOCKERS_STEP_POST, sim.getActivePlayerId(), sim.getActivePlayerId()));
|
||||||
|
@ -437,20 +436,20 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
|
||||||
node.children.clear();
|
node.children.clear();
|
||||||
node.children.add(bestNode);
|
node.children.add(bestNode);
|
||||||
}
|
}
|
||||||
if (logger.isLoggable(Level.FINE))
|
if (logger.isDebugEnabled())
|
||||||
logger.fine("returning -- combat blocker score: " + val + " depth:" + depth + " for player:" + game.getPlayer(node.getPlayerId()).getName());
|
logger.debug("returning -- combat blocker score: " + val + " depth:" + depth + " for player:" + game.getPlayer(node.getPlayerId()).getName());
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int simulateCounterAttack(Game game, SimulationNode node, int depth, int alpha, int beta) {
|
protected int simulateCounterAttack(Game game, SimulationNode node, int depth, int alpha, int beta) {
|
||||||
if (Thread.interrupted()) {
|
if (Thread.interrupted()) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
logger.fine("interrupted");
|
logger.debug("interrupted");
|
||||||
return GameStateEvaluator.evaluate(playerId, game);
|
return GameStateEvaluator.evaluate(playerId, game);
|
||||||
}
|
}
|
||||||
Integer val = null;
|
Integer val = null;
|
||||||
if (!game.isGameOver()) {
|
if (!game.isGameOver()) {
|
||||||
logger.fine("simulating -- counter attack");
|
logger.debug("simulating -- counter attack");
|
||||||
simulateToEnd(game);
|
simulateToEnd(game);
|
||||||
game.getState().setActivePlayerId(game.getState().getPlayerList(game.getActivePlayerId()).getNext());
|
game.getState().setActivePlayerId(game.getState().getPlayerList(game.getActivePlayerId()).getNext());
|
||||||
game.getTurn().setPhase(new BeginningPhase());
|
game.getTurn().setPhase(new BeginningPhase());
|
||||||
|
@ -461,8 +460,8 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
|
||||||
game.getPhase().endPhase(game, game.getActivePlayerId());
|
game.getPhase().endPhase(game, game.getActivePlayerId());
|
||||||
}
|
}
|
||||||
val = simulateCombat(game, node, depth-1, alpha, beta, true);
|
val = simulateCombat(game, node, depth-1, alpha, beta, true);
|
||||||
if (logger.isLoggable(Level.FINE))
|
if (logger.isDebugEnabled())
|
||||||
logger.fine("returning -- counter attack score: " + val + " depth:" + depth + " for player:" + game.getPlayer(node.getPlayerId()).getName());
|
logger.debug("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 = GameStateEvaluator.evaluate(playerId, game);
|
||||||
|
@ -472,7 +471,7 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
|
||||||
protected void simulateStep(Game game, Step step) {
|
protected void simulateStep(Game game, Step step) {
|
||||||
if (Thread.interrupted()) {
|
if (Thread.interrupted()) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
logger.fine("interrupted");
|
logger.debug("interrupted");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!game.isGameOver()) {
|
if (!game.isGameOver()) {
|
||||||
|
@ -492,7 +491,7 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
|
||||||
protected void finishCombat(Game game) {
|
protected void finishCombat(Game game) {
|
||||||
if (Thread.interrupted()) {
|
if (Thread.interrupted()) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
logger.fine("interrupted");
|
logger.debug("interrupted");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
simulateStep(game, new CombatDamageStep(true));
|
simulateStep(game, new CombatDamageStep(true));
|
||||||
|
@ -503,10 +502,10 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
|
||||||
protected int simulatePostCombatMain(Game game, SimulationNode node, int depth, int alpha, int beta) {
|
protected int simulatePostCombatMain(Game game, SimulationNode node, int depth, int alpha, int beta) {
|
||||||
if (Thread.interrupted()) {
|
if (Thread.interrupted()) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
logger.fine("interrupted");
|
logger.debug("interrupted");
|
||||||
return GameStateEvaluator.evaluate(playerId, game);
|
return GameStateEvaluator.evaluate(playerId, game);
|
||||||
}
|
}
|
||||||
logger.fine("simulating -- post combat main");
|
logger.debug("simulating -- post combat main");
|
||||||
game.getTurn().setPhase(new PostCombatMainPhase());
|
game.getTurn().setPhase(new PostCombatMainPhase());
|
||||||
if (game.getPhase().beginPhase(game, game.getActivePlayerId())) {
|
if (game.getPhase().beginPhase(game, game.getActivePlayerId())) {
|
||||||
game.getPhase().setStep(new PostCombatMainStep());
|
game.getPhase().setStep(new PostCombatMainStep());
|
||||||
|
@ -520,7 +519,7 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
|
||||||
protected void simulateToEnd(Game game) {
|
protected void simulateToEnd(Game game) {
|
||||||
if (Thread.interrupted()) {
|
if (Thread.interrupted()) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
logger.fine("interrupted");
|
logger.debug("interrupted");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!game.isGameOver()) {
|
if (!game.isGameOver()) {
|
||||||
|
|
|
@ -33,9 +33,7 @@ import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.logging.Level;
|
import org.apache.log4j.Logger;
|
||||||
import java.util.logging.Logger;
|
|
||||||
import mage.util.Logging;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -43,7 +41,7 @@ import mage.util.Logging;
|
||||||
*/
|
*/
|
||||||
public class Config {
|
public class Config {
|
||||||
|
|
||||||
private final static Logger logger = Logging.getLogger(Config.class.getName());
|
private final static Logger logger = Logger.getLogger(Config.class);
|
||||||
|
|
||||||
public static final int maxDepth;
|
public static final int maxDepth;
|
||||||
public static final int maxNodes;
|
public static final int maxNodes;
|
||||||
|
@ -59,9 +57,9 @@ public class Config {
|
||||||
File file = new File(Config.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
|
File file = new File(Config.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.fatal("", ex);
|
||||||
} catch (URISyntaxException ex) {
|
} catch (URISyntaxException ex) {
|
||||||
Logger.getLogger(Config.class.getName()).log(Level.SEVERE, null, ex);
|
logger.fatal("", 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"));
|
||||||
|
|
|
@ -31,18 +31,11 @@ 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.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,8 +47,7 @@ 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 org.apache.log4j.Logger;
|
||||||
import mage.util.Logging;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -63,7 +55,7 @@ import mage.util.Logging;
|
||||||
*/
|
*/
|
||||||
public class SimulatedPlayer extends ComputerPlayer<SimulatedPlayer> {
|
public class SimulatedPlayer extends ComputerPlayer<SimulatedPlayer> {
|
||||||
|
|
||||||
private final static transient Logger logger = Logging.getLogger(SimulatedPlayer.class.getName());
|
private final static transient Logger logger = Logger.getLogger(SimulatedPlayer.class);
|
||||||
private boolean isSimulatedPlayer;
|
private boolean isSimulatedPlayer;
|
||||||
private FilterAbility filter;
|
private FilterAbility filter;
|
||||||
private transient ConcurrentLinkedQueue<Ability> allActions;
|
private transient ConcurrentLinkedQueue<Ability> allActions;
|
||||||
|
@ -154,10 +146,10 @@ public class SimulatedPlayer extends ComputerPlayer<SimulatedPlayer> {
|
||||||
sim.getCombat().declareAttacker(attackersList.get(j).getId(), defenderId, sim);
|
sim.getCombat().declareAttacker(attackersList.get(j).getId(), defenderId, sim);
|
||||||
}
|
}
|
||||||
if (engagements.put(sim.getCombat().getValue(sim), sim.getCombat()) != null) {
|
if (engagements.put(sim.getCombat().getValue(sim), sim.getCombat()) != null) {
|
||||||
logger.fine("simulating -- found redundant attack combination");
|
logger.debug("simulating -- found redundant attack combination");
|
||||||
}
|
}
|
||||||
else if (logger.isLoggable(Level.FINE)) {
|
else if (logger.isDebugEnabled()) {
|
||||||
logger.fine("simulating -- attack:" + sim.getCombat().getGroups().size());
|
logger.debug("simulating -- attack:" + sim.getCombat().getGroups().size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new ArrayList<Combat>(engagements.values());
|
return new ArrayList<Combat>(engagements.values());
|
||||||
|
@ -185,15 +177,15 @@ public class SimulatedPlayer extends ComputerPlayer<SimulatedPlayer> {
|
||||||
int numGroups = game.getCombat().getGroups().size();
|
int numGroups = game.getCombat().getGroups().size();
|
||||||
//try to block each attacker with each potential blocker
|
//try to block each attacker with each potential blocker
|
||||||
Permanent blocker = blockers.get(0);
|
Permanent blocker = blockers.get(0);
|
||||||
if (logger.isLoggable(Level.FINE))
|
if (logger.isDebugEnabled())
|
||||||
logger.fine("simulating -- block:" + blocker);
|
logger.debug("simulating -- block:" + blocker);
|
||||||
List<Permanent> remaining = remove(blockers, blocker);
|
List<Permanent> remaining = remove(blockers, blocker);
|
||||||
for (int i = 0; i < numGroups; i++) {
|
for (int i = 0; i < numGroups; i++) {
|
||||||
if (game.getCombat().getGroups().get(i).canBlock(blocker, game)) {
|
if (game.getCombat().getGroups().get(i).canBlock(blocker, game)) {
|
||||||
Game sim = game.copy();
|
Game sim = game.copy();
|
||||||
sim.getCombat().getGroups().get(i).addBlocker(blocker.getId(), playerId, sim);
|
sim.getCombat().getGroups().get(i).addBlocker(blocker.getId(), playerId, sim);
|
||||||
if (engagements.put(sim.getCombat().getValue(sim), sim.getCombat()) != null)
|
if (engagements.put(sim.getCombat().getValue(sim), sim.getCombat()) != null)
|
||||||
logger.fine("simulating -- found redundant block combination");
|
logger.debug("simulating -- found redundant block combination");
|
||||||
addBlocker(sim, remaining, engagements); // and recurse minus the used blocker
|
addBlocker(sim, remaining, engagements); // and recurse minus the used blocker
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -205,8 +197,8 @@ public class SimulatedPlayer extends ComputerPlayer<SimulatedPlayer> {
|
||||||
Ability ability = source.copy();
|
Ability ability = source.copy();
|
||||||
List<Ability> options = getPlayableOptions(ability, game);
|
List<Ability> options = getPlayableOptions(ability, game);
|
||||||
if (options.size() == 0) {
|
if (options.size() == 0) {
|
||||||
if (logger.isLoggable(Level.FINE))
|
if (logger.isDebugEnabled())
|
||||||
logger.fine("simulating -- triggered ability:" + ability);
|
logger.debug("simulating -- triggered ability:" + ability);
|
||||||
game.getStack().push(new StackAbility(ability, playerId));
|
game.getStack().push(new StackAbility(ability, playerId));
|
||||||
ability.activate(game, false);
|
ability.activate(game, false);
|
||||||
game.applyEffects();
|
game.applyEffects();
|
||||||
|
@ -216,7 +208,7 @@ public class SimulatedPlayer extends ComputerPlayer<SimulatedPlayer> {
|
||||||
SimulationNode parent = (SimulationNode) game.getCustomData();
|
SimulationNode parent = (SimulationNode) 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.debug("simulating -- triggered ability - adding children:" + options.size());
|
||||||
for (Ability option: options) {
|
for (Ability option: options) {
|
||||||
addAbilityNode(parent, option, depth, game);
|
addAbilityNode(parent, option, depth, game);
|
||||||
}
|
}
|
||||||
|
@ -230,7 +222,7 @@ public class SimulatedPlayer extends ComputerPlayer<SimulatedPlayer> {
|
||||||
ability.activate(sim, false);
|
ability.activate(sim, false);
|
||||||
sim.applyEffects();
|
sim.applyEffects();
|
||||||
SimulationNode newNode = new SimulationNode(sim, depth, playerId);
|
SimulationNode newNode = new SimulationNode(sim, depth, playerId);
|
||||||
logger.fine("simulating -- node #:" + SimulationNode.getCount() + " triggered ability option");
|
logger.debug("simulating -- node #:" + SimulationNode.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);
|
||||||
|
|
|
@ -33,8 +33,6 @@ import mage.server.util.PluginClassLoader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FilenameFilter;
|
import java.io.FilenameFilter;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
import mage.game.match.MatchType;
|
import mage.game.match.MatchType;
|
||||||
import mage.game.tournament.TournamentType;
|
import mage.game.tournament.TournamentType;
|
||||||
import mage.server.game.DeckValidatorFactory;
|
import mage.server.game.DeckValidatorFactory;
|
||||||
|
@ -45,7 +43,7 @@ import mage.server.util.ConfigSettings;
|
||||||
import mage.server.util.config.Plugin;
|
import mage.server.util.config.Plugin;
|
||||||
import mage.server.util.config.GamePlugin;
|
import mage.server.util.config.GamePlugin;
|
||||||
import mage.util.Copier;
|
import mage.util.Copier;
|
||||||
import mage.util.Logging;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -53,7 +51,7 @@ import mage.util.Logging;
|
||||||
*/
|
*/
|
||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
private static Logger logger = Logging.getLogger(Main.class.getName());
|
private static Logger logger = Logger.getLogger(Main.class);
|
||||||
|
|
||||||
private final static String testModeArg = "-testMode=";
|
private final static String testModeArg = "-testMode=";
|
||||||
private final static String pluginFolder = "plugins";
|
private final static String pluginFolder = "plugins";
|
||||||
|
@ -68,7 +66,7 @@ public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
logger.info("Starting MAGE server version " + version);
|
logger.info("Starting MAGE server version " + version);
|
||||||
logger.info("Logging level: " + Logging.getLevel(logger));
|
logger.info("Logging level: " + logger.getLevel());
|
||||||
deleteSavedGames();
|
deleteSavedGames();
|
||||||
ConfigSettings config = ConfigSettings.getInstance();
|
ConfigSettings config = ConfigSettings.getInstance();
|
||||||
for (GamePlugin plugin: config.getGameTypes()) {
|
for (GamePlugin plugin: config.getGameTypes()) {
|
||||||
|
@ -101,7 +99,7 @@ public class Main {
|
||||||
ip = InetAddress.getLocalHost().getHostAddress();
|
ip = InetAddress.getLocalHost().getHostAddress();
|
||||||
}
|
}
|
||||||
} catch (UnknownHostException ex) {
|
} catch (UnknownHostException ex) {
|
||||||
logger.log(Level.WARNING, "Could not get server address: ", ex);
|
logger.warn("Could not get server address: ", ex);
|
||||||
}
|
}
|
||||||
String ipParam = System.getProperty("server");
|
String ipParam = System.getProperty("server");
|
||||||
if (ipParam != null) {
|
if (ipParam != null) {
|
||||||
|
@ -117,9 +115,9 @@ public class Main {
|
||||||
logger.info("Loading plugin: " + plugin.getClassName());
|
logger.info("Loading plugin: " + plugin.getClassName());
|
||||||
return Class.forName(plugin.getClassName(), true, classLoader);
|
return Class.forName(plugin.getClassName(), true, classLoader);
|
||||||
} catch (ClassNotFoundException ex) {
|
} catch (ClassNotFoundException ex) {
|
||||||
logger.log(Level.SEVERE, "Plugin not Found:" + plugin.getJar() + " - check plugin folder");
|
logger.warn("Plugin not Found:" + plugin.getJar() + " - check plugin folder");
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.log(Level.SEVERE, "Error loading plugin " + plugin.getJar(), ex);
|
logger.fatal("Error loading plugin " + plugin.getJar(), ex);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -130,9 +128,9 @@ public class Main {
|
||||||
logger.info("Loading game type: " + plugin.getClassName());
|
logger.info("Loading game type: " + plugin.getClassName());
|
||||||
return (MatchType) Class.forName(plugin.getTypeName(), true, classLoader).newInstance();
|
return (MatchType) Class.forName(plugin.getTypeName(), true, classLoader).newInstance();
|
||||||
} catch (ClassNotFoundException ex) {
|
} catch (ClassNotFoundException ex) {
|
||||||
logger.log(Level.SEVERE, "Game type not found:" + plugin.getJar() + " - check plugin folder");
|
logger.warn("Game type not found:" + plugin.getJar() + " - check plugin folder");
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.log(Level.SEVERE, "Error loading game type " + plugin.getJar(), ex);
|
logger.fatal("Error loading game type " + plugin.getJar(), ex);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -143,9 +141,9 @@ public class Main {
|
||||||
logger.info("Loading tournament type: " + plugin.getClassName());
|
logger.info("Loading tournament type: " + plugin.getClassName());
|
||||||
return (TournamentType) Class.forName(plugin.getTypeName(), true, classLoader).newInstance();
|
return (TournamentType) Class.forName(plugin.getTypeName(), true, classLoader).newInstance();
|
||||||
} catch (ClassNotFoundException ex) {
|
} catch (ClassNotFoundException ex) {
|
||||||
logger.log(Level.SEVERE, "Tournament type not found:" + plugin.getJar() + " - check plugin folder");
|
logger.warn("Tournament type not found:" + plugin.getJar() + " - check plugin folder");
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.log(Level.SEVERE, "Error loading game type " + plugin.getJar(), ex);
|
logger.fatal("Error loading game type " + plugin.getJar(), ex);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,16 +127,16 @@ public class PlayGameTest extends MageTestBase {
|
||||||
if (card != null) {
|
if (card != null) {
|
||||||
cards.add(card);
|
cards.add(card);
|
||||||
} else {
|
} else {
|
||||||
logger.severe("Couldn't find a card: " + cardName);
|
logger.fatal("Couldn't find a card: " + cardName);
|
||||||
logger.severe("line: " + line);
|
logger.fatal("line: " + line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.warning("Unknown player: " + nickname);
|
logger.warn("Unknown player: " + nickname);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.warning("Init string wasn't parsed: " + line);
|
logger.warn("Init string wasn't parsed: " + line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -11,20 +11,19 @@ import mage.server.util.PluginClassLoader;
|
||||||
import mage.server.util.config.GamePlugin;
|
import mage.server.util.config.GamePlugin;
|
||||||
import mage.server.util.config.Plugin;
|
import mage.server.util.config.Plugin;
|
||||||
import mage.util.Copier;
|
import mage.util.Copier;
|
||||||
import mage.util.Logging;
|
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FilenameFilter;
|
import java.io.FilenameFilter;
|
||||||
import java.util.logging.Level;
|
import org.apache.log4j.Level;
|
||||||
import java.util.logging.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author ayratn
|
* @author ayratn
|
||||||
*/
|
*/
|
||||||
public class MageTestBase {
|
public class MageTestBase {
|
||||||
protected static Logger logger = Logging.getLogger(MageTestBase.class.getName());
|
protected static Logger logger = Logger.getLogger(MageTestBase.class);
|
||||||
|
|
||||||
public static PluginClassLoader classLoader = new PluginClassLoader();
|
public static PluginClassLoader classLoader = new PluginClassLoader();
|
||||||
|
|
||||||
|
@ -34,8 +33,9 @@ public class MageTestBase {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void init() {
|
public static void init() {
|
||||||
|
Logger.getRootLogger().setLevel(Level.DEBUG);
|
||||||
logger.info("Starting MAGE tests");
|
logger.info("Starting MAGE tests");
|
||||||
logger.info("Logging level: " + Logging.getLevel(logger));
|
logger.info("Logging level: " + logger.getLevel());
|
||||||
deleteSavedGames();
|
deleteSavedGames();
|
||||||
ConfigSettings config = ConfigSettings.getInstance();
|
ConfigSettings config = ConfigSettings.getInstance();
|
||||||
for (GamePlugin plugin : config.getGameTypes()) {
|
for (GamePlugin plugin : config.getGameTypes()) {
|
||||||
|
@ -59,9 +59,9 @@ public class MageTestBase {
|
||||||
logger.info("Loading plugin: " + plugin.getClassName());
|
logger.info("Loading plugin: " + plugin.getClassName());
|
||||||
return Class.forName(plugin.getClassName(), true, classLoader);
|
return Class.forName(plugin.getClassName(), true, classLoader);
|
||||||
} catch (ClassNotFoundException ex) {
|
} catch (ClassNotFoundException ex) {
|
||||||
logger.log(Level.SEVERE, "Plugin not Found:" + plugin.getJar() + " - check plugin folder");
|
logger.warn("Plugin not Found:" + plugin.getJar() + " - check plugin folder");
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.log(Level.SEVERE, "Error loading plugin " + plugin.getJar(), ex);
|
logger.fatal("Error loading plugin " + plugin.getJar(), ex);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -72,9 +72,9 @@ public class MageTestBase {
|
||||||
logger.info("Loading game type: " + plugin.getClassName());
|
logger.info("Loading game type: " + plugin.getClassName());
|
||||||
return (MatchType) Class.forName(plugin.getTypeName(), true, classLoader).newInstance();
|
return (MatchType) Class.forName(plugin.getTypeName(), true, classLoader).newInstance();
|
||||||
} catch (ClassNotFoundException ex) {
|
} catch (ClassNotFoundException ex) {
|
||||||
logger.log(Level.SEVERE, "Game type not found:" + plugin.getJar() + " - check plugin folder");
|
logger.warn("Game type not found:" + plugin.getJar() + " - check plugin folder");
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.log(Level.SEVERE, "Error loading game type " + plugin.getJar(), ex);
|
logger.fatal("Error loading game type " + plugin.getJar(), ex);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -85,9 +85,9 @@ public class MageTestBase {
|
||||||
logger.info("Loading tournament type: " + plugin.getClassName());
|
logger.info("Loading tournament type: " + plugin.getClassName());
|
||||||
return (TournamentType) Class.forName(plugin.getTypeName(), true, classLoader).newInstance();
|
return (TournamentType) Class.forName(plugin.getTypeName(), true, classLoader).newInstance();
|
||||||
} catch (ClassNotFoundException ex) {
|
} catch (ClassNotFoundException ex) {
|
||||||
logger.log(Level.SEVERE, "Tournament type not found:" + plugin.getJar() + " - check plugin folder");
|
logger.warn("Tournament type not found:" + plugin.getJar() + " - check plugin folder");
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.log(Level.SEVERE, "Error loading game type " + plugin.getJar(), ex);
|
logger.fatal("Error loading game type " + plugin.getJar(), ex);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,13 +90,18 @@ public class TargetCreatureOrPlayer extends TargetImpl<TargetCreatureOrPlayer> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canTarget(UUID id, Ability source, Game game) {
|
public boolean canTarget(UUID id, Ability source, Game game) {
|
||||||
|
return canTarget(null, id, source, game);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean canTarget(UUID controllerId, UUID id, Ability source, Game game) {
|
||||||
Permanent permanent = game.getPermanent(id);
|
Permanent permanent = game.getPermanent(id);
|
||||||
MageObject targetSource = game.getObject(source.getSourceId());
|
MageObject targetSource = game.getObject(source.getSourceId());
|
||||||
if (permanent != null) {
|
if (permanent != null) {
|
||||||
if (source != null)
|
if (source != null)
|
||||||
return permanent.canBeTargetedBy(targetSource) && filter.match(permanent, source.getControllerId(), game);
|
//TODO: check for replacement effects
|
||||||
|
return permanent.canBeTargetedBy(game.getObject(source.getSourceId())) && filter.match(permanent, controllerId, game);
|
||||||
else
|
else
|
||||||
return filter.match(permanent);
|
return filter.match(permanent, controllerId, game);
|
||||||
}
|
}
|
||||||
Player player = game.getPlayer(id);
|
Player player = game.getPlayer(id);
|
||||||
if (player != null)
|
if (player != null)
|
||||||
|
|
Loading…
Reference in a new issue