- Improved TapAllAI.

This commit is contained in:
Sloth
2013-03-21 08:33:10 +00:00
parent fcf4ac4339
commit 87e607755d
3 changed files with 37 additions and 19 deletions

View File

@@ -1,9 +1,8 @@
Name:Thoughtweft Gambit Name:Thoughtweft Gambit
ManaCost:4 WU WU ManaCost:4 WU WU
Types:Instant Types:Instant
#Switched order of abilities since DB$UntapAll doesn't exist yet A:SP$ TapAll | Cost$ 4 WU WU | ValidCards$ Creature.OppCtrl | SubAbility$ DBUnTap | SpellDescription$ Tap all creatures your opponents control and untap all creatures you control.
A:SP$ UntapAll | Cost$ 4 WU WU | ValidCards$ Creature.YouCtrl | SubAbility$ DBTap | SpellDescription$ Tap all creatures your opponents control and untap all creatures you control. SVar:DBUnTap:DB$ UntapAll | ValidCards$ Creature.YouCtrl
SVar:DBTap:DB$ TapAll | ValidCards$ Creature.OppCtrl
SVar:Picture:http://www.wizards.com/global/images/magic/general/thoughtweft_gambit.jpg SVar:Picture:http://www.wizards.com/global/images/magic/general/thoughtweft_gambit.jpg
Oracle:Tap all creatures your opponents control and untap all creatures you control. Oracle:Tap all creatures your opponents control and untap all creatures you control.
SetInfo:SHM Uncommon SetInfo:SHM Uncommon

View File

@@ -13,6 +13,7 @@ import forge.Singletons;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target; import forge.card.spellability.Target;
import forge.game.phase.CombatUtil;
import forge.game.phase.PhaseType; import forge.game.phase.PhaseType;
import forge.game.player.AIPlayer; import forge.game.player.AIPlayer;
import forge.game.player.Player; import forge.game.player.Player;
@@ -56,29 +57,43 @@ public class TapAllAi extends SpellAbilityAi {
validTappables = CardLists.filter(validTappables, Presets.UNTAPPED); validTappables = CardLists.filter(validTappables, Presets.UNTAPPED);
final Random r = MyRandom.getRandom(); final Random r = MyRandom.getRandom();
boolean rr = false; if (r.nextFloat() > Math.pow(.6667, sa.getActivationsThisTurn())) {
if (r.nextFloat() <= Math.pow(.6667, sa.getActivationsThisTurn())) { return false;
rr = true;
} }
if (validTappables.size() > 0) { if (validTappables.isEmpty()) {
final List<Card> human = CardLists.filter(validTappables, new Predicate<Card>() { return false;
}
final List<Card> human = CardLists.filter(validTappables, new Predicate<Card>() {
@Override
public boolean apply(final Card c) {
return c.getController().equals(opp);
}
});
final List<Card> compy = CardLists.filter(validTappables, new Predicate<Card>() {
@Override
public boolean apply(final Card c) {
return c.getController().equals(ai);
}
});
if (human.size() <= compy.size()) {
return false;
}
// in AI's turn, check if there are possible attackers, before tapping blockers
if (Singletons.getModel().getGame().getPhaseHandler().isPlayerTurn(ai) && !SpellAbilityAi.isSorcerySpeed(sa)) {
validTappables = ai.getCardsIn(ZoneType.Battlefield);
final boolean any = Iterables.any(validTappables, new Predicate<Card>() {
@Override @Override
public boolean apply(final Card c) { public boolean apply(final Card c) {
return c.getController().equals(opp); return CombatUtil.canAttack(c) && CombatUtil.canAttackNextTurn(c);
} }
}); });
final List<Card> compy = CardLists.filter(validTappables, new Predicate<Card>() { if(!any) {
@Override return false;
public boolean apply(final Card c) {
return c.getController().equals(ai);
}
});
if (human.size() > compy.size()) {
return rr;
} }
} }
return false; return true;
} }
/** /**

View File

@@ -807,13 +807,17 @@ public class CombatUtil {
* @return a boolean. * @return a boolean.
*/ */
public static boolean canAttack(final Card c, final GameEntity defender) { public static boolean canAttack(final Card c, final GameEntity defender) {
return canAttack(c) && canAttackNextTurn(c, defender);
}
public static boolean canAttack(final Card c) {
if (c.isTapped() || c.isPhasedOut() if (c.isTapped() || c.isPhasedOut()
|| (c.hasSickness() && !c.hasKeyword("CARDNAME can attack as though it had haste.")) || (c.hasSickness() && !c.hasKeyword("CARDNAME can attack as though it had haste."))
|| Singletons.getModel().getGame().getPhaseHandler().getPhase() || Singletons.getModel().getGame().getPhaseHandler().getPhase()
.isAfter(PhaseType.COMBAT_DECLARE_ATTACKERS)) { .isAfter(PhaseType.COMBAT_DECLARE_ATTACKERS)) {
return false; return false;
} }
return CombatUtil.canAttackNextTurn(c, defender); return true;
} }
// can a creature attack if untapped and without summoning sickness? // can a creature attack if untapped and without summoning sickness?