AI: improved target amount abilities:

* added support to search targets from multiple opponents instead one;
 * added support of TargetCreaturePermanentAmount and all new target types;
 * added new priorities (kills most valuable first);
 * added bad and good conditions (choose most valuable in good case and most weakest in bad case, e.g. damage yourself);
 * fixed that AI targets opponent for good ability instead yourself;
This commit is contained in:
Oleg Agafonov 2019-06-26 21:46:11 +04:00
parent 073b003b37
commit 34ff038053
2 changed files with 361 additions and 62 deletions

View file

@ -0,0 +1,231 @@
package org.mage.test.AI.basic;
import mage.abilities.Ability;
import mage.abilities.SpellAbility;
import mage.abilities.common.EntersBattlefieldTriggeredAbility;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.common.DamageMultiEffect;
import mage.constants.CardType;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import mage.target.common.TargetCreaturePermanentAmount;
import org.junit.Ignore;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBaseAI;
/**
* @author JayDi85
*/
public class TargetPriorityTest extends CardTestPlayerBaseAI {
// TODO: enable _target_ tests after computerPlayer.chooseTarget will be reworks like chooseTargetAmount
@Test
@Ignore
public void test_target_PriorityKillByBigPT() {
addCard(Zone.HAND, playerA, "Lightning Bolt");
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 1);
//
addCard(Zone.BATTLEFIELD, playerB, "Memnite", 3); // 1/1
addCard(Zone.BATTLEFIELD, playerB, "Balduvian Bears", 3); // 2/2
addCard(Zone.BATTLEFIELD, playerB, "Ashcoat Bear", 3); // 2/2 with ability
addCard(Zone.BATTLEFIELD, playerB, "Golden Bear", 3); // 4/3
addCard(Zone.BATTLEFIELD, playerB, "Battering Sliver", 3); // 4/4 with ability
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Lightning Bolt");
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
assertAllCommandsUsed();
assertPermanentCount(playerB, "Memnite", 3);
assertPermanentCount(playerB, "Balduvian Bears", 3);
assertPermanentCount(playerB, "Ashcoat Bear", 3);
assertPermanentCount(playerB, "Golden Bear", 3 - 1);
assertPermanentCount(playerB, "Battering Sliver", 3);
}
@Test
@Ignore
public void test_target_PriorityByKillByLowPT() {
addCard(Zone.HAND, playerA, "Lightning Bolt");
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 1);
//
addCard(Zone.BATTLEFIELD, playerB, "Memnite", 3); // 1/1
//addCard(Zone.BATTLEFIELD, playerB, "Balduvian Bears", 3); // 2/2
//addCard(Zone.BATTLEFIELD, playerB, "Ashcoat Bear", 3); // 2/2 with ability
//addCard(Zone.BATTLEFIELD, playerB, "Golden Bear", 3); // 4/3
addCard(Zone.BATTLEFIELD, playerB, "Battering Sliver", 3); // 4/4 with ability
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Lightning Bolt");
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
assertAllCommandsUsed();
assertPermanentCount(playerB, "Memnite", 3 - 1);
//assertPermanentCount(playerB, "Balduvian Bears", 3);
//assertPermanentCount(playerB, "Ashcoat Bear", 3);
//assertPermanentCount(playerB, "Golden Bear", 3);
assertPermanentCount(playerB, "Battering Sliver", 3);
}
@Test
@Ignore
public void test_target_PriorityKillByExtraPoints() {
addCard(Zone.HAND, playerA, "Lightning Bolt");
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 1);
//
addCard(Zone.BATTLEFIELD, playerB, "Memnite", 3); // 1/1
addCard(Zone.BATTLEFIELD, playerB, "Balduvian Bears", 3); // 2/2
addCard(Zone.BATTLEFIELD, playerB, "Ashcoat Bear", 3); // 2/2 with ability
//addCard(Zone.BATTLEFIELD, playerB, "Golden Bear", 3); // 4/3
addCard(Zone.BATTLEFIELD, playerB, "Battering Sliver", 3); // 4/4 with ability
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Lightning Bolt");
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
assertAllCommandsUsed();
assertPermanentCount(playerB, "Memnite", 3);
assertPermanentCount(playerB, "Balduvian Bears", 3);
assertPermanentCount(playerB, "Ashcoat Bear", 3 - 1);
//assertPermanentCount(playerB, "Golden Bear", 3);
assertPermanentCount(playerB, "Battering Sliver", 3);
}
//
@Test
public void test_targetAmount_PriorityKillByBigPT() {
addCard(Zone.HAND, playerA, "Flames of the Firebrand"); // damage 3
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 3);
//
addCard(Zone.BATTLEFIELD, playerB, "Memnite", 3); // 1/1
addCard(Zone.BATTLEFIELD, playerB, "Balduvian Bears", 3); // 2/2
addCard(Zone.BATTLEFIELD, playerB, "Ashcoat Bear", 3); // 2/2 with ability
addCard(Zone.BATTLEFIELD, playerB, "Golden Bear", 3); // 4/3
addCard(Zone.BATTLEFIELD, playerB, "Battering Sliver", 3); // 4/4 with ability
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Flames of the Firebrand");
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
assertAllCommandsUsed();
assertPermanentCount(playerB, "Memnite", 3);
assertPermanentCount(playerB, "Balduvian Bears", 3);
assertPermanentCount(playerB, "Ashcoat Bear", 3);
assertPermanentCount(playerB, "Golden Bear", 3 - 1);
assertPermanentCount(playerB, "Battering Sliver", 3);
}
@Test
public void test_targetAmount_PriorityByKillByLowPT() {
addCard(Zone.HAND, playerA, "Flames of the Firebrand"); // damage 3
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 3);
//
addCard(Zone.BATTLEFIELD, playerB, "Memnite", 3); // 1/1
addCard(Zone.BATTLEFIELD, playerB, "Balduvian Bears", 3); // 2/2
//addCard(Zone.BATTLEFIELD, playerB, "Ashcoat Bear", 3); // 2/2 with ability
//addCard(Zone.BATTLEFIELD, playerB, "Golden Bear", 3); // 4/3
addCard(Zone.BATTLEFIELD, playerB, "Battering Sliver", 3); // 4/4 with ability
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Flames of the Firebrand");
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
assertAllCommandsUsed();
assertPermanentCount(playerB, "Memnite", 3 - 1);
assertPermanentCount(playerB, "Balduvian Bears", 3 - 1);
//assertPermanentCount(playerB, "Ashcoat Bear", 3);
//assertPermanentCount(playerB, "Golden Bear", 3);
assertPermanentCount(playerB, "Battering Sliver", 3);
}
@Test
public void test_targetAmount_PriorityKillByExtraPoints() {
addCard(Zone.HAND, playerA, "Flames of the Firebrand"); // damage 3
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 3);
//
addCard(Zone.BATTLEFIELD, playerB, "Memnite", 3); // 1/1
addCard(Zone.BATTLEFIELD, playerB, "Balduvian Bears", 3); // 2/2
addCard(Zone.BATTLEFIELD, playerB, "Ashcoat Bear", 3); // 2/2 with ability
//addCard(Zone.BATTLEFIELD, playerB, "Golden Bear", 3); // 4/3
addCard(Zone.BATTLEFIELD, playerB, "Battering Sliver", 3); // 4/4 with ability
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Flames of the Firebrand");
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
assertAllCommandsUsed();
assertPermanentCount(playerB, "Memnite", 3 - 1);
assertPermanentCount(playerB, "Balduvian Bears", 3);
assertPermanentCount(playerB, "Ashcoat Bear", 3 - 1);
//assertPermanentCount(playerB, "Golden Bear", 3);
assertPermanentCount(playerB, "Battering Sliver", 3);
}
@Test
public void test_targetAmount_NormalCase() {
Ability ability = new SimpleActivatedAbility(Zone.ALL, new DamageMultiEffect(3), new ManaCostsImpl("R"));
ability.addTarget(new TargetCreaturePermanentAmount(3));
addCustomCardWithAbility("damage 3", playerA, ability);
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 1);
//
addCard(Zone.BATTLEFIELD, playerB, "Memnite", 3); // 1/1
addCard(Zone.BATTLEFIELD, playerB, "Balduvian Bears", 3); // 2/2
addCard(Zone.BATTLEFIELD, playerB, "Ashcoat Bear", 3); // 2/2 with ability
addCard(Zone.BATTLEFIELD, playerB, "Golden Bear", 3); // 4/3
addCard(Zone.BATTLEFIELD, playerB, "Battering Sliver", 3); // 4/4 with ability
activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{R}: ");
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
assertAllCommandsUsed();
assertPermanentCount(playerB, "Memnite", 3);
assertPermanentCount(playerB, "Balduvian Bears", 3);
assertPermanentCount(playerB, "Ashcoat Bear", 3);
assertPermanentCount(playerB, "Golden Bear", 3 - 1);
assertPermanentCount(playerB, "Battering Sliver", 3);
}
@Test
public void test_targetAmount_BadCase() {
// choose targets as enters battlefield (e.g. can't be canceled)
SpellAbility spell = new SpellAbility(new ManaCostsImpl("R"), "damage 3", Zone.HAND);
Ability ability = new EntersBattlefieldTriggeredAbility(new DamageMultiEffect(3));
ability.addTarget(new TargetCreaturePermanentAmount(3));
addCustomCardWithSpell(playerA, spell, ability, CardType.ENCHANTMENT);
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 1);
//
addCard(Zone.BATTLEFIELD, playerA, "Memnite", 3); // 1/1
addCard(Zone.BATTLEFIELD, playerA, "Balduvian Bears", 3); // 2/2
addCard(Zone.BATTLEFIELD, playerA, "Ashcoat Bear", 3); // 2/2 with ability
addCard(Zone.BATTLEFIELD, playerA, "Golden Bear", 3); // 4/3
addCard(Zone.BATTLEFIELD, playerA, "Battering Sliver", 3); // 4/4 with ability
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "damage 3");
// must damage x3 Balduvian Bears by -1 to keep alive
checkDamage("pt after", 1, PhaseStep.BEGIN_COMBAT, playerA, "Balduvian Bears", 1);
showBattlefield("after", 1, PhaseStep.BEGIN_COMBAT, playerA);
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
assertAllCommandsUsed();
assertPermanentCount(playerA, "damage 3", 1);
assertPermanentCount(playerA, "Memnite", 3);
assertPermanentCount(playerA, "Balduvian Bears", 3);
assertPermanentCount(playerA, "Ashcoat Bear", 3);
assertPermanentCount(playerA, "Golden Bear", 3);
assertPermanentCount(playerA, "Battering Sliver", 3);
}
}