mirror of
https://github.com/correl/mage.git
synced 2024-11-28 19:19:55 +00:00
Fixed combat actions in MAD AI. Updated tests.
This commit is contained in:
parent
1f259ec772
commit
53e9d2752b
13 changed files with 46 additions and 22 deletions
Binary file not shown.
|
@ -503,7 +503,9 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
|||
beta = val;
|
||||
bestNode = newNode;
|
||||
bestNode.setScore(val);
|
||||
node.setCombat(newNode.getCombat());
|
||||
if (newNode.getChildren().size() > 0) {
|
||||
bestNode.setCombat(newNode.getChildren().get(0).getCombat());
|
||||
}
|
||||
}
|
||||
|
||||
// no need to check other actions
|
||||
|
@ -517,11 +519,14 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
|||
alpha = val;
|
||||
bestNode = newNode;
|
||||
bestNode.setScore(val);
|
||||
node.setCombat(newNode.getCombat());
|
||||
if (node.getTargets().size() > 0)
|
||||
if (newNode.getChildren().size() > 0) {
|
||||
bestNode.setCombat(newNode.getChildren().get(0).getCombat());
|
||||
}
|
||||
/*if (node.getTargets().size() > 0)
|
||||
targets = node.getTargets();
|
||||
if (node.getChoices().size() > 0)
|
||||
choices = node.getChoices();
|
||||
*/
|
||||
if (depth == maxDepth) {
|
||||
logger.info("saved");
|
||||
node.children.clear();
|
||||
|
@ -813,6 +818,7 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
|||
for (int i = 0; i < groups.size(); i++) {
|
||||
if (i < combat.getGroups().size()) {
|
||||
for (UUID blockerId: combat.getGroups().get(i).getBlockers()) {
|
||||
logger.info("select blocker: " + blockerId + " vs " + groups.get(i).getAttackers().get(0));
|
||||
this.declareBlocker(blockerId, groups.get(i).getAttackers().get(0), game);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,6 +43,7 @@ import mage.players.Player;
|
|||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
|
@ -184,6 +185,7 @@ public class ComputerPlayer7 extends ComputerPlayer6 implements Player {
|
|||
//if (bestScore > currentScore || allowBadMoves) {
|
||||
actions = new LinkedList<Ability>(root.abilities);
|
||||
combat = root.combat;
|
||||
logger.debug("final score: " + bestScore);
|
||||
//} else {
|
||||
//System.out.println("[" + game.getPlayer(playerId).getName() + "][post] Action: not better score");
|
||||
//}
|
||||
|
@ -241,8 +243,8 @@ public class ComputerPlayer7 extends ComputerPlayer6 implements Player {
|
|||
val = simulateCombat(game, node, depth-1, alpha, beta, false);
|
||||
break;
|
||||
case POSTCOMBAT_MAIN:
|
||||
val = simulateCounterAttack(game, node, depth-1, alpha, beta);
|
||||
break;
|
||||
//val = simulateCounterAttack(game, node, depth-1, alpha, beta);
|
||||
//break;
|
||||
default:
|
||||
val = GameStateEvaluator2.evaluate(playerId, game);
|
||||
break;
|
||||
|
@ -305,7 +307,7 @@ public class ComputerPlayer7 extends ComputerPlayer6 implements Player {
|
|||
}
|
||||
else if (!counter) {
|
||||
finishCombat(game);
|
||||
val = simulateCounterAttack(game, node, depth, alpha, beta);
|
||||
///val = simulateCounterAttack(game, node, depth, alpha, beta);
|
||||
}
|
||||
}
|
||||
if (val == null)
|
||||
|
@ -329,6 +331,9 @@ public class ComputerPlayer7 extends ComputerPlayer6 implements Player {
|
|||
if (logger.isDebugEnabled())
|
||||
logger.debug(attacker.getName() + "'s possible attackers: " + attacker.getAvailableAttackers(game));
|
||||
for (Combat engagement: attacker.addAttackers(game)) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Attackers: " + engagement.getAttackers() + ", blockers: " + engagement.getBlockers());
|
||||
}
|
||||
if (alpha >= beta) {
|
||||
logger.debug("simulating -- pruning attackers");
|
||||
break;
|
||||
|
@ -359,7 +364,9 @@ public class ComputerPlayer7 extends ComputerPlayer6 implements Player {
|
|||
beta = val;
|
||||
bestNode = newNode;
|
||||
bestNode.setScore(val);
|
||||
node.setCombat(simCombat);
|
||||
if (newNode.getChildren().size() > 0) {
|
||||
bestNode.setCombat(newNode.getChildren().get(0).getCombat());
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -367,7 +374,9 @@ public class ComputerPlayer7 extends ComputerPlayer6 implements Player {
|
|||
alpha = val;
|
||||
bestNode = newNode;
|
||||
bestNode.setScore(val);
|
||||
node.setCombat(simCombat);
|
||||
if (newNode.getChildren().size() > 0) {
|
||||
bestNode.setCombat(newNode.getChildren().get(0).getCombat());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -396,7 +405,8 @@ public class ComputerPlayer7 extends ComputerPlayer6 implements Player {
|
|||
SimulatedPlayer2 defender = (SimulatedPlayer2) game.getPlayer(defenderId);
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug(defender.getName() + "'s possible blockers: " + defender.getAvailableBlockers(game));
|
||||
for (Combat engagement: defender.addBlockers(game)) {
|
||||
List<Combat> combats = defender.addBlockers(game);
|
||||
for (Combat engagement: combats) {
|
||||
if (alpha >= beta) {
|
||||
logger.debug("simulating -- pruning blockers");
|
||||
break;
|
||||
|
@ -436,14 +446,15 @@ public class ComputerPlayer7 extends ComputerPlayer6 implements Player {
|
|||
beta = val;
|
||||
bestNode = newNode;
|
||||
bestNode.setScore(val);
|
||||
node.setCombat(simCombat);
|
||||
bestNode.setCombat(simCombat);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (val > alpha) {
|
||||
alpha = val;
|
||||
bestNode = newNode;
|
||||
node.setCombat(simCombat);
|
||||
bestNode.setScore(val);
|
||||
bestNode.setCombat(simCombat);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -532,7 +543,8 @@ public class ComputerPlayer7 extends ComputerPlayer6 implements Player {
|
|||
game.getPlayers().resetPassed();
|
||||
return addActions(node, depth, alpha, beta);
|
||||
}
|
||||
return simulateCounterAttack(game, node, depth, alpha, beta);
|
||||
//return simulateCounterAttack(game, node, depth, alpha, beta);
|
||||
return GameStateEvaluator2.evaluate(playerId, game);
|
||||
}
|
||||
|
||||
protected void simulateToEnd(Game game) {
|
||||
|
|
|
@ -5,16 +5,16 @@
|
|||
|
||||
package mage.player.ai;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.player.ai.ma.ArtificialScoringSystem;
|
||||
import mage.players.Player;
|
||||
import mage.util.Logging;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author nantuko
|
||||
|
|
|
@ -272,7 +272,14 @@ public class SimulatedPlayer2 extends ComputerPlayer<SimulatedPlayer2> {
|
|||
logger.debug("simulating -- attack:" + sim.getCombat().getGroups().size());
|
||||
}
|
||||
}
|
||||
return new ArrayList<Combat>(engagements.values());
|
||||
List list = new ArrayList<Combat>(engagements.values());
|
||||
Collections.sort(list, new Comparator<Combat>() {
|
||||
@Override
|
||||
public int compare(Combat o1, Combat o2) {
|
||||
return Integer.valueOf(o2.getGroups().size()).compareTo(Integer.valueOf(o1.getGroups().size()));
|
||||
}
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<Combat> addBlockers(Game game) {
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -4,7 +4,6 @@ import junit.framework.Assert;
|
|||
import mage.Constants;
|
||||
import mage.counters.Counter;
|
||||
import mage.counters.CounterType;
|
||||
import mage.game.GameImpl;
|
||||
import mage.game.permanent.Permanent;
|
||||
import org.junit.Test;
|
||||
import org.mage.test.serverside.base.CardTestBase;
|
||||
|
@ -37,8 +36,5 @@ public class LevelUpAbilityTest extends CardTestBase {
|
|||
Assert.assertNotNull(master.getCounters());
|
||||
Assert.assertFalse(master.getCounters().isEmpty());
|
||||
Assert.assertEquals(12, master.getCounters().getCount(CounterType.LEVEL));
|
||||
|
||||
System.out.println("Copy count: " + GameImpl.copyCount);
|
||||
System.out.println("Copy time: " + GameImpl.copyTime + " ms");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ public class DamageDistributionTest extends CardTestBase {
|
|||
|
||||
Permanent instigator = getPermanent("Warren Instigator", playerA.getId());
|
||||
Assert.assertNotNull(instigator);
|
||||
Assert.assertTrue("Computer didn't attacked with Warren Instigator", instigator.isTapped());
|
||||
|
||||
// should block and die
|
||||
assertPermanentCount(playerB, "Merfolk Looter", 0);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.mage.test.serverside.performance;
|
||||
|
||||
import mage.game.Game;
|
||||
import org.junit.Ignore;
|
||||
import org.mage.test.serverside.base.CardTestBase;
|
||||
|
||||
/**
|
||||
|
@ -8,6 +9,7 @@ import org.mage.test.serverside.base.CardTestBase;
|
|||
*
|
||||
* @ayratn
|
||||
*/
|
||||
@Ignore
|
||||
public class CopyGameStatePerformanceTest extends CardTestBase {
|
||||
|
||||
public void run() throws Exception {
|
||||
|
|
Loading…
Reference in a new issue