diff --git a/Mage.Server.Plugins/Mage.Player.AIMCTS/src/mage/player/ai/MCTSNode.java b/Mage.Server.Plugins/Mage.Player.AIMCTS/src/mage/player/ai/MCTSNode.java index 15f8a5b4e76..0b4fb0a73e4 100644 --- a/Mage.Server.Plugins/Mage.Player.AIMCTS/src/mage/player/ai/MCTSNode.java +++ b/Mage.Server.Plugins/Mage.Player.AIMCTS/src/mage/player/ai/MCTSNode.java @@ -61,6 +61,7 @@ public class MCTSNode { private List children = new ArrayList(); private Ability action; private Game game; + private Combat combat; private String stateValue; private UUID playerId; private boolean terminal = false; @@ -85,8 +86,9 @@ public class MCTSNode { nodeCount++; } - protected MCTSNode(MCTSNode parent, Game game) { + protected MCTSNode(MCTSNode parent, Game game, Combat combat) { this.game = game; + this.combat = combat; this.stateValue = game.getState().getValue(false, game); this.terminal = game.isGameOver(); this.parent = parent; @@ -147,7 +149,6 @@ public class MCTSNode { sim.resume(); children.add(new MCTSNode(this, sim, ability)); } - game = null; break; case SELECT_ATTACKERS: // logger.info("Select attackers:" + player.getName()); @@ -160,7 +161,7 @@ public class MCTSNode { simPlayer.declareAttacker(attackerId, defenderId, sim); } sim.resume(); - children.add(new MCTSNode(this, sim)); + children.add(new MCTSNode(this, sim, sim.getCombat())); } break; case SELECT_BLOCKERS: @@ -178,10 +179,11 @@ public class MCTSNode { } } sim.resume(); - children.add(new MCTSNode(this, sim)); + children.add(new MCTSNode(this, sim, sim.getCombat())); } break; } + game = null; } public int simulate(UUID playerId) { @@ -269,7 +271,7 @@ public class MCTSNode { } public Combat getCombat() { - return game.getCombat(); + return combat; } public int getNodeCount() { @@ -340,9 +342,11 @@ public class MCTSNode { } public boolean isWinner(UUID playerId) { - Player player = game.getPlayer(playerId); - if (player != null && player.hasWon()) - return true; + if (game != null) { + Player player = game.getPlayer(playerId); + if (player != null && player.hasWon()) + return true; + } return false; } @@ -399,7 +403,7 @@ public class MCTSNode { } } else { - if (mergeChild.game.getCombat().getValue().equals(child.game.getCombat().getValue())) { + if (mergeChild.combat.getValue().equals(child.combat.getValue())) { if (!mergeChild.stateValue.equals(child.stateValue)) { logger.info("mismatched merge states"); mergeChildren.remove(mergeChild); @@ -421,18 +425,18 @@ public class MCTSNode { } } - public void print(int depth) { - String indent = String.format("%1$-" + depth + "s", ""); - StringBuilder sb = new StringBuilder(); - MCTSPlayer player = (MCTSPlayer) game.getPlayer(playerId); - sb.append(indent).append(player.getName()).append(" ").append(visits).append(":").append(wins).append(" - "); - if (action != null) - sb.append(action.toString()); - System.out.println(sb.toString()); - for (MCTSNode child: children) { - child.print(depth + 1); - } - } +// public void print(int depth) { +// String indent = String.format("%1$-" + depth + "s", ""); +// StringBuilder sb = new StringBuilder(); +// MCTSPlayer player = (MCTSPlayer) game.getPlayer(playerId); +// sb.append(indent).append(player.getName()).append(" ").append(visits).append(":").append(wins).append(" - "); +// if (action != null) +// sb.append(action.toString()); +// System.out.println(sb.toString()); +// for (MCTSNode child: children) { +// child.print(depth + 1); +// } +// } public int size() { int num = 1; diff --git a/Mage.Server.Plugins/Mage.Player.AIMCTS/src/mage/player/ai/SimulatedPlayerMCTS.java b/Mage.Server.Plugins/Mage.Player.AIMCTS/src/mage/player/ai/SimulatedPlayerMCTS.java index 27182d89fae..f1187606dc4 100644 --- a/Mage.Server.Plugins/Mage.Player.AIMCTS/src/mage/player/ai/SimulatedPlayerMCTS.java +++ b/Mage.Server.Plugins/Mage.Player.AIMCTS/src/mage/player/ai/SimulatedPlayerMCTS.java @@ -310,26 +310,26 @@ public class SimulatedPlayerMCTS extends MCTSPlayer { @Override public boolean chooseTarget(Outcome outcome, Target target, Ability source, Game game) { - if (this.isHuman()) +// if (this.isHuman()) return chooseRandomTarget(target, source, game); - return super.chooseTarget(outcome, target, source, game); +// return super.chooseTarget(outcome, target, source, game); } @Override public boolean chooseTarget(Outcome outcome, Cards cards, TargetCard target, Ability source, Game game) { - if (this.isHuman()) { +// if (this.isHuman()) { if (cards.isEmpty()) return !target.isRequired(); Card card = cards.getRandom(game); target.addTarget(card.getId(), source, game); return true; - } - return super.chooseTarget(outcome, cards, target, source, game); +// } +// return super.chooseTarget(outcome, cards, target, source, game); } @Override public boolean chooseTargetAmount(Outcome outcome, TargetAmount target, Ability source, Game game) { - if (this.isHuman()) { +// if (this.isHuman()) { Set possibleTargets = target.possibleTargets(source==null?null:source.getSourceId(), playerId, game); if (possibleTargets.isEmpty()) return !target.isRequired(); @@ -350,8 +350,8 @@ public class SimulatedPlayerMCTS extends MCTSPlayer { } target.addTarget(targetId, rnd.nextInt(target.getAmountRemaining()) + 1, source, game); return true; - } - return super.chooseTargetAmount(outcome, target, source, game); +// } +// return super.chooseTargetAmount(outcome, target, source, game); } @Override diff --git a/Mage.Server/config/config.xml b/Mage.Server/config/config.xml index 3703d1642ae..928761f7cb0 100644 --- a/Mage.Server/config/config.xml +++ b/Mage.Server/config/config.xml @@ -6,7 +6,7 @@ - + diff --git a/Mage.Server/plugins/mage-player-aimcts.jar b/Mage.Server/plugins/mage-player-aimcts.jar index d45723969c2..94c424de3a0 100644 Binary files a/Mage.Server/plugins/mage-player-aimcts.jar and b/Mage.Server/plugins/mage-player-aimcts.jar differ