From e90ce893c54118415bda0b9f4e1234a2c17c4ef1 Mon Sep 17 00:00:00 2001 From: magenoxx Date: Wed, 20 Jun 2012 11:01:16 +0400 Subject: [PATCH] Changes in state evaluation (permanents more valuable). Fix in combat blocking. --- .../mage/player/ai/GameStateEvaluator2.java | 59 +++++++++++++++++++ .../src/mage/player/ai/util/CombatUtil.java | 8 ++- 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/GameStateEvaluator2.java b/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/GameStateEvaluator2.java index 6cc06e43d90..e956cf23d1c 100644 --- a/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/GameStateEvaluator2.java +++ b/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/GameStateEvaluator2.java @@ -24,6 +24,7 @@ import java.util.logging.Logger; */ public class GameStateEvaluator2 { +<<<<<<< HEAD private final static transient Logger logger = Logging.getLogger(GameStateEvaluator2.class.getName()); static { @@ -80,6 +81,64 @@ public class GameStateEvaluator2 { int score = lifeScore + permanentScore + handScore; //if (logger.isLoggable(Level.FINE)) logger.fine("game state evaluated to- lifeScore:" + lifeScore + " permanentScore:" + permanentScore /*+ " handScore:" + handScore*/ + "total:" + score); +======= + private final static transient Logger logger = Logging.getLogger(GameStateEvaluator2.class.getName()); + + static { + logger.setLevel(Level.ALL); + } + + public static final int WIN_GAME_SCORE = 100000000; + public static final int LOSE_GAME_SCORE = -WIN_GAME_SCORE; + + + private static final int LIFE_FACTOR = Config2.evaluatorLifeFactor; + private static final int PERMANENT_FACTOR = Config2.evaluatorPermanentFactor; + private static final int CREATURE_FACTOR = Config2.evaluatorCreatureFactor; + private static final int HAND_FACTOR = Config2.evaluatorHandFactor; + + public static int evaluate(UUID playerId, Game game) { + Player player = game.getPlayer(playerId); + Player opponent = game.getPlayer(game.getOpponents(playerId).iterator().next()); + if (game.isGameOver()) { + if (player.hasLost() || opponent.hasWon()) + return LOSE_GAME_SCORE; + if (opponent.hasLost() || player.hasWon()) + return WIN_GAME_SCORE; + } + //int lifeScore = (player.getLife() - opponent.getLife()) * LIFE_FACTOR; + + //int lifeScore = (ArtificialScoringSystem.getLifeScore(player.getLife()) - opponent.getLife()) * LIFE_FACTOR; + int lifeScore = 0; + if (player.getLife() <= 0) { // we don't want a tie + lifeScore = ArtificialScoringSystem.LOSE_GAME_SCORE; + } else if (opponent.getLife() <= 0) { + lifeScore = ArtificialScoringSystem.WIN_GAME_SCORE; + } else { + lifeScore = ArtificialScoringSystem.getLifeScore(player.getLife()) - ArtificialScoringSystem.getLifeScore(opponent.getLife()); + } + + int permanentScore = 0; + try { + for (Permanent permanent: game.getBattlefield().getAllActivePermanents(playerId)) { + permanentScore += 10 * evaluatePermanent(permanent, game); + } + for (Permanent permanent: game.getBattlefield().getAllActivePermanents(opponent.getId())) { + permanentScore -= evaluatePermanent(permanent, game); + } + } catch (Throwable t) { + t.printStackTrace(); + } + //permanentScore *= PERMANENT_FACTOR; + + int handScore = 0; + handScore = player.getHand().size() - opponent.getHand().size(); + handScore *= 2; + + int score = lifeScore + permanentScore + handScore; + //if (logger.isLoggable(Level.FINE)) + logger.fine("game state evaluated to- lifeScore:" + lifeScore + " permanentScore:" + permanentScore /*+ " handScore:" + handScore*/ + "total:" + score); +>>>>>>> Changes in state evaluation (permanents more valuable). Fix in combat blocking. return score; } diff --git a/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/util/CombatUtil.java b/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/util/CombatUtil.java index 1574d6bc3c2..67150c3ccfb 100644 --- a/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/util/CombatUtil.java +++ b/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/util/CombatUtil.java @@ -187,8 +187,12 @@ public class CombatUtil { for (Permanent blocker : possibleBlockers) { SurviveInfo info = willItSurvive(game, attackerId, defenderId, attacker, blocker); //if (info.isAttackerDied() && !info.isBlockerDied()) { - if (info.isAttackerDied()) { - blockers.add(blocker); + if (info != null) { + if (info.isAttackerDied()) { + blockers.add(blocker); + } else if (!info.isBlockerDied()) { + blockers.add(blocker); + } } } return blockers;