mirror of
https://github.com/magefree/mage.git
synced 2026-01-26 21:29:17 -08:00
test framework: added support of AI vs AI games (test must override getFullSimulatedPlayers to setup additional AIs);
This commit is contained in:
parent
add2d0473e
commit
30ae4a8d66
3 changed files with 94 additions and 6 deletions
|
|
@ -0,0 +1,64 @@
|
|||
package org.mage.test.AI.basic;
|
||||
|
||||
import mage.constants.PhaseStep;
|
||||
import mage.constants.Zone;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.mage.test.serverside.base.CardTestPlayerBaseAI;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author JayDi85
|
||||
*/
|
||||
public class SimulationPerformanceAITest extends CardTestPlayerBaseAI {
|
||||
|
||||
@Override
|
||||
public List<String> getFullSimulatedPlayers() {
|
||||
return Arrays.asList("PlayerA", "PlayerB");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_AIvsAI_Simple() {
|
||||
// both must kill x2 bears by x2 bolts
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Balduvian Bears", 2);
|
||||
addCard(Zone.BATTLEFIELD, playerB, "Balduvian Bears", 2);
|
||||
addCard(Zone.HAND, playerA, "Lightning Bolt", 2);
|
||||
addCard(Zone.HAND, playerB, "Lightning Bolt", 2);
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 2);
|
||||
addCard(Zone.BATTLEFIELD, playerB, "Mountain", 2);
|
||||
|
||||
setStrictChooseMode(true);
|
||||
setStopAt(1, PhaseStep.END_TURN);
|
||||
execute();
|
||||
|
||||
assertGraveyardCount(playerA, "Balduvian Bears", 2);
|
||||
assertGraveyardCount(playerB, "Balduvian Bears", 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_AIvsAI_LongGame() {
|
||||
// many bears and bolts must help to end game fast
|
||||
int maxTurn = 40;
|
||||
removeAllCardsFromLibrary(playerA);
|
||||
removeAllCardsFromLibrary(playerB);
|
||||
|
||||
addCard(Zone.LIBRARY, playerA, "Mountain", 10);
|
||||
addCard(Zone.LIBRARY, playerA, "Forest", 10);
|
||||
addCard(Zone.LIBRARY, playerA, "Lightning Bolt", 20);
|
||||
addCard(Zone.LIBRARY, playerA, "Balduvian Bears", 10);
|
||||
//
|
||||
addCard(Zone.LIBRARY, playerB, "Mountain", 10);
|
||||
addCard(Zone.LIBRARY, playerA, "Forest", 10);
|
||||
addCard(Zone.LIBRARY, playerB, "Lightning Bolt", 20);
|
||||
addCard(Zone.LIBRARY, playerB, "Balduvian Bears", 10);
|
||||
|
||||
// full ai simulation
|
||||
setStrictChooseMode(true);
|
||||
setStopAt(maxTurn, PhaseStep.END_TURN);
|
||||
execute();
|
||||
|
||||
Assert.assertTrue("One of player must won a game before turn " + maxTurn + ", but it ends on " + currentGame, currentGame.hasEnded());
|
||||
}
|
||||
}
|
||||
|
|
@ -1076,6 +1076,7 @@ public class TestPlayer implements Player {
|
|||
if (numberOfActions == actions.size()) {
|
||||
foundNoAction++;
|
||||
if (foundNoAction > maxCallsWithoutAction) {
|
||||
// how-to fix: if you really need a long game with many turns then use prepare command TestPlayer.setMaxCallsWithoutAction
|
||||
throw new AssertionError("Too much priority calls to " + getName()
|
||||
+ " without taking any action than allowed (" + maxCallsWithoutAction + ") on turn " + game.getTurnNum());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,22 +6,45 @@ import mage.game.Game;
|
|||
import mage.game.GameException;
|
||||
import mage.game.TwoPlayerDuel;
|
||||
import mage.game.mulligan.MulliganType;
|
||||
import mage.players.Player;
|
||||
import org.mage.test.player.TestComputerPlayer7;
|
||||
import org.mage.test.player.TestPlayer;
|
||||
import org.mage.test.serverside.base.impl.CardTestPlayerAPIImpl;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* PlayerA is full AI player and process all actions as AI logic. You don't need aiXXX commands in that tests.
|
||||
* <p>
|
||||
* If you need custom AI tests then use CardTestPlayerBaseWithAIHelps with aiXXX commands
|
||||
* If you need simple AI tests for single command/priority then use CardTestPlayerBaseWithAIHelps with aiXXX commands
|
||||
* If you need full AI tests with game simulations then use current CardTestPlayerBaseAI
|
||||
* <p>
|
||||
* Only PlayerA ai-controlled by default. Use getFullSimulatedPlayers for additional AI players, e.g. AI vs AI tests.
|
||||
*
|
||||
* @author LevelX2
|
||||
* @author LevelX2, JayDi85
|
||||
*/
|
||||
public abstract class CardTestPlayerBaseAI extends CardTestPlayerAPIImpl {
|
||||
|
||||
int skill = 6;
|
||||
/**
|
||||
* Allow to change AI skill level
|
||||
*/
|
||||
public int getSkillLevel() {
|
||||
return 6;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow to change full simulates players (default is PlayerA)
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<String> getFullSimulatedPlayers() {
|
||||
return Arrays.asList("PlayerA");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Game createNewGameAndPlayers() throws GameException, FileNotFoundException {
|
||||
|
|
@ -34,10 +57,10 @@ public abstract class CardTestPlayerBaseAI extends CardTestPlayerAPIImpl {
|
|||
|
||||
@Override
|
||||
protected TestPlayer createPlayer(String name, RangeOfInfluence rangeOfInfluence) {
|
||||
if (name.equals("PlayerA")) {
|
||||
TestPlayer testPlayer = new TestPlayer(new TestComputerPlayer7("PlayerA", RangeOfInfluence.ONE, skill));
|
||||
if (getFullSimulatedPlayers().contains(name)) {
|
||||
TestPlayer testPlayer = new TestPlayer(new TestComputerPlayer7(name, RangeOfInfluence.ONE, getSkillLevel()));
|
||||
testPlayer.setAIPlayer(true);
|
||||
testPlayer.setAIRealGameSimulation(true); // enable AI logic simulation for all turns by default
|
||||
testPlayer.setAIRealGameSimulation(true); // enable full AI support (game simulations) for all turns by default
|
||||
return testPlayer;
|
||||
}
|
||||
return super.createPlayer(name, rangeOfInfluence);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue