Extra tests for AI;

This commit is contained in:
Oleg Agafonov 2019-07-12 19:09:26 +04:00
parent e02d8a079b
commit 02b1e86f20
2 changed files with 26 additions and 0 deletions

View file

@ -841,10 +841,14 @@ public class ComputerPlayer6 extends ComputerPlayer /*implements Player*/ {
int attackerValue = eval.evaluate(attacker, game);
for (Permanent blocker : possibleBlockers) {
int blockerValue = eval.evaluate(blocker, game);
// blocker can kill attacker
if (attacker.getPower().getValue() <= blocker.getToughness().getValue()
&& attacker.getToughness().getValue() <= blocker.getPower().getValue()) {
safeToAttack = false;
}
// kill each other
if (attacker.getToughness().getValue() == blocker.getPower().getValue()
&& attacker.getPower().getValue() == blocker.getToughness().getValue()) {
if (attackerValue > blockerValue
@ -859,19 +863,26 @@ public class ComputerPlayer6 extends ComputerPlayer /*implements Player*/ {
safeToAttack = false;
}
}
// attacker can kill by deathtouch
if (attacker.getAbilities().containsKey(DeathtouchAbility.getInstance().getId())
|| attacker.getAbilities().containsKey(IndestructibleAbility.getInstance().getId())) {
safeToAttack = true;
}
// attacker can ignore blocker
if (attacker.getAbilities().containsKey(FlyingAbility.getInstance().getId())
&& !blocker.getAbilities().containsKey(FlyingAbility.getInstance().getId())
&& !blocker.getAbilities().containsKey(ReachAbility.getInstance().getId())) {
safeToAttack = true;
}
}
// 0 damage
if (attacker.getPower().getValue() == 0) {
safeToAttack = false;
}
if (safeToAttack) {
// undo has to be possible e.g. if not able to pay a attack fee (e.g. Ghostly Prison)
attackingPlayer.declareAttacker(attacker.getId(), defenderId, game, true);

View file

@ -204,4 +204,19 @@ public class AttackAndBlockByAITest extends CardTestPlayerBaseAI {
assertLife(playerA, 20);
assertLife(playerB, 20);
}
@Test
public void test_Attack_1_with_counters_vs_1() {
// chainbreaker real stats is 1/1, it's can be saftly attacked
addCard(Zone.BATTLEFIELD, playerA, "Balduvian Bears", 1); // 2/2
addCard(Zone.BATTLEFIELD, playerB, "Chainbreaker", 1); // 3/3, but with 2x -1/-1 counters
setStopAt(1, PhaseStep.END_TURN);
setStrictChooseMode(true);
execute();
assertAllCommandsUsed();
assertLife(playerA, 20);
assertLife(playerB, 20 - 2);
}
}