refactor: combined announceX methods in one, improved X message and selection for AI (part of #10330)

This commit is contained in:
Oleg Agafonov 2025-05-16 19:34:57 +04:00
parent 6af198836b
commit 66db821437
37 changed files with 90 additions and 158 deletions

View file

@ -23,7 +23,7 @@ public class ProteanHydraTest extends CardTestPlayerBase {
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Protean Hydra");
setStrictChooseMode(false); // test AI use max for X
setStrictChooseMode(false); // TODO: good test for AI's announceX - duplicate it as AI test
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();

View file

@ -169,6 +169,7 @@ public class SoulBurnTest extends CardTestPlayerBase {
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Soul Burn", "Craw Wurm");
setStrictChooseMode(false); // TODO: good test for AI's announceX - duplicate it as AI test (few examples)
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
assertPermanentCount(playerB, "Craw Wurm", 1);

View file

@ -56,6 +56,7 @@ public class IncreasingCardsTest extends CardTestPlayerBase {
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Increasing Confusion");
activateAbility(3, PhaseStep.PRECOMBAT_MAIN, playerA, "Flashback {X}{U}");
setStrictChooseMode(false); // TODO: good test for AI's announceX - duplicate it as AI test
setStopAt(3, PhaseStep.BEGIN_COMBAT);
execute();

View file

@ -65,7 +65,7 @@ public class HELIOSOneTest extends CardTestPlayerBase {
} catch (AssertionError e) {
Assert.assertTrue(
"X=0 is not a valid choice. Error message:\n" + e.getMessage(),
e.getMessage().contains("Message: Announce the number of {E} to pay")
e.getMessage().contains("Message: Announce the value for {X}")
);
}
}

View file

@ -29,6 +29,7 @@ public class PostMortemLungeTest extends CardTestPlayerBase {
attack(1, playerA, "Elite Vanguard");
setStrictChooseMode(false); // TODO: good test for AI's announceX - duplicate it as AI test
setStopAt(1, PhaseStep.CLEANUP);
execute();

View file

@ -6,7 +6,6 @@ import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.costs.AlternativeSourceCosts;
import mage.abilities.costs.Cost;
import mage.abilities.costs.Costs;
import mage.abilities.costs.VariableCost;
import mage.abilities.costs.mana.ManaCost;
import mage.abilities.costs.mana.ManaCosts;
import mage.abilities.effects.common.InfoEffect;
@ -2916,39 +2915,20 @@ public class TestPlayer implements Player {
}
@Override
public int announceXMana(int min, int max, String message, Game game, Ability ability) {
assertAliasSupportInChoices(false);
if (!choices.isEmpty()) {
for (String choice : new ArrayList<>(choices)) {
if (choice.startsWith("X=")) {
int xValue = Integer.parseInt(choice.substring(2));
assertXMinMaxValue(game, ability, xValue, min, max);
choices.remove(choice);
return xValue;
}
}
}
this.chooseStrictModeFailed("choice", game, getInfo(ability, game)
+ "\nMessage: " + message + prepareXMaxInfo(min, max));
return computerPlayer.announceXMana(min, max, message, game, ability);
}
@Override
public int announceXCost(int min, int max, String message, Game game, Ability ability, VariableCost variablCost) {
public int announceX(int min, int max, String message, Game game, Ability source, boolean isManaPay) {
assertAliasSupportInChoices(false);
if (!choices.isEmpty()) {
if (choices.get(0).startsWith("X=")) {
int xValue = Integer.parseInt(choices.get(0).substring(2));
assertXMinMaxValue(game, ability, xValue, min, max);
assertXMinMaxValue(game, source, xValue, min, max);
choices.remove(0);
return xValue;
}
}
this.chooseStrictModeFailed("choice", game, getInfo(ability, game)
this.chooseStrictModeFailed("choice", game, getInfo(source, game)
+ "\nMessage: " + message + prepareXMaxInfo(min, max));
return computerPlayer.announceXCost(min, max, message, game, ability, null);
return computerPlayer.announceX(min, max, message, game, source, isManaPay);
}
private String prepareXMaxInfo(int min, int max) {