mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 10:40:06 -08:00
tests: added AI performance tests to reproduce bad use cases with too much possible targets
This commit is contained in:
parent
416beb741c
commit
7d229e511c
2 changed files with 50 additions and 0 deletions
|
|
@ -81,6 +81,7 @@ public class ComputerPlayer extends PlayerImpl {
|
|||
// * 5 for good performance on average computer
|
||||
// * use your's CPU cores for best performance
|
||||
// TODO: add server config to control max AI threads (with CPU cores by default)
|
||||
// TODO: rework AI implementation to use multiple sims calculation instead one by one
|
||||
final static int COMPUTER_MAX_THREADS_FOR_SIMULATIONS = 5;
|
||||
|
||||
private final transient Map<Mana, Card> unplayable = new TreeMap<>();
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package org.mage.test.AI.basic;
|
|||
import mage.constants.PhaseStep;
|
||||
import mage.constants.Zone;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.mage.test.serverside.base.CardTestPlayerBaseAI;
|
||||
|
||||
|
|
@ -61,4 +62,52 @@ public class SimulationPerformanceAITest extends CardTestPlayerBaseAI {
|
|||
|
||||
Assert.assertTrue("One of player must won a game before turn " + maxTurn + ", but it ends on " + currentGame, currentGame.hasEnded());
|
||||
}
|
||||
|
||||
private void runManyTargetOptionsTest(String info, int totalCreatures, int needDiedCreatures, int needPlayerLife) {
|
||||
// When Bogardan Hellkite enters, it deals 5 damage divided as you choose among any number of targets.
|
||||
addCard(Zone.HAND, playerA, "Bogardan Hellkite", 1); // {6}{R}{R}
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 8);
|
||||
//
|
||||
addCard(Zone.BATTLEFIELD, playerB, "Balduvian Bears", totalCreatures);
|
||||
|
||||
setStrictChooseMode(true);
|
||||
setStopAt(1, PhaseStep.BEGIN_COMBAT);
|
||||
execute();
|
||||
|
||||
assertPermanentCount(playerA, "Bogardan Hellkite", 1); // if fail then AI stops before all sims ends
|
||||
assertGraveyardCount(playerB, "Balduvian Bears", needDiedCreatures);
|
||||
assertLife(playerB, needPlayerLife);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_AIvsAI_ManyTargetOptions_Simple() {
|
||||
// 2 damage to bear and 3 damage to player B
|
||||
runManyTargetOptionsTest("1 target creature", 1, 1, 20 - 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_AIvsAI_ManyTargetOptions_Few() {
|
||||
// 4 damage to x2 bears and 1 damage to player B
|
||||
runManyTargetOptionsTest("2 target creatures", 2, 2, 20 - 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_AIvsAI_ManyTargetOptions_Many() {
|
||||
// 4 damage to x2 bears and 1 damage to player B
|
||||
runManyTargetOptionsTest("5 target creatures", 2, 2, 20 - 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore // AI code must be improved
|
||||
// TODO: need memory optimization
|
||||
// TODO: need sims/options amount optimization (example: target name + score as unique param to reduce possible options)
|
||||
// TODO: need best choice selection on timeout (AI must make any good/bad choice on timeout with game log - not a skip)
|
||||
public void test_AIvsAI_ManyTargetOptions_TooMuch() {
|
||||
// possible problems:
|
||||
// - big memory consumption on sims prepare (memory overflow)
|
||||
// - too many sims to calculate (AI fail on time out and do nothing)
|
||||
|
||||
// 4 damage to x2 bears and 1 damage to player B
|
||||
runManyTargetOptionsTest("50 target creatures", 50, 2, 20 - 1);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue