Ejemplo n.º 1
0
 @Override
 public void assignDamage(
     int damage, List<UUID> targets, String singleTargetName, UUID sourceId, Game game) {
   int remainingDamage = damage;
   UUID targetId;
   int amount;
   while (remainingDamage > 0) {
     if (targets.size() == 1) {
       targetId = targets.get(0);
       amount = remainingDamage;
     } else {
       targetId = targets.get(rnd.nextInt(targets.size()));
       amount = rnd.nextInt(damage + 1);
     }
     Permanent permanent = game.getPermanent(targetId);
     if (permanent != null) {
       permanent.damage(amount, sourceId, game, true, false);
       remainingDamage -= amount;
     } else {
       Player player = game.getPlayer(targetId);
       if (player != null) {
         player.damage(amount, sourceId, game, false, true);
         remainingDamage -= amount;
       }
     }
     targets.remove(targetId);
   }
 }
Ejemplo n.º 2
0
 @Override
 public void selectAttackers(Game game, UUID attackingPlayerId) {
   // useful only for two player games - will only attack first opponent
   UUID defenderId = game.getOpponents(playerId).iterator().next();
   List<Permanent> attackersList = super.getAvailableAttackers(game);
   // use binary digits to calculate powerset of attackers
   int powerElements = (int) Math.pow(2, attackersList.size());
   int value = rnd.nextInt(powerElements);
   StringBuilder binary = new StringBuilder();
   binary.append(Integer.toBinaryString(value));
   while (binary.length() < attackersList.size()) {
     binary.insert(0, "0"); // pad with zeros
   }
   for (int i = 0; i < attackersList.size(); i++) {
     if (binary.charAt(i) == '1')
       game.getCombat().declareAttacker(attackersList.get(i).getId(), defenderId, game);
   }
   actionCount++;
 }
Ejemplo n.º 3
0
 @Override
 public boolean triggerAbility(TriggeredAbility source, Game game) {
   if (source != null && source.canChooseTarget(game)) {
     Ability ability;
     List<Ability> options = getPlayableOptions(source, game);
     if (options.isEmpty()) {
       ability = source;
     } else {
       if (options.size() == 1) ability = options.get(0);
       else ability = options.get(rnd.nextInt(options.size()));
     }
     if (ability.isUsesStack()) {
       game.getStack().push(new StackAbility(ability, playerId));
       if (ability.activate(game, false)) {
         actionCount++;
         return true;
       }
     } else {
       if (ability.activate(game, false)) {
         ability.resolve(game);
         actionCount++;
         return true;
       }
     }
   }
   return false;
 }
Ejemplo n.º 4
0
 private Ability getAction(Game game) {
   List<Ability> playables = getPlayableAbilities(game);
   Ability ability;
   while (true) {
     if (playables.size() == 1) ability = playables.get(0);
     else ability = playables.get(rnd.nextInt(playables.size()));
     List<Ability> options = getPlayableOptions(ability, game);
     if (!options.isEmpty()) {
       if (options.size() == 1) ability = options.get(0);
       else ability = options.get(rnd.nextInt(options.size()));
     }
     if (ability.getManaCosts().getVariableCosts().size() > 0) {
       int amount =
           getAvailableManaProducers(game).size() - ability.getManaCosts().convertedManaCost();
       if (amount > 0) {
         ability = ability.copy();
         ability.getManaCostsToPay().add(new GenericManaCost(rnd.nextInt(amount)));
       }
     }
     // check if ability kills player, if not then it's ok to play
     //            if (ability.isUsesStack()) {
     //                Game testSim = game.copy();
     //                activateAbility((ActivatedAbility) ability, testSim);
     //                StackObject testAbility = testSim.getStack().pop();
     //                testAbility.resolve(testSim);
     //                testSim.applyEffects();
     //                testSim.checkStateAndTriggered();
     //                if (!testSim.getPlayer(playerId).hasLost()) {
     //                    break;
     //                }
     //            }
     //            else {
     break;
     //            }
   }
   return ability;
 }
Ejemplo n.º 5
0
 @Override
 public UUID chooseBlockerOrder(List<Permanent> blockers, Game game) {
   return blockers.get(rnd.nextInt(blockers.size())).getId();
 }
Ejemplo n.º 6
0
 @Override
 public UUID chooseAttackerOrder(List<Permanent> attackers, Game game) {
   return attackers.get(rnd.nextInt(attackers.size())).getId();
 }
Ejemplo n.º 7
0
 @Override
 public TriggeredAbility chooseTriggeredAbility(List<TriggeredAbility> abilities, Game game) {
   return abilities.get(rnd.nextInt(abilities.size()));
 }
Ejemplo n.º 8
0
 @Override
 public int chooseEffect(List<String> rEffects, Game game) {
   return rnd.nextInt(rEffects.size());
 }
Ejemplo n.º 9
0
 protected List<Ability> getPlayableAbilities(Game game) {
   List<Ability> playables = getPlayable(game, true);
   playables.add(pass);
   return playables;
 }