Test framework: added AI support for attack/block phases, added attack/block skip commands;

This commit is contained in:
Oleg Agafonov 2019-07-12 13:54:24 +04:00
parent 7871b95d81
commit be281ff402
5 changed files with 42 additions and 10 deletions

View file

@ -1,4 +1,3 @@
package org.mage.test.AI.basic;
import mage.constants.PhaseStep;
@ -10,14 +9,12 @@ import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBaseAI;
/**
*
* @author LevelX2
*/
public class PreventRepeatedActionsTest extends CardTestPlayerBaseAI {
/**
* Check that an equipment is not switched again an again between creatures
*
*/
@Test
public void testEquipOnlyOnce() {
@ -77,10 +74,13 @@ public class PreventRepeatedActionsTest extends CardTestPlayerBaseAI {
attack(2, playerB, "Silvercoat Lion");
attack(2, playerB, "Silvercoat Lion");
blockSkip(2, playerA);
setStopAt(2, PhaseStep.END_TURN);
execute();
assertPermanentCount(playerA, "Kiora's Follower", 2);
assertPermanentCount(playerB, "Silvercoat Lion", 2);
assertLife(playerA, 16);
assertTapped("Kiora's Follower", false);
}

View file

@ -1,4 +1,3 @@
package org.mage.test.AI.basic;
import mage.constants.PhaseStep;
@ -9,7 +8,6 @@ import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBaseAI;
/**
*
* @author LevelX2
*/
public class TargetsAreChosenTest extends CardTestPlayerBaseAI {
@ -158,6 +156,7 @@ public class TargetsAreChosenTest extends CardTestPlayerBaseAI {
// Whenever a creature an opponent controls dies, put a +1/+1 counter on Malakir Cullblade.
addCard(Zone.BATTLEFIELD, playerA, "Malakir Cullblade", 5);
attackSkip(1, playerA);
attack(3, playerA, "Nefashu");
setStopAt(3, PhaseStep.POSTCOMBAT_MAIN);
execute();

View file

@ -72,7 +72,9 @@ public class TestPlayer implements Player {
private static final Logger logger = Logger.getLogger(TestPlayer.class);
public static final String TARGET_SKIP = "[skip]";
public static final String TARGET_SKIP = "[target_skip]";
public static final String BLOCK_SKIP = "[block_skip]";
public static final String ATTACK_SKIP = "[attack_skip]";
private int maxCallsWithoutAction = 100;
private int foundNoAction = 0;
@ -1242,6 +1244,14 @@ public class TestPlayer implements Player {
mustAttackByAction = true;
String command = action.getAction();
command = command.substring(command.indexOf("attack:") + 7);
// skip attack
if (command.startsWith(ATTACK_SKIP)) {
it.remove();
madeAttackByAction = true;
break;
}
String[] groups = command.split("\\$");
for (int i = 1; i < groups.length; i++) {
String group = groups[i];
@ -1291,6 +1301,11 @@ public class TestPlayer implements Player {
if (mustAttackByAction && !madeAttackByAction) {
this.chooseStrictModeFailed(game, "select attackers must use attack command but don't");
}
// AI play if no actions available
if (!mustAttackByAction && this.AIPlayer) {
this.computerPlayer.selectAttackers(game, attackingPlayerId);
}
}
@Override
@ -1306,10 +1321,19 @@ public class TestPlayer implements Player {
UUID opponentId = game.getOpponents(computerPlayer.getId()).iterator().next();
// Map of Blocker reference -> list of creatures blocked
Map<MageObjectReference, List<MageObjectReference>> blockedCreaturesByCreature = new HashMap<>();
boolean mustBlockByAction = false;
for (PlayerAction action : tempActions) {
if (action.getTurnNum() == game.getTurnNum() && action.getAction().startsWith("block:")) {
mustBlockByAction = true;
String command = action.getAction();
command = command.substring(command.indexOf("block:") + 6);
// skip block
if (command.startsWith(BLOCK_SKIP)) {
actions.remove(action);
break;
}
String[] groups = command.split("\\$");
String blockerName = groups[0];
String attackerName = groups[1];
@ -1324,6 +1348,11 @@ public class TestPlayer implements Player {
}
}
checkMultipleBlockers(game, blockedCreaturesByCreature);
// AI play if no actions available
if (!mustBlockByAction && this.AIPlayer) {
this.computerPlayer.selectBlockers(game, defendingPlayerId);
}
}
// Checks if a creature can block at least one more creature

View file

@ -37,8 +37,4 @@ public abstract class CardTestPlayerBaseAI extends CardTestPlayerAPIImpl {
}
return super.createPlayer(name, rangeOfInfluence);
}
public void setAISkill(int skill) {
this.skill = skill;
}
}

View file

@ -1527,12 +1527,20 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
player.addAction(turnNum, PhaseStep.DECLARE_ATTACKERS, new StringBuilder("attack:").append(attacker).append("$planeswalker=").append(planeswalker).toString());
}
public void attackSkip(int turnNum, TestPlayer player) {
attack(turnNum, player, TestPlayer.ATTACK_SKIP);
}
public void block(int turnNum, TestPlayer player, String blocker, String attacker) {
//Assert.assertNotEquals("", blocker);
//Assert.assertNotEquals("", attacker);
player.addAction(turnNum, PhaseStep.DECLARE_BLOCKERS, "block:" + blocker + '$' + attacker);
}
public void blockSkip(int turnNum, TestPlayer player) {
block(turnNum, player, TestPlayer.BLOCK_SKIP, "");
}
/**
* For use choices set "Yes" or "No" the the choice string. For X values set
* "X=[xValue]" example: for X=3 set choice string to "X=3".