use of mage.game.combat.CombatGroup in project mage by magefree.
the class ComputerPlayer method selectBlockers.
@Override
public void selectBlockers(Ability source, Game game, UUID defendingPlayerId) {
log.debug("selectBlockers");
List<Permanent> blockers = getAvailableBlockers(game);
CombatSimulator sim = simulateBlock(CombatSimulator.load(game), blockers, game);
List<CombatGroup> groups = game.getCombat().getGroups();
for (int i = 0; i < groups.size(); i++) {
for (CreatureSimulator creature : sim.groups.get(i).blockers) {
groups.get(i).addBlocker(creature.id, playerId, game);
}
}
}
use of mage.game.combat.CombatGroup in project mage by magefree.
the class ComputerPlayerMCTS method selectBlockers.
@Override
public void selectBlockers(Ability source, Game game, UUID defendingPlayerId) {
StringBuilder sb = new StringBuilder();
sb.append(game.getTurn().getValue(game.getTurnNum())).append(" player ").append(name).append(" blocking: ");
getNextAction(game, NextAction.SELECT_BLOCKERS);
Combat simulatedCombat = root.getCombat();
List<CombatGroup> currentGroups = game.getCombat().getGroups();
for (int i = 0; i < currentGroups.size(); i++) {
if (i < simulatedCombat.getGroups().size()) {
CombatGroup currentGroup = currentGroups.get(i);
CombatGroup simulatedGroup = simulatedCombat.getGroups().get(i);
sb.append(game.getPermanent(currentGroup.getAttackers().get(0)).getName()).append(" with: ");
for (UUID blockerId : simulatedGroup.getBlockers()) {
// blockers can be added automaticly by requirement effects, so we must add only missing blockers
if (!currentGroup.getBlockers().contains(blockerId)) {
this.declareBlocker(this.getId(), blockerId, currentGroup.getAttackers().get(0), game);
sb.append(game.getPermanent(blockerId).getName()).append(',');
}
}
sb.append('|');
}
}
logger.info(sb.toString());
MCTSNode.logHitMiss();
}
use of mage.game.combat.CombatGroup in project mage by magefree.
the class SimulatedPlayerMCTS method selectBlockers.
@Override
public void selectBlockers(Ability source, Game game, UUID defendingPlayerId) {
// logger.info("select blockers");
int numGroups = game.getCombat().getGroups().size();
if (numGroups == 0) {
return;
}
List<Permanent> blockers = getAvailableBlockers(game);
for (Permanent blocker : blockers) {
int check = RandomUtil.nextInt(numGroups + 1);
if (check < numGroups) {
CombatGroup group = game.getCombat().getGroups().get(check);
if (!group.getAttackers().isEmpty()) {
this.declareBlocker(this.getId(), blocker.getId(), group.getAttackers().get(0), game);
}
}
}
actionCount++;
}
use of mage.game.combat.CombatGroup in project mage by magefree.
the class ComputerPlayer3 method simulateBlockers.
protected int simulateBlockers(Game game, SimulationNode node, UUID defenderId, int alpha, int beta, boolean counter) {
if (Thread.interrupted()) {
Thread.currentThread().interrupt();
logger.debug(indent(node.depth) + "interrupted");
return GameStateEvaluator.evaluate(playerId, game);
}
Integer val = null;
SimulationNode bestNode = null;
// check if defender is being attacked
if (game.getCombat().isAttacked(defenderId, game)) {
SimulatedPlayer defender = (SimulatedPlayer) game.getPlayer(defenderId);
if (logger.isDebugEnabled()) {
logger.debug(indent(node.depth) + defender.getName() + "'s possible blockers: " + defender.getAvailableBlockers(game));
}
for (Combat engagement : defender.addBlockers(game)) {
if (alpha >= beta) {
logger.debug(indent(node.depth) + "simulating -- pruning blockers");
break;
}
Game sim = game.copy();
for (CombatGroup group : engagement.getGroups()) {
if (!group.getAttackers().isEmpty()) {
UUID attackerId = group.getAttackers().get(0);
for (UUID blockerId : group.getBlockers()) {
sim.getPlayer(defenderId).declareBlocker(defenderId, blockerId, attackerId, sim);
}
}
}
sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARED_BLOCKERS, defenderId, defenderId));
SimulationNode newNode = new SimulationNode(node, sim, defenderId);
if (logger.isDebugEnabled()) {
logger.debug(indent(node.depth) + "simulating block for player:" + game.getPlayer(defenderId).getName());
}
sim.checkStateAndTriggered();
while (!sim.getStack().isEmpty()) {
sim.getStack().resolve(sim);
logger.debug(indent(node.depth) + "resolving triggered abilities");
sim.applyEffects();
}
sim.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARE_BLOCKERS_STEP_POST, sim.getActivePlayerId(), sim.getActivePlayerId()));
Combat simCombat = sim.getCombat().copy();
finishCombat(sim);
if (sim.checkIfGameIsOver()) {
val = GameStateEvaluator.evaluate(playerId, sim);
} else if (!counter) {
val = simulatePostCombatMain(sim, newNode, alpha, beta);
} else
val = GameStateEvaluator.evaluate(playerId, sim);
if (!defenderId.equals(playerId)) {
if (val < beta) {
beta = val;
bestNode = newNode;
node.setCombat(simCombat);
}
} else {
if (val > alpha) {
alpha = val;
bestNode = newNode;
node.setCombat(simCombat);
}
}
}
}
if (val == null)
val = GameStateEvaluator.evaluate(playerId, game);
if (bestNode != null) {
node.children.clear();
node.children.add(bestNode);
}
if (logger.isDebugEnabled())
logger.debug(indent(node.depth) + "returning -- combat blocker score: " + val + " depth:" + node.depth + " for player:" + game.getPlayer(node.getPlayerId()).getName());
return val;
}
use of mage.game.combat.CombatGroup in project mage by magefree.
the class ImprisonUnblockEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent enchantment = game.getPermanent(source.getSourceId());
if (enchantment != null && enchantment.getAttachedTo() != null) {
Permanent permanent = game.getPermanent(enchantment.getAttachedTo());
if (permanent != null) {
if (permanent.isCreature(game)) {
// Tap the creature
permanent.tap(source, game);
// Remove it from combat
Effect effect = new RemoveFromCombatTargetEffect();
effect.setTargetPointer(new FixedTarget(permanent, game));
effect.apply(game, source);
// Make blocked creatures unblocked
BlockedByOnlyOneCreatureThisCombatWatcher watcher = game.getState().getWatcher(BlockedByOnlyOneCreatureThisCombatWatcher.class);
if (watcher != null) {
Set<CombatGroup> combatGroups = watcher.getBlockedOnlyByCreature(permanent.getId());
if (combatGroups != null) {
for (CombatGroup combatGroup : combatGroups) {
if (combatGroup != null) {
combatGroup.setBlocked(false, game);
}
}
}
}
return true;
}
}
}
return false;
}
Aggregations