mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +00:00
more AI fixes - dont use x=0 for activated abilities
This commit is contained in:
parent
42509dd4f8
commit
0668548f4f
6 changed files with 29 additions and 10 deletions
|
@ -186,7 +186,10 @@ public class ComputerPlayer2 extends ComputerPlayer<ComputerPlayer2> implements
|
||||||
SimulationNode.resetCount();
|
SimulationNode.resetCount();
|
||||||
root = new SimulationNode(null, sim, playerId);
|
root = new SimulationNode(null, sim, playerId);
|
||||||
logger.debug("simulating actions");
|
logger.debug("simulating actions");
|
||||||
|
if (!isTestMode)
|
||||||
addActionsTimed(new FilterAbility());
|
addActionsTimed(new FilterAbility());
|
||||||
|
else
|
||||||
|
addActions(root, new FilterAbility(), Integer.MIN_VALUE, Integer.MAX_VALUE);
|
||||||
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);
|
||||||
|
@ -400,7 +403,7 @@ public class ComputerPlayer2 extends ComputerPlayer<ComputerPlayer2> implements
|
||||||
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());
|
||||||
boolean isSimulatedPlayer = currentPlayer.getId().equals(playerId);
|
boolean isSimulatedPlayer = currentPlayer.getId().equals(playerId);
|
||||||
logger.debug(indent(node.depth) + "simulating -- player " + currentPlayer.getName());
|
logger.debug(indent(node.depth) + "simulating priority -- 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.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
|
@ -425,7 +428,7 @@ public class ComputerPlayer2 extends ComputerPlayer<ComputerPlayer2> implements
|
||||||
}
|
}
|
||||||
SimulationNode newNode = new SimulationNode(node, sim, action, currentPlayer.getId());
|
SimulationNode newNode = new SimulationNode(node, sim, action, currentPlayer.getId());
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
logger.debug(indent(node.depth) + "simulating -- node #:" + SimulationNode.getCount() + " actions:" + action);
|
logger.debug(indent(newNode.depth) + "simulating -- node #:" + SimulationNode.getCount() + " actions:" + action);
|
||||||
sim.checkStateAndTriggered();
|
sim.checkStateAndTriggered();
|
||||||
int val = addActions(newNode, filter, alpha, beta);
|
int val = addActions(newNode, filter, alpha, beta);
|
||||||
if (!isSimulatedPlayer) {
|
if (!isSimulatedPlayer) {
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
package mage.player.ai;
|
package mage.player.ai;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import mage.Constants.AbilityType;
|
import mage.Constants.AbilityType;
|
||||||
import mage.Constants.PhaseStep;
|
import mage.Constants.PhaseStep;
|
||||||
|
@ -159,8 +160,10 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
|
||||||
root = new SimulationNode(null, sim, playerId);
|
root = new SimulationNode(null, sim, playerId);
|
||||||
logger.debug("simulating pre combat actions -----------------------------------------------------------------------------------------");
|
logger.debug("simulating pre combat actions -----------------------------------------------------------------------------------------");
|
||||||
|
|
||||||
|
if (!isTestMode)
|
||||||
addActionsTimed(new FilterAbility());
|
addActionsTimed(new FilterAbility());
|
||||||
// addActions(root, new FilterAbility(), maxDepth, Integer.MIN_VALUE, Integer.MAX_VALUE);
|
else
|
||||||
|
addActions(root, new FilterAbility(), Integer.MIN_VALUE, Integer.MAX_VALUE);
|
||||||
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);
|
||||||
|
@ -180,8 +183,10 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
|
||||||
SimulationNode.resetCount();
|
SimulationNode.resetCount();
|
||||||
root = new SimulationNode(null, sim, playerId);
|
root = new SimulationNode(null, sim, playerId);
|
||||||
logger.debug("simulating post combat actions ----------------------------------------------------------------------------------------");
|
logger.debug("simulating post combat actions ----------------------------------------------------------------------------------------");
|
||||||
|
if (!isTestMode)
|
||||||
addActionsTimed(new FilterAbility());
|
addActionsTimed(new FilterAbility());
|
||||||
// addActions(root, new FilterAbility(), maxDepth, Integer.MIN_VALUE, Integer.MAX_VALUE);
|
else
|
||||||
|
addActions(root, new FilterAbility(), Integer.MIN_VALUE, Integer.MAX_VALUE);
|
||||||
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);
|
||||||
|
@ -291,7 +296,6 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!counter) {
|
else if (!counter) {
|
||||||
simulateToEnd(game);
|
|
||||||
val = simulatePostCombatMain(game, node, alpha, beta);
|
val = simulatePostCombatMain(game, node, alpha, beta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -329,7 +333,8 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
|
||||||
|
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
logger.debug(indent(node.depth) + attacker.getName() + "'s possible attackers: " + attacker.getAvailableAttackers(game));
|
logger.debug(indent(node.depth) + attacker.getName() + "'s possible attackers: " + attacker.getAvailableAttackers(game));
|
||||||
for (Combat engagement: attacker.addAttackers(game)) {
|
List<Combat> engagements = attacker.addAttackers(game);
|
||||||
|
for (Combat engagement: engagements) {
|
||||||
if (alpha >= beta) {
|
if (alpha >= beta) {
|
||||||
logger.debug(indent(node.depth) + "simulating -- pruning attackers");
|
logger.debug(indent(node.depth) + "simulating -- pruning attackers");
|
||||||
break;
|
break;
|
||||||
|
@ -464,6 +469,7 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
|
||||||
}
|
}
|
||||||
Integer val = null;
|
Integer val = null;
|
||||||
if (!game.isGameOver()) {
|
if (!game.isGameOver()) {
|
||||||
|
logger.debug(indent(node.depth) + "simulating -- ending turn");
|
||||||
simulateToEnd(game);
|
simulateToEnd(game);
|
||||||
game.getState().setActivePlayerId(game.getState().getPlayerList(game.getActivePlayerId()).getNext());
|
game.getState().setActivePlayerId(game.getState().getPlayerList(game.getActivePlayerId()).getNext());
|
||||||
logger.debug(indent(node.depth) + "simulating -- counter attack for player " + game.getPlayer(game.getActivePlayerId()).getName());
|
logger.debug(indent(node.depth) + "simulating -- counter attack for player " + game.getPlayer(game.getActivePlayerId()).getName());
|
||||||
|
@ -474,6 +480,7 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
|
||||||
simulateStep(game, new DrawStep());
|
simulateStep(game, new DrawStep());
|
||||||
game.getPhase().endPhase(game, game.getActivePlayerId());
|
game.getPhase().endPhase(game, game.getActivePlayerId());
|
||||||
}
|
}
|
||||||
|
//TODO: calculate opponent actions before combat
|
||||||
val = simulateCombat(game, node, alpha, beta, true);
|
val = simulateCombat(game, node, alpha, beta, true);
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
logger.debug(indent(node.depth) + "returning -- counter attack score: " + val + " depth:" + node.depth + " for player:" + game.getPlayer(node.getPlayerId()).getName());
|
logger.debug(indent(node.depth) + "returning -- counter attack score: " + val + " depth:" + node.depth + " for player:" + game.getPlayer(node.getPlayerId()).getName());
|
||||||
|
|
|
@ -37,6 +37,7 @@ import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
|
import mage.abilities.SpellAbility;
|
||||||
import mage.abilities.TriggeredAbility;
|
import mage.abilities.TriggeredAbility;
|
||||||
import mage.abilities.common.PassAbility;
|
import mage.abilities.common.PassAbility;
|
||||||
import mage.abilities.costs.mana.GenericManaCost;
|
import mage.abilities.costs.mana.GenericManaCost;
|
||||||
|
@ -147,7 +148,15 @@ public class SimulatedPlayer extends ComputerPlayer<SimulatedPlayer> {
|
||||||
//add a generic mana cost for each amount possible
|
//add a generic mana cost for each amount possible
|
||||||
protected void simulateVariableCosts(Ability ability, Game game) {
|
protected void simulateVariableCosts(Ability ability, Game game) {
|
||||||
int numAvailable = getAvailableManaProducers(game).size();
|
int numAvailable = getAvailableManaProducers(game).size();
|
||||||
for (int i = 0; i < numAvailable; i++) {
|
int start = 0;
|
||||||
|
if (!(ability instanceof SpellAbility)) {
|
||||||
|
//only use x=0 on spell abilities
|
||||||
|
if (numAvailable == 0)
|
||||||
|
return;
|
||||||
|
else
|
||||||
|
start = 1;
|
||||||
|
}
|
||||||
|
for (int i = start; i < numAvailable; i++) {
|
||||||
Ability newAbility = ability.copy();
|
Ability newAbility = ability.copy();
|
||||||
newAbility.addManaCost(new GenericManaCost(i));
|
newAbility.addManaCost(new GenericManaCost(i));
|
||||||
allActions.add(newAbility);
|
allActions.add(newAbility);
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in a new issue