use of mage.game.permanent.Permanent 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.permanent.Permanent 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.permanent.Permanent in project mage by magefree.
the class SimulatedPlayerMCTS method assignDamage.
@Override
public void assignDamage(int damage, List<UUID> targets, String singleTargetName, UUID attackerId, Ability source, Game game) {
if (this.isHuman()) {
int remainingDamage = damage;
UUID targetId;
int amount;
while (remainingDamage > 0) {
if (targets.size() == 1) {
targetId = targets.get(0);
amount = remainingDamage;
} else {
targetId = targets.get(RandomUtil.nextInt(targets.size()));
amount = RandomUtil.nextInt(damage + 1);
}
Permanent permanent = game.getPermanent(targetId);
if (permanent != null) {
permanent.damage(amount, attackerId, source, game, false, true);
remainingDamage -= amount;
} else {
Player player = game.getPlayer(targetId);
if (player != null) {
player.damage(amount, attackerId, source, game);
remainingDamage -= amount;
}
}
targets.remove(targetId);
}
} else {
super.assignDamage(damage, targets, singleTargetName, attackerId, source, game);
}
}
use of mage.game.permanent.Permanent in project mage by magefree.
the class SimulatedPlayer method addBlocker.
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");
// and recurse minus the used blocker
addBlocker(sim, remaining, engagements);
}
}
addBlocker(game, remaining, engagements);
}
use of mage.game.permanent.Permanent in project mage by magefree.
the class SimulatedPlayer method addAttackers.
/*@Override
public boolean playXMana(VariableManaCost cost, ManaCosts<ManaCost> costs, Game game) {
//simulateVariableCosts method adds a generic mana cost for each option
for (ManaCost manaCost: costs) {
if (manaCost instanceof GenericManaCost) {
cost.setPayment(manaCost.getPayment());
logger.debug("simulating -- X = " + cost.getPayment().count());
break;
}
}
cost.setPaid();
return true;
}*/
public List<Combat> addAttackers(Game game) {
Map<Integer, Combat> engagements = new HashMap<>();
// useful only for two player games - will only attack first opponent
UUID defenderId = game.getOpponents(playerId).iterator().next();
List<Permanent> attackersList = super.getAvailableAttackers(defenderId, game);
// use binary digits to calculate powerset of attackers
int powerElements = (int) Math.pow(2, attackersList.size());
StringBuilder binary = new StringBuilder();
for (int i = powerElements - 1; i >= 0; i--) {
Game sim = game.copy();
binary.setLength(0);
binary.append(Integer.toBinaryString(i));
while (binary.length() < attackersList.size()) {
binary.insert(0, '0');
}
for (int j = 0; j < attackersList.size(); j++) {
if (binary.charAt(j) == '1') {
// makes it possible to UNDO a declared attacker with costs from e.g. Propaganda
setStoredBookmark(sim.bookmarkState());
if (!sim.getCombat().declareAttacker(attackersList.get(j).getId(), defenderId, playerId, sim)) {
sim.undo(playerId);
}
}
}
if (engagements.put(sim.getCombat().getValue().hashCode(), sim.getCombat()) != null) {
logger.debug("simulating -- found redundant attack combination");
} else if (logger.isDebugEnabled()) {
logger.debug("simulating -- attack:" + sim.getCombat().getGroups().size());
}
}
return new ArrayList<>(engagements.values());
}
Aggregations