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;
|
beta = val;
|
||||||
bestNode = newNode;
|
bestNode = newNode;
|
||||||
bestNode.setScore(val);
|
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
|
// no need to check other actions
|
||||||
|
@ -517,11 +519,14 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
||||||
alpha = val;
|
alpha = val;
|
||||||
bestNode = newNode;
|
bestNode = newNode;
|
||||||
bestNode.setScore(val);
|
bestNode.setScore(val);
|
||||||
node.setCombat(newNode.getCombat());
|
if (newNode.getChildren().size() > 0) {
|
||||||
if (node.getTargets().size() > 0)
|
bestNode.setCombat(newNode.getChildren().get(0).getCombat());
|
||||||
|
}
|
||||||
|
/*if (node.getTargets().size() > 0)
|
||||||
targets = node.getTargets();
|
targets = node.getTargets();
|
||||||
if (node.getChoices().size() > 0)
|
if (node.getChoices().size() > 0)
|
||||||
choices = node.getChoices();
|
choices = node.getChoices();
|
||||||
|
*/
|
||||||
if (depth == maxDepth) {
|
if (depth == maxDepth) {
|
||||||
logger.info("saved");
|
logger.info("saved");
|
||||||
node.children.clear();
|
node.children.clear();
|
||||||
|
@ -813,6 +818,7 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
||||||
for (int i = 0; i < groups.size(); i++) {
|
for (int i = 0; i < groups.size(); i++) {
|
||||||
if (i < combat.getGroups().size()) {
|
if (i < combat.getGroups().size()) {
|
||||||
for (UUID blockerId: combat.getGroups().get(i).getBlockers()) {
|
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);
|
this.declareBlocker(blockerId, groups.get(i).getAttackers().get(0), game);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,7 @@ import mage.players.Player;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -184,6 +185,7 @@ public class ComputerPlayer7 extends ComputerPlayer6 implements Player {
|
||||||
//if (bestScore > currentScore || allowBadMoves) {
|
//if (bestScore > currentScore || allowBadMoves) {
|
||||||
actions = new LinkedList<Ability>(root.abilities);
|
actions = new LinkedList<Ability>(root.abilities);
|
||||||
combat = root.combat;
|
combat = root.combat;
|
||||||
|
logger.debug("final score: " + bestScore);
|
||||||
//} else {
|
//} else {
|
||||||
//System.out.println("[" + game.getPlayer(playerId).getName() + "][post] Action: not better score");
|
//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);
|
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 = GameStateEvaluator2.evaluate(playerId, game);
|
val = GameStateEvaluator2.evaluate(playerId, game);
|
||||||
break;
|
break;
|
||||||
|
@ -305,7 +307,7 @@ public class ComputerPlayer7 extends ComputerPlayer6 implements Player {
|
||||||
}
|
}
|
||||||
else if (!counter) {
|
else if (!counter) {
|
||||||
finishCombat(game);
|
finishCombat(game);
|
||||||
val = simulateCounterAttack(game, node, depth, alpha, beta);
|
///val = simulateCounterAttack(game, node, depth, alpha, beta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (val == null)
|
if (val == null)
|
||||||
|
@ -329,6 +331,9 @@ public class ComputerPlayer7 extends ComputerPlayer6 implements Player {
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
logger.debug(attacker.getName() + "'s possible attackers: " + attacker.getAvailableAttackers(game));
|
logger.debug(attacker.getName() + "'s possible attackers: " + attacker.getAvailableAttackers(game));
|
||||||
for (Combat engagement: attacker.addAttackers(game)) {
|
for (Combat engagement: attacker.addAttackers(game)) {
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
|
logger.debug("Attackers: " + engagement.getAttackers() + ", blockers: " + engagement.getBlockers());
|
||||||
|
}
|
||||||
if (alpha >= beta) {
|
if (alpha >= beta) {
|
||||||
logger.debug("simulating -- pruning attackers");
|
logger.debug("simulating -- pruning attackers");
|
||||||
break;
|
break;
|
||||||
|
@ -359,7 +364,9 @@ public class ComputerPlayer7 extends ComputerPlayer6 implements Player {
|
||||||
beta = val;
|
beta = val;
|
||||||
bestNode = newNode;
|
bestNode = newNode;
|
||||||
bestNode.setScore(val);
|
bestNode.setScore(val);
|
||||||
node.setCombat(simCombat);
|
if (newNode.getChildren().size() > 0) {
|
||||||
|
bestNode.setCombat(newNode.getChildren().get(0).getCombat());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -367,7 +374,9 @@ public class ComputerPlayer7 extends ComputerPlayer6 implements Player {
|
||||||
alpha = val;
|
alpha = val;
|
||||||
bestNode = newNode;
|
bestNode = newNode;
|
||||||
bestNode.setScore(val);
|
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);
|
SimulatedPlayer2 defender = (SimulatedPlayer2) game.getPlayer(defenderId);
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
logger.debug(defender.getName() + "'s possible blockers: " + defender.getAvailableBlockers(game));
|
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) {
|
if (alpha >= beta) {
|
||||||
logger.debug("simulating -- pruning blockers");
|
logger.debug("simulating -- pruning blockers");
|
||||||
break;
|
break;
|
||||||
|
@ -436,14 +446,15 @@ public class ComputerPlayer7 extends ComputerPlayer6 implements Player {
|
||||||
beta = val;
|
beta = val;
|
||||||
bestNode = newNode;
|
bestNode = newNode;
|
||||||
bestNode.setScore(val);
|
bestNode.setScore(val);
|
||||||
node.setCombat(simCombat);
|
bestNode.setCombat(simCombat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (val > alpha) {
|
if (val > alpha) {
|
||||||
alpha = val;
|
alpha = val;
|
||||||
bestNode = newNode;
|
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();
|
game.getPlayers().resetPassed();
|
||||||
return addActions(node, depth, alpha, beta);
|
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) {
|
protected void simulateToEnd(Game game) {
|
||||||
|
|
|
@ -5,16 +5,16 @@
|
||||||
|
|
||||||
package mage.player.ai;
|
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.Game;
|
||||||
import mage.game.permanent.Permanent;
|
import mage.game.permanent.Permanent;
|
||||||
import mage.player.ai.ma.ArtificialScoringSystem;
|
import mage.player.ai.ma.ArtificialScoringSystem;
|
||||||
import mage.players.Player;
|
import mage.players.Player;
|
||||||
import mage.util.Logging;
|
import mage.util.Logging;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author nantuko
|
* @author nantuko
|
||||||
|
@ -80,7 +80,7 @@ public class GameStateEvaluator2 {
|
||||||
int score = lifeScore + permanentScore + handScore;
|
int score = lifeScore + permanentScore + handScore;
|
||||||
//if (logger.isLoggable(Level.FINE))
|
//if (logger.isLoggable(Level.FINE))
|
||||||
logger.fine("game state evaluated to- lifeScore:" + lifeScore + " permanentScore:" + permanentScore /*+ " handScore:" + handScore*/ + "total:" + score);
|
logger.fine("game state evaluated to- lifeScore:" + lifeScore + " permanentScore:" + permanentScore /*+ " handScore:" + handScore*/ + "total:" + score);
|
||||||
return score;
|
return score;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int evaluatePermanent(Permanent permanent, Game game) {
|
public static int evaluatePermanent(Permanent permanent, Game game) {
|
||||||
|
|
|
@ -272,7 +272,14 @@ public class SimulatedPlayer2 extends ComputerPlayer<SimulatedPlayer2> {
|
||||||
logger.debug("simulating -- attack:" + sim.getCombat().getGroups().size());
|
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) {
|
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.Constants;
|
||||||
import mage.counters.Counter;
|
import mage.counters.Counter;
|
||||||
import mage.counters.CounterType;
|
import mage.counters.CounterType;
|
||||||
import mage.game.GameImpl;
|
|
||||||
import mage.game.permanent.Permanent;
|
import mage.game.permanent.Permanent;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mage.test.serverside.base.CardTestBase;
|
import org.mage.test.serverside.base.CardTestBase;
|
||||||
|
@ -37,8 +36,5 @@ public class LevelUpAbilityTest extends CardTestBase {
|
||||||
Assert.assertNotNull(master.getCounters());
|
Assert.assertNotNull(master.getCounters());
|
||||||
Assert.assertFalse(master.getCounters().isEmpty());
|
Assert.assertFalse(master.getCounters().isEmpty());
|
||||||
Assert.assertEquals(12, master.getCounters().getCount(CounterType.LEVEL));
|
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());
|
Permanent instigator = getPermanent("Warren Instigator", playerA.getId());
|
||||||
Assert.assertNotNull(instigator);
|
Assert.assertNotNull(instigator);
|
||||||
|
Assert.assertTrue("Computer didn't attacked with Warren Instigator", instigator.isTapped());
|
||||||
|
|
||||||
// should block and die
|
// should block and die
|
||||||
assertPermanentCount(playerB, "Merfolk Looter", 0);
|
assertPermanentCount(playerB, "Merfolk Looter", 0);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package org.mage.test.serverside.performance;
|
package org.mage.test.serverside.performance;
|
||||||
|
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
|
import org.junit.Ignore;
|
||||||
import org.mage.test.serverside.base.CardTestBase;
|
import org.mage.test.serverside.base.CardTestBase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -8,6 +9,7 @@ import org.mage.test.serverside.base.CardTestBase;
|
||||||
*
|
*
|
||||||
* @ayratn
|
* @ayratn
|
||||||
*/
|
*/
|
||||||
|
@Ignore
|
||||||
public class CopyGameStatePerformanceTest extends CardTestBase {
|
public class CopyGameStatePerformanceTest extends CardTestBase {
|
||||||
|
|
||||||
public void run() throws Exception {
|
public void run() throws Exception {
|
||||||
|
|
Loading…
Reference in a new issue