more AI fixes - dont use x=0 for activated abilities

This commit is contained in:
BetaSteward 2011-03-10 22:07:13 -05:00
parent 42509dd4f8
commit 0668548f4f
6 changed files with 29 additions and 10 deletions

View file

@ -186,7 +186,10 @@ public class ComputerPlayer2 extends ComputerPlayer<ComputerPlayer2> implements
SimulationNode.resetCount();
root = new SimulationNode(null, sim, playerId);
logger.debug("simulating actions");
addActionsTimed(new FilterAbility());
if (!isTestMode)
addActionsTimed(new FilterAbility());
else
addActions(root, new FilterAbility(), Integer.MIN_VALUE, Integer.MAX_VALUE);
if (root.children.size() > 0) {
root = root.children.get(0);
actions = new LinkedList<Ability>(root.abilities);
@ -400,7 +403,7 @@ public class ComputerPlayer2 extends ComputerPlayer<ComputerPlayer2> implements
node.setGameValue(game.getState().getValue());
SimulatedPlayer currentPlayer = (SimulatedPlayer) game.getPlayer(game.getPlayerList().get());
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;
List<Ability> allActions = currentPlayer.simulatePriority(game, filter);
if (logger.isDebugEnabled())
@ -425,7 +428,7 @@ public class ComputerPlayer2 extends ComputerPlayer<ComputerPlayer2> implements
}
SimulationNode newNode = new SimulationNode(node, sim, action, currentPlayer.getId());
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();
int val = addActions(newNode, filter, alpha, beta);
if (!isSimulatedPlayer) {

View file

@ -29,6 +29,7 @@
package mage.player.ai;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
import mage.Constants.AbilityType;
import mage.Constants.PhaseStep;
@ -159,8 +160,10 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
root = new SimulationNode(null, sim, playerId);
logger.debug("simulating pre combat actions -----------------------------------------------------------------------------------------");
addActionsTimed(new FilterAbility());
// addActions(root, new FilterAbility(), maxDepth, Integer.MIN_VALUE, Integer.MAX_VALUE);
if (!isTestMode)
addActionsTimed(new FilterAbility());
else
addActions(root, new FilterAbility(), Integer.MIN_VALUE, Integer.MAX_VALUE);
if (root.children.size() > 0) {
root = root.children.get(0);
actions = new LinkedList<Ability>(root.abilities);
@ -180,8 +183,10 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
SimulationNode.resetCount();
root = new SimulationNode(null, sim, playerId);
logger.debug("simulating post combat actions ----------------------------------------------------------------------------------------");
addActionsTimed(new FilterAbility());
// addActions(root, new FilterAbility(), maxDepth, Integer.MIN_VALUE, Integer.MAX_VALUE);
if (!isTestMode)
addActionsTimed(new FilterAbility());
else
addActions(root, new FilterAbility(), Integer.MIN_VALUE, Integer.MAX_VALUE);
if (root.children.size() > 0) {
root = root.children.get(0);
actions = new LinkedList<Ability>(root.abilities);
@ -291,7 +296,6 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
}
}
else if (!counter) {
simulateToEnd(game);
val = simulatePostCombatMain(game, node, alpha, beta);
}
}
@ -329,7 +333,8 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
if (logger.isDebugEnabled())
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) {
logger.debug(indent(node.depth) + "simulating -- pruning attackers");
break;
@ -464,6 +469,7 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
}
Integer val = null;
if (!game.isGameOver()) {
logger.debug(indent(node.depth) + "simulating -- ending turn");
simulateToEnd(game);
game.getState().setActivePlayerId(game.getState().getPlayerList(game.getActivePlayerId()).getNext());
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());
game.getPhase().endPhase(game, game.getActivePlayerId());
}
//TODO: calculate opponent actions before combat
val = simulateCombat(game, node, alpha, beta, true);
if (logger.isDebugEnabled())
logger.debug(indent(node.depth) + "returning -- counter attack score: " + val + " depth:" + node.depth + " for player:" + game.getPlayer(node.getPlayerId()).getName());

View file

@ -37,6 +37,7 @@ import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentLinkedQueue;
import mage.abilities.Ability;
import mage.abilities.SpellAbility;
import mage.abilities.TriggeredAbility;
import mage.abilities.common.PassAbility;
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
protected void simulateVariableCosts(Ability ability, Game game) {
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();
newAbility.addManaCost(new GenericManaCost(i));
allActions.add(newAbility);