public List<Ability> simulatePriority(Game game) { allActions = new ConcurrentLinkedQueue<>(); Game sim = game.copy(); simulateOptions(sim, pass); ArrayList<Ability> list = new ArrayList<>(allActions); //Collections.shuffle(list); Collections.reverse(list); return list; }
public List<Combat> addBlockers(Game game) { Map<Integer, Combat> engagements = new HashMap<>(); int numGroups = game.getCombat().getGroups().size(); if (numGroups == 0) return new ArrayList<>(); //add a node with no blockers Game sim = game.copy(); engagements.put(sim.getCombat().getValue().hashCode(), sim.getCombat()); sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARED_BLOCKERS, playerId, playerId)); List<Permanent> blockers = getAvailableBlockers(game); addBlocker(game, blockers, engagements); return new ArrayList<>(engagements.values()); }
public List<Combat> addBlockers(Game game) { Map<Integer, Combat> engagements = new HashMap<>(); int numGroups = game.getCombat().getGroups().size(); if (numGroups == 0) { return Collections.emptyList(); } //add a node with no blockers Game sim = game.copy(); engagements.put(sim.getCombat().getValue().hashCode(), sim.getCombat()); sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARED_BLOCKERS, playerId, playerId)); List<Permanent> blockers = getAvailableBlockers(game); addBlocker(game, blockers, engagements); return new ArrayList<>(engagements.values()); }
StringBuilder binary = new StringBuilder(); for (int i = powerElements - 1; i >= 0; i--) { Game sim = game.copy(); binary.setLength(0); binary.append(Integer.toBinaryString(i));
public List<Ability> simulatePriority(Game game) { allActions = new ConcurrentLinkedQueue<>(); Game sim = game.copy(); sim.setSimulation(true); forced = false; simulateOptions(sim); ArrayList<Ability> list = new ArrayList<>(allActions); Collections.reverse(list); if (!forced) { list.add(pass); } if (logger.isTraceEnabled()) { for (Ability a : allActions) { logger.info("ability==" + a); if (!a.getTargets().isEmpty()) { MageObject mageObject = game.getObject(a.getFirstTarget()); if (mageObject != null) { logger.info(" target=" + mageObject.getName()); } else { Player player = game.getPlayer(a.getFirstTarget()); if (player != null) { logger.info(" target=" + player.getName()); } } } } } return list; }
protected void addBlocker(Game game, List<Permanent> blockers, Map<Integer, Combat> engagements) { if (blockers.isEmpty()) return; int numGroups = game.getCombat().getGroups().size(); //try to block each attacker with each potential blocker Permanent blocker = blockers.get(0); if (logger.isDebugEnabled()) logger.debug("simulating -- block:" + blocker); List<Permanent> remaining = remove(blockers, blocker); for (int i = 0; i < numGroups; i++) { if (game.getCombat().getGroups().get(i).canBlock(blocker, game)) { Game sim = game.copy(); sim.getCombat().getGroups().get(i).addBlocker(blocker.getId(), playerId, sim); if (engagements.put(sim.getCombat().getValue().hashCode(), sim.getCombat()) != null) logger.debug("simulating -- found redundant block combination"); addBlocker(sim, remaining, engagements); // and recurse minus the used blocker } } addBlocker(game, remaining, engagements); }
protected void addBlocker(Game game, List<Permanent> blockers, Map<Integer, Combat> engagements) { if (blockers.isEmpty()) { return; } int numGroups = game.getCombat().getGroups().size(); //try to block each attacker with each potential blocker Permanent blocker = blockers.get(0); logger.debug("simulating -- block:" + blocker); List<Permanent> remaining = remove(blockers, blocker); for (int i = 0; i < numGroups; i++) { if (game.getCombat().getGroups().get(i).canBlock(blocker, game)) { Game sim = game.copy(); sim.getCombat().getGroups().get(i).addBlocker(blocker.getId(), playerId, sim); if (engagements.put(sim.getCombat().getValue().hashCode(), sim.getCombat()) != null) { logger.debug("simulating -- found redundant block combination"); } addBlocker(sim, remaining, engagements); // and recurse minus the used blocker } } addBlocker(game, remaining, engagements); }
protected void addAbilityNode(SimulationNode2 parent, Ability ability, int depth, Game game) { Game sim = game.copy(); sim.getStack().push(new StackAbility(ability, playerId)); if (ability.activate(sim, false) && ability.isUsesStack()) { game.fireEvent(new GameEvent(GameEvent.EventType.TRIGGERED_ABILITY, ability.getId(), ability.getSourceId(), ability.getControllerId())); } sim.applyEffects(); SimulationNode2 newNode = new SimulationNode2(parent, sim, depth, playerId); logger.debug("simulating -- node #:" + SimulationNode2.getCount() + " triggered ability option"); for (Target target : ability.getTargets()) { for (UUID targetId : target.getTargets()) { newNode.getTargets().add(targetId); } } parent.children.add(newNode); }
/** * Copies game and replaces all players in copy with simulated players * * @param game * @return a new game object with simulated players */ protected Game createSimulation(Game game) { Game sim = game.copy(); sim.setSimulation(true); for (Player copyPlayer : sim.getState().getPlayers().values()) { Player origPlayer = game.getState().getPlayers().get(copyPlayer.getId()).copy(); if (!suggested.isEmpty()) { logger.debug(origPlayer.getName() + " suggested: " + suggested); } SimulatedPlayer2 newPlayer = new SimulatedPlayer2(copyPlayer.getId(), copyPlayer.getId().equals(playerId), suggested); newPlayer.restore(origPlayer); sim.getState().getPlayers().put(copyPlayer.getId(), newPlayer); } return sim; }
protected void addAbilityNode(SimulationNode parent, Ability ability, Game game) { Game sim = game.copy(); sim.getStack().push(new StackAbility(ability, playerId)); ability.activate(sim, false); if (ability.activate(sim, false) && ability.isUsesStack()) { game.fireEvent(new GameEvent(GameEvent.EventType.TRIGGERED_ABILITY, ability.getId(), ability.getSourceId(), ability.getControllerId())); } sim.applyEffects(); SimulationNode newNode = new SimulationNode(parent, sim, playerId); logger.debug(indent(newNode.getDepth()) + "simulating -- node #:" + SimulationNode.getCount() + " triggered ability option"); for (Target target: ability.getTargets()) { for (UUID targetId: target.getTargets()) { newNode.getTargets().add(targetId); } } parent.children.add(newNode); }
/** * Copies game and replaces all players in copy with simulated players * * @param game * @return a new game object with simulated players */ protected Game createSimulation(Game game) { Game sim = game.copy(); for (Player copyPlayer: sim.getState().getPlayers().values()) { Player origPlayer = game.getState().getPlayers().get(copyPlayer.getId()).copy(); SimulatedPlayer newPlayer = new SimulatedPlayer(copyPlayer.getId(), copyPlayer.getId().equals(playerId), maxDepth); newPlayer.restore(origPlayer); sim.getState().getPlayers().put(copyPlayer.getId(), newPlayer); } sim.setSimulation(true); return sim; }
protected void resolve(SimulationNode node, Game game) { StackObject ability = game.getStack().pop(); if (ability instanceof StackAbility) { SearchEffect effect = getSearchEffect((StackAbility) ability); if (effect != null && ability.getControllerId().equals(playerId)) { Target target = effect.getTarget(); if (!target.doneChosing()) { for (UUID targetId: target.possibleTargets(ability.getSourceId(), ability.getControllerId(), game)) { Game sim = game.copy(); StackAbility newAbility = (StackAbility) ability.copy(); SearchEffect newEffect = getSearchEffect((StackAbility) newAbility); newEffect.getTarget().addTarget(targetId, newAbility, sim); sim.getStack().push(newAbility); SimulationNode newNode = new SimulationNode(node, sim, ability.getControllerId()); node.children.add(newNode); newNode.getTargets().add(targetId); logger.debug(indent(node.depth) + "simulating search -- node#: " + SimulationNode.getCount() + "for player: " + sim.getPlayer(ability.getControllerId()).getName()); } return; } } } logger.debug(indent(node.depth) + "simulating resolve "); ability.resolve(game); game.applyEffects(); game.getPlayers().resetPassed(); game.getPlayerList().setCurrent(game.getActivePlayerId()); }
return false; if (action.isUsesStack()) { Game testSim = sim.copy(); StackObject ability = testSim.getStack().pop(); ability.resolve(testSim);
if (!target.doneChosing()) { for (UUID targetId : target.possibleTargets(stackObject.getSourceId(), stackObject.getControllerId(), game)) { Game sim = game.copy(); StackAbility newAbility = (StackAbility) stackObject.copy(); SearchEffect newEffect = getSearchEffect(newAbility);
int count = Integer.parseInt(numberChoice.getChoice()); if (player.getLibrary().count(filter, game) == count) { player.damage(8, source.getSourceId(), game.copy(), false, true);
/** * Copies game and replaces all players in copy with simulated players * Shuffles each players library so that there is no knowledge of its order * * @param game * @return a new game object with simulated players */ protected Game createSimulation(Game game, UUID playerId) { Game sim = game.copy(); for (Player copyPlayer: sim.getState().getPlayers().values()) { Player origPlayer = game.getState().getPlayers().get(copyPlayer.getId()).copy(); SimulatedPlayerMCTS newPlayer = new SimulatedPlayerMCTS(copyPlayer.getId(), true); newPlayer.restore(origPlayer); sim.getState().getPlayers().put(copyPlayer.getId(), newPlayer); } randomizePlayers(sim, playerId); sim.setSimulation(true); return sim; }
public static SurviveInfo getCombatInfo(Game game, UUID attackingPlayerId, UUID defendingPlayerId, Permanent attacker) { Game sim = game.copy(); Combat combat = sim.getCombat(); combat.setAttacker(attackingPlayerId); combat.setDefenders(sim); UUID defenderId = sim.getCombat().getDefenders().iterator().next(); boolean triggered = false; sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARED_BLOCKERS, defendingPlayerId, defendingPlayerId)); sim.checkStateAndTriggered(); while (!sim.getStack().isEmpty()) { triggered = true; sim.getStack().resolve(sim); sim.applyEffects(); } sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARE_BLOCKERS_STEP_POST, sim.getActivePlayerId(), sim.getActivePlayerId())); simulateStep(sim, new FirstCombatDamageStep()); simulateStep(sim, new CombatDamageStep()); simulateStep(sim, new EndOfCombatStep()); // The following commented out call produces random freezes. //sim.checkStateAndTriggered(); while (!sim.getStack().isEmpty()) { triggered = true; sim.getStack().resolve(sim); sim.applyEffects(); } return new SurviveInfo(!sim.getBattlefield().containsPermanent(attacker.getId()), false, sim.getPlayer(defenderId), triggered); }
Game mcts = game.copy();
public static SurviveInfo willItSurvive2(Game game, UUID attackingPlayerId, UUID defendingPlayerId, Permanent attacker, Permanent blocker) { Game sim = game.copy();
public static SurviveInfo willItSurvive(Game game, UUID attackingPlayerId, UUID defendingPlayerId, Permanent attacker, Permanent blocker) { Game sim = game.copy(); Combat combat = sim.getCombat(); combat.setAttacker(attackingPlayerId); combat.setDefenders(sim); if (blocker == null || attacker == null || sim.getPlayer(defendingPlayerId) == null) { return null; } sim.getPlayer(defendingPlayerId).declareBlocker(defendingPlayerId, blocker.getId(), attacker.getId(), sim); sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARED_BLOCKERS, defendingPlayerId, defendingPlayerId)); sim.checkStateAndTriggered(); while (!sim.getStack().isEmpty()) { sim.getStack().resolve(sim); sim.applyEffects(); } sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARE_BLOCKERS_STEP_POST, sim.getActivePlayerId(), sim.getActivePlayerId())); simulateStep(sim, new FirstCombatDamageStep()); simulateStep(sim, new CombatDamageStep()); simulateStep(sim, new EndOfCombatStep()); // The following commented out call produces random freezes. //sim.checkStateAndTriggered(); while (!sim.getStack().isEmpty()) { sim.getStack().resolve(sim); sim.applyEffects(); } return new SurviveInfo(!sim.getBattlefield().containsPermanent(attacker.getId()), !sim.getBattlefield().containsPermanent(blocker.getId())); }