mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +00:00
fixes
This commit is contained in:
parent
784eb17456
commit
66e7a3beae
5 changed files with 496 additions and 496 deletions
|
@ -19,12 +19,12 @@
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mage</groupId>
|
<groupId>org.mage</groupId>
|
||||||
<artifactId>mage</artifactId>
|
<artifactId>Mage</artifactId>
|
||||||
<version>${mage-version}</version>
|
<version>${mage-version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mage</groupId>
|
<groupId>org.mage</groupId>
|
||||||
<artifactId>mage-player-ai</artifactId>
|
<artifactId>Mage-Player-AI</artifactId>
|
||||||
<version>${mage-version}</version>
|
<version>${mage-version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
|
@ -66,471 +66,471 @@ import mage.util.Logging;
|
||||||
*
|
*
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
*/
|
*/
|
||||||
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 = Logging.getLogger(ComputerPlayer3.class.getName());
|
||||||
|
//
|
||||||
private static FilterAbility filterLand = new FilterAbility();
|
// private static FilterAbility filterLand = new FilterAbility();
|
||||||
private static FilterAbility filterNotLand = new FilterAbility();
|
// private static FilterAbility filterNotLand = new FilterAbility();
|
||||||
|
//
|
||||||
static {
|
// static {
|
||||||
filterLand.getTypes().add(AbilityType.PLAY_LAND);
|
// filterLand.getTypes().add(AbilityType.PLAY_LAND);
|
||||||
filterLand.setZone(Zone.HAND);
|
// filterLand.setZone(Zone.HAND);
|
||||||
|
//
|
||||||
filterNotLand.getTypes().add(AbilityType.PLAY_LAND);
|
// filterNotLand.getTypes().add(AbilityType.PLAY_LAND);
|
||||||
filterNotLand.setZone(Zone.HAND);
|
// filterNotLand.setZone(Zone.HAND);
|
||||||
filterNotLand.setNotFilter(true);
|
// filterNotLand.setNotFilter(true);
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public ComputerPlayer3(String name, Deck deck, RangeOfInfluence range) {
|
// public ComputerPlayer3(String name, Deck deck, RangeOfInfluence range) {
|
||||||
super(name, deck, range);
|
// super(name, deck, range);
|
||||||
maxDepth = Config.maxDepth;
|
// maxDepth = Config.maxDepth;
|
||||||
maxNodes = Config.maxNodes;
|
// maxNodes = Config.maxNodes;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public ComputerPlayer3(final ComputerPlayer3 player) {
|
// public ComputerPlayer3(final ComputerPlayer3 player) {
|
||||||
super(player);
|
// super(player);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public ComputerPlayer3 copy() {
|
// public ComputerPlayer3 copy() {
|
||||||
return new ComputerPlayer3(this);
|
// return new ComputerPlayer3(this);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public void priority(Game game) {
|
// public void priority(Game game) {
|
||||||
logState(game);
|
// logState(game);
|
||||||
game.firePriorityEvent(playerId);
|
// game.firePriorityEvent(playerId);
|
||||||
switch (game.getTurn().getStepType()) {
|
// switch (game.getTurn().getStepType()) {
|
||||||
case UPKEEP:
|
// case UPKEEP:
|
||||||
case DRAW:
|
// case DRAW:
|
||||||
pass();
|
// pass();
|
||||||
break;
|
// break;
|
||||||
case PRECOMBAT_MAIN:
|
// case PRECOMBAT_MAIN:
|
||||||
if (game.getActivePlayerId().equals(playerId)) {
|
// if (game.getActivePlayerId().equals(playerId)) {
|
||||||
if (actions.size() == 0) {
|
// if (actions.size() == 0) {
|
||||||
calculatePreCombatActions(game);
|
// calculatePreCombatActions(game);
|
||||||
}
|
// }
|
||||||
act(game);
|
// act(game);
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
pass();
|
// pass();
|
||||||
break;
|
// break;
|
||||||
case BEGIN_COMBAT:
|
// case BEGIN_COMBAT:
|
||||||
pass();
|
// pass();
|
||||||
break;
|
// break;
|
||||||
case DECLARE_ATTACKERS:
|
// case DECLARE_ATTACKERS:
|
||||||
if (!game.getActivePlayerId().equals(playerId)) {
|
// if (!game.getActivePlayerId().equals(playerId)) {
|
||||||
if (actions.size() == 0) {
|
// if (actions.size() == 0) {
|
||||||
calculatePreCombatActions(game);
|
// calculatePreCombatActions(game);
|
||||||
}
|
// }
|
||||||
act(game);
|
// act(game);
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
pass();
|
// pass();
|
||||||
break;
|
// break;
|
||||||
case DECLARE_BLOCKERS:
|
// case DECLARE_BLOCKERS:
|
||||||
case COMBAT_DAMAGE:
|
// case COMBAT_DAMAGE:
|
||||||
case END_COMBAT:
|
// case END_COMBAT:
|
||||||
pass();
|
// pass();
|
||||||
break;
|
// break;
|
||||||
case POSTCOMBAT_MAIN:
|
// case POSTCOMBAT_MAIN:
|
||||||
if (game.getActivePlayerId().equals(playerId)) {
|
// if (game.getActivePlayerId().equals(playerId)) {
|
||||||
if (actions.size() == 0) {
|
// if (actions.size() == 0) {
|
||||||
calculatePostCombatActions(game);
|
// calculatePostCombatActions(game);
|
||||||
}
|
// }
|
||||||
act(game);
|
// act(game);
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
pass();
|
// pass();
|
||||||
break;
|
// break;
|
||||||
case END_TURN:
|
// case END_TURN:
|
||||||
case CLEANUP:
|
// case CLEANUP:
|
||||||
pass();
|
// pass();
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
protected void calculatePreCombatActions(Game game) {
|
// protected void calculatePreCombatActions(Game game) {
|
||||||
if (!getNextAction(game)) {
|
// if (!getNextAction(game)) {
|
||||||
currentScore = GameStateEvaluator.evaluate(playerId, game);
|
// currentScore = GameStateEvaluator.evaluate(playerId, game);
|
||||||
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.fine("simulating pre 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);
|
||||||
actions = new LinkedList<Ability>(root.abilities);
|
// actions = new LinkedList<Ability>(root.abilities);
|
||||||
combat = root.combat;
|
// combat = root.combat;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
protected void calculatePostCombatActions(Game game) {
|
// protected void calculatePostCombatActions(Game game) {
|
||||||
if (!getNextAction(game)) {
|
// if (!getNextAction(game)) {
|
||||||
currentScore = GameStateEvaluator.evaluate(playerId, game);
|
// currentScore = GameStateEvaluator.evaluate(playerId, game);
|
||||||
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.fine("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);
|
||||||
actions = new LinkedList<Ability>(root.abilities);
|
// actions = new LinkedList<Ability>(root.abilities);
|
||||||
combat = root.combat;
|
// combat = root.combat;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
protected int addActions(SimulationNode node, FilterAbility filter, int depth, int alpha, int beta) {
|
// protected int addActions(SimulationNode 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 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.fine("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.fine("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:" + game.getPlayer(game.getPlayerList().get()).getName());
|
// logger.fine("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);
|
||||||
}
|
// }
|
||||||
else {
|
// else {
|
||||||
stepFinished = true;
|
// stepFinished = true;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if (game.isGameOver()) {
|
// if (game.isGameOver()) {
|
||||||
val = GameStateEvaluator.evaluate(playerId, game);
|
// val = GameStateEvaluator.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 = 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.fine("simulating -- abandoning check, no immediate benefit");
|
||||||
val = testScore;
|
// val = testScore;
|
||||||
}
|
// }
|
||||||
else {
|
// else {
|
||||||
switch (game.getTurn().getStepType()) {
|
// switch (game.getTurn().getStepType()) {
|
||||||
case PRECOMBAT_MAIN:
|
// case PRECOMBAT_MAIN:
|
||||||
val = simulateCombat(game, node, depth-1, alpha, beta, false);
|
// val = simulateCombat(game, node, depth-1, alpha, beta, false);
|
||||||
break;
|
// break;
|
||||||
case POSTCOMBAT_MAIN:
|
// case POSTCOMBAT_MAIN:
|
||||||
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 = GameStateEvaluator.evaluate(playerId, game);
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
else {
|
// else {
|
||||||
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 = GameStateEvaluator.evaluate(playerId, game);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
else if (node.getChildren().size() > 0) {
|
// else if (node.getChildren().size() > 0) {
|
||||||
logger.fine("simulating -- trigger added children:" + node.getChildren().size());
|
// logger.fine("simulating -- trigger added children:" + node.getChildren().size());
|
||||||
val = minimaxAB(node, filter, depth, alpha, beta);
|
// val = minimaxAB(node, filter, depth, alpha, beta);
|
||||||
}
|
// }
|
||||||
else {
|
// else {
|
||||||
val = simulatePriority(node, game, filter, depth, alpha, beta);
|
// val = simulatePriority(node, game, filter, depth, alpha, beta);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
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.fine("returning -- score: " + val + " depth:" + depth + " step:" + game.getTurn().getStepType() + " for player:" + game.getPlayer(node.getPlayerId()).getName());
|
||||||
return val;
|
// return val;
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
protected int simulateCombat(Game game, SimulationNode node, int depth, int alpha, int beta, boolean counter) {
|
// protected int simulateCombat(Game game, SimulationNode 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 GameStateEvaluator.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());
|
||||||
if (game.getPhase().beginPhase(game, game.getActivePlayerId())) {
|
// if (game.getPhase().beginPhase(game, game.getActivePlayerId())) {
|
||||||
simulateStep(game, new BeginCombatStep());
|
// simulateStep(game, new BeginCombatStep());
|
||||||
game.getPhase().setStep(new DeclareAttackersStep());
|
// game.getPhase().setStep(new DeclareAttackersStep());
|
||||||
if (!game.getStep().skipStep(game, game.getActivePlayerId())) {
|
// if (!game.getStep().skipStep(game, game.getActivePlayerId())) {
|
||||||
game.fireEvent(new GameEvent(GameEvent.EventType.DECLARE_ATTACKERS_STEP_PRE, null, null, game.getActivePlayerId()));
|
// game.fireEvent(new GameEvent(GameEvent.EventType.DECLARE_ATTACKERS_STEP_PRE, null, null, game.getActivePlayerId()));
|
||||||
if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.DECLARING_ATTACKERS, game.getActivePlayerId(), game.getActivePlayerId()))) {
|
// if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.DECLARING_ATTACKERS, game.getActivePlayerId(), game.getActivePlayerId()))) {
|
||||||
val = simulateAttackers(game, node, game.getActivePlayerId(), depth, alpha, beta, counter);
|
// val = simulateAttackers(game, node, game.getActivePlayerId(), depth, alpha, beta, counter);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
else if (!counter) {
|
// else if (!counter) {
|
||||||
simulateToEnd(game);
|
// simulateToEnd(game);
|
||||||
val = simulatePostCombatMain(game, node, depth, alpha, beta);
|
// val = simulatePostCombatMain(game, node, depth, alpha, beta);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
else {
|
// else {
|
||||||
if (!game.getStep().skipStep(game, game.getActivePlayerId())) {
|
// if (!game.getStep().skipStep(game, game.getActivePlayerId())) {
|
||||||
game.fireEvent(new GameEvent(GameEvent.EventType.DECLARE_BLOCKERS_STEP_PRE, null, null, game.getActivePlayerId()));
|
// game.fireEvent(new GameEvent(GameEvent.EventType.DECLARE_BLOCKERS_STEP_PRE, null, null, game.getActivePlayerId()));
|
||||||
if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.DECLARING_BLOCKERS, game.getActivePlayerId(), game.getActivePlayerId()))) {
|
// if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.DECLARING_BLOCKERS, game.getActivePlayerId(), game.getActivePlayerId()))) {
|
||||||
//only suitable for two player games - only simulates blocks for 1st defender
|
// //only suitable for two player games - only simulates blocks for 1st defender
|
||||||
val = simulateBlockers(game, node, game.getCombat().getDefenders().iterator().next(), depth, alpha, beta, counter);
|
// val = simulateBlockers(game, node, game.getCombat().getDefenders().iterator().next(), depth, alpha, beta, counter);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
else if (!counter) {
|
// else if (!counter) {
|
||||||
finishCombat(game);
|
// finishCombat(game);
|
||||||
val = GameStateEvaluator.evaluate(playerId, game);
|
// val = GameStateEvaluator.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 = GameStateEvaluator.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, 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.fine("interrupted");
|
||||||
return GameStateEvaluator.evaluate(playerId, game);
|
// return GameStateEvaluator.evaluate(playerId, game);
|
||||||
}
|
// }
|
||||||
Integer val = null;
|
// Integer val = null;
|
||||||
SimulationNode bestNode = null;
|
// SimulationNode bestNode = null;
|
||||||
SimulatedPlayer attacker = (SimulatedPlayer) game.getPlayer(attackerId);
|
// SimulatedPlayer attacker = (SimulatedPlayer) 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();
|
||||||
UUID defenderId = game.getOpponents(playerId).iterator().next();
|
// UUID defenderId = game.getOpponents(playerId).iterator().next();
|
||||||
for (CombatGroup group: engagement.getGroups()) {
|
// for (CombatGroup group: engagement.getGroups()) {
|
||||||
for (UUID attackId: group.getAttackers()) {
|
// for (UUID attackId: group.getAttackers()) {
|
||||||
sim.getPlayer(attackerId).declareAttacker(attackId, defenderId, sim);
|
// sim.getPlayer(attackerId).declareAttacker(attackId, defenderId, sim);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
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.isLoggable(Level.FINE))
|
||||||
logger.fine("simulating attack -- node#: " + SimulationNode.getCount());
|
// logger.fine("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.fine("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()));
|
||||||
Combat simCombat = sim.getCombat().copy();
|
// Combat simCombat = sim.getCombat().copy();
|
||||||
sim.getPhase().setStep(new DeclareBlockersStep());
|
// sim.getPhase().setStep(new DeclareBlockersStep());
|
||||||
val = simulateCombat(sim, newNode, depth-1, alpha, beta, counter);
|
// val = simulateCombat(sim, newNode, depth-1, alpha, beta, counter);
|
||||||
if (!attackerId.equals(playerId)) {
|
// if (!attackerId.equals(playerId)) {
|
||||||
if (val < beta) {
|
// if (val < beta) {
|
||||||
beta = val;
|
// beta = val;
|
||||||
bestNode = newNode;
|
// bestNode = newNode;
|
||||||
node.setCombat(simCombat);
|
// node.setCombat(simCombat);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
else {
|
// else {
|
||||||
if (val > alpha) {
|
// if (val > alpha) {
|
||||||
alpha = val;
|
// alpha = val;
|
||||||
bestNode = newNode;
|
// bestNode = newNode;
|
||||||
node.setCombat(simCombat);
|
// node.setCombat(simCombat);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
if (val == null)
|
// if (val == null)
|
||||||
val = GameStateEvaluator.evaluate(playerId, game);
|
// val = GameStateEvaluator.evaluate(playerId, game);
|
||||||
if (bestNode != null) {
|
// if (bestNode != null) {
|
||||||
node.children.clear();
|
// node.children.clear();
|
||||||
node.children.add(bestNode);
|
// node.children.add(bestNode);
|
||||||
}
|
// }
|
||||||
if (logger.isLoggable(Level.FINE))
|
// if (logger.isLoggable(Level.FINE))
|
||||||
logger.fine("returning -- combat attacker score: " + val + " depth:" + depth + " for player:" + game.getPlayer(node.getPlayerId()).getName());
|
// logger.fine("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.fine("interrupted");
|
||||||
return GameStateEvaluator.evaluate(playerId, game);
|
// return GameStateEvaluator.evaluate(playerId, game);
|
||||||
}
|
// }
|
||||||
Integer val = null;
|
// Integer val = null;
|
||||||
SimulationNode bestNode = null;
|
// SimulationNode 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);
|
// 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.fine("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);
|
// UUID attackerId = group.getAttackers().get(0);
|
||||||
for (UUID blockerId: group.getBlockers()) {
|
// for (UUID blockerId: group.getBlockers()) {
|
||||||
sim.getPlayer(defenderId).declareBlocker(blockerId, attackerId, sim);
|
// 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.isLoggable(Level.FINE))
|
||||||
logger.fine("simulating block -- node#: " + SimulationNode.getCount());
|
// logger.fine("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.fine("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()));
|
||||||
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 = GameStateEvaluator.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 = GameStateEvaluator.evaluate(playerId, sim);
|
||||||
if (!defenderId.equals(playerId)) {
|
// if (!defenderId.equals(playerId)) {
|
||||||
if (val < beta) {
|
// if (val < beta) {
|
||||||
beta = val;
|
// beta = val;
|
||||||
bestNode = newNode;
|
// bestNode = newNode;
|
||||||
node.setCombat(simCombat);
|
// node.setCombat(simCombat);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
else {
|
// else {
|
||||||
if (val > alpha) {
|
// if (val > alpha) {
|
||||||
alpha = val;
|
// alpha = val;
|
||||||
bestNode = newNode;
|
// bestNode = newNode;
|
||||||
node.setCombat(simCombat);
|
// node.setCombat(simCombat);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
if (val == null)
|
// if (val == null)
|
||||||
val = GameStateEvaluator.evaluate(playerId, game);
|
// val = GameStateEvaluator.evaluate(playerId, game);
|
||||||
if (bestNode != null) {
|
// if (bestNode != null) {
|
||||||
node.children.clear();
|
// node.children.clear();
|
||||||
node.children.add(bestNode);
|
// node.children.add(bestNode);
|
||||||
}
|
// }
|
||||||
if (logger.isLoggable(Level.FINE))
|
// if (logger.isLoggable(Level.FINE))
|
||||||
logger.fine("returning -- combat blocker score: " + val + " depth:" + depth + " for player:" + game.getPlayer(node.getPlayerId()).getName());
|
// logger.fine("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.fine("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.fine("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());
|
||||||
if (game.getPhase().beginPhase(game, game.getActivePlayerId())) {
|
// if (game.getPhase().beginPhase(game, game.getActivePlayerId())) {
|
||||||
simulateStep(game, new UntapStep());
|
// simulateStep(game, new UntapStep());
|
||||||
simulateStep(game, new UpkeepStep());
|
// simulateStep(game, new UpkeepStep());
|
||||||
simulateStep(game, new DrawStep());
|
// simulateStep(game, new DrawStep());
|
||||||
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.isLoggable(Level.FINE))
|
||||||
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 = GameStateEvaluator.evaluate(playerId, game);
|
||||||
return val;
|
// return val;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
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.fine("interrupted");
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
if (!game.isGameOver()) {
|
// if (!game.isGameOver()) {
|
||||||
game.getPhase().setStep(step);
|
// game.getPhase().setStep(step);
|
||||||
if (!step.skipStep(game, game.getActivePlayerId())) {
|
// if (!step.skipStep(game, game.getActivePlayerId())) {
|
||||||
step.beginStep(game, game.getActivePlayerId());
|
// step.beginStep(game, game.getActivePlayerId());
|
||||||
game.checkStateAndTriggered();
|
// game.checkStateAndTriggered();
|
||||||
while (!game.getStack().isEmpty()) {
|
// while (!game.getStack().isEmpty()) {
|
||||||
game.getStack().resolve(game);
|
// game.getStack().resolve(game);
|
||||||
game.applyEffects();
|
// game.applyEffects();
|
||||||
}
|
// }
|
||||||
step.endStep(game, game.getActivePlayerId());
|
// step.endStep(game, game.getActivePlayerId());
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
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.fine("interrupted");
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
simulateStep(game, new CombatDamageStep(true));
|
// simulateStep(game, new CombatDamageStep(true));
|
||||||
simulateStep(game, new CombatDamageStep(false));
|
// simulateStep(game, new CombatDamageStep(false));
|
||||||
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, SimulationNode 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 GameStateEvaluator.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());
|
||||||
if (game.getPhase().beginPhase(game, game.getActivePlayerId())) {
|
// if (game.getPhase().beginPhase(game, game.getActivePlayerId())) {
|
||||||
game.getPhase().setStep(new PostCombatMainStep());
|
// game.getPhase().setStep(new PostCombatMainStep());
|
||||||
game.getStep().beginStep(game, playerId);
|
// game.getStep().beginStep(game, playerId);
|
||||||
game.getPlayers().resetPassed();
|
// game.getPlayers().resetPassed();
|
||||||
return addActions(node, new FilterAbility(), depth, alpha, beta);
|
// return addActions(node, new FilterAbility(), depth, alpha, beta);
|
||||||
}
|
// }
|
||||||
return simulateCounterAttack(game, node, depth, alpha, beta);
|
// return simulateCounterAttack(game, node, depth, alpha, beta);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
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.fine("interrupted");
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
if (!game.isGameOver()) {
|
// if (!game.isGameOver()) {
|
||||||
game.getTurn().getPhase().endPhase(game, game.getActivePlayerId());
|
// game.getTurn().getPhase().endPhase(game, game.getActivePlayerId());
|
||||||
game.getTurn().setPhase(new EndPhase());
|
// game.getTurn().setPhase(new EndPhase());
|
||||||
if (game.getTurn().getPhase().beginPhase(game, game.getActivePlayerId())) {
|
// if (game.getTurn().getPhase().beginPhase(game, game.getActivePlayerId())) {
|
||||||
simulateStep(game, new EndStep());
|
// simulateStep(game, new EndStep());
|
||||||
simulateStep(game, new CleanupStep());
|
// simulateStep(game, new CleanupStep());
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
//}
|
||||||
|
|
|
@ -38,25 +38,25 @@ import mage.util.Logging;
|
||||||
*
|
*
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
*/
|
*/
|
||||||
public class SimulateBlockWorker implements Callable {
|
//public class SimulateBlockWorker implements Callable {
|
||||||
|
//
|
||||||
private final static Logger logger = Logging.getLogger(SimulationWorker.class.getName());
|
// private final static Logger logger = Logging.getLogger(SimulationWorker.class.getName());
|
||||||
|
//
|
||||||
private SimulationNode node;
|
// private SimulationNode node;
|
||||||
private ComputerPlayer3 player;
|
//// private ComputerPlayer3 player;
|
||||||
|
//
|
||||||
public SimulateBlockWorker(ComputerPlayer3 player, SimulationNode node) {
|
// public SimulateBlockWorker(ComputerPlayer3 player, SimulationNode node) {
|
||||||
this.player = player;
|
// this.player = player;
|
||||||
this.node = node;
|
// this.node = node;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public Object call() {
|
// public Object call() {
|
||||||
try {
|
// try {
|
||||||
// player.simulateBlock(node);
|
//// player.simulateBlock(node);
|
||||||
} catch (Exception ex) {
|
// } catch (Exception ex) {
|
||||||
logger.log(Level.SEVERE, null, ex);
|
// logger.log(Level.SEVERE, null, ex);
|
||||||
}
|
// }
|
||||||
return null;
|
// return null;
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|
|
@ -19,17 +19,17 @@
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mage</groupId>
|
<groupId>org.mage</groupId>
|
||||||
<artifactId>mage</artifactId>
|
<artifactId>Mage</artifactId>
|
||||||
<version>${mage-version}</version>
|
<version>${mage-version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mage</groupId>
|
<groupId>org.mage</groupId>
|
||||||
<artifactId>mage-common</artifactId>
|
<artifactId>Mage-Common</artifactId>
|
||||||
<version>${mage-version}</version>
|
<version>${mage-version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mage</groupId>
|
<groupId>org.mage</groupId>
|
||||||
<artifactId>mage-sets</artifactId>
|
<artifactId>Mage-Sets</artifactId>
|
||||||
<version>${mage-version}</version>
|
<version>${mage-version}</version>
|
||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mage</groupId>
|
<groupId>org.mage</groupId>
|
||||||
<artifactId>mage</artifactId>
|
<artifactId>Mage</artifactId>
|
||||||
<version>${mage-version}</version>
|
<version>${mage-version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
Loading…
Reference in a new issue