forked from External/mage
- WIP: AI and multi targets, human and X=0 use cases, human and impossible targets use cases;
- improved stability and shared logic (related to #13606, #11134, #11666, continue from a53eb66b58, close #13617, close #13613);
- improved test logs and debug info to show more target info on errors;
- improved test framework to support multiple addTarget calls;
- improved test framework to find bad commands order for targets (related to #11666);
- fixed game freezes on auto-choice usages with disconnected or under control players (related to #11285);
- gui, game: fixed that player doesn't mark avatar as selected/green in "up to" targeting;
- gui, game: fixed small font in some popup messages on big screens (related to #969);
- gui, game: added min targets info for target selection dialog;
- for devs: added new cheat option to call and test any game dialog (define own dialogs, targets, etc in HumanDialogsTester);
- for devs: now tests require complete an any or up to target selection by addTarget + TestPlayer.TARGET_SKIP or setChoice + TestPlayer.CHOICE_SKIP (if not all max/possible targets used);
- for devs: added detail targets info for activate/trigger/cast, can be useful to debug unit tests, auto-choose or AI (see DebugUtil.GAME_SHOW_CHOOSE_TARGET_LOGS)
111 lines
5.7 KiB
Java
111 lines
5.7 KiB
Java
package mage.utils.testers;
|
|
|
|
import mage.abilities.Ability;
|
|
import mage.constants.Outcome;
|
|
import mage.game.Game;
|
|
import mage.players.Player;
|
|
import mage.target.TargetAmount;
|
|
import mage.target.Targets;
|
|
import mage.target.common.TargetAnyTargetAmount;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* Part of testable game dialogs
|
|
* <p>
|
|
* Supported methods:
|
|
* - player.chooseTarget(amount)
|
|
*
|
|
* @author JayDi85
|
|
*/
|
|
class ChooseAmountTestableDialog extends BaseTestableDialog {
|
|
|
|
boolean isYou; // who choose - you or opponent
|
|
int distributeAmount;
|
|
int targetsMin;
|
|
int targetsMax;
|
|
|
|
public ChooseAmountTestableDialog(boolean isYou, String name, int distributeAmount, int targetsMin, int targetsMax) {
|
|
super(String.format("player.chooseTarget(%s, amount)", isYou ? "you" : "AI"),
|
|
name,
|
|
String.format("%d between %d-%d targets", distributeAmount, targetsMin, targetsMax));
|
|
this.isYou = isYou;
|
|
this.distributeAmount = distributeAmount;
|
|
this.targetsMin = targetsMin;
|
|
this.targetsMax = targetsMax;
|
|
}
|
|
|
|
@Override
|
|
public List<String> showDialog(Player player, Ability source, Game game, Player opponent) {
|
|
TargetAmount choosingTarget = new TargetAnyTargetAmount(this.distributeAmount, this.targetsMin, this.targetsMax);
|
|
Player choosingPlayer = this.isYou ? player : opponent;
|
|
|
|
// TODO: add "damage" word in ability text, so chooseTargetAmount an show diff dialog (due inner logic - distribute damage or 1/1)
|
|
boolean chooseRes = choosingPlayer.chooseTargetAmount(Outcome.Benefit, choosingTarget, source, game);
|
|
List<String> result = new ArrayList<>();
|
|
if (chooseRes) {
|
|
Targets.printDebugTargets(getGroup() + " - " + this.getName() + " - " + "TRUE", new Targets(choosingTarget), source, game, result);
|
|
} else {
|
|
Targets.printDebugTargets(getGroup() + " - " + this.getName() + " - " + "FALSE", new Targets(choosingTarget), source, game, result);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
static public void register(TestableDialogsRunner runner) {
|
|
// test game started with 2 players and 1 land on battlefield
|
|
// so it's better to use target limits like 0, 1, 3, 5, max
|
|
|
|
List<Boolean> isYous = Arrays.asList(false, true);
|
|
|
|
for (boolean isYou : isYous) {
|
|
// up to
|
|
runner.registerDialog(new ChooseAmountTestableDialog(isYou, "up to", 0, 0, 0));
|
|
runner.registerDialog(new ChooseAmountTestableDialog(isYou, "up to", 0, 0, 1));
|
|
runner.registerDialog(new ChooseAmountTestableDialog(isYou, "up to", 0, 0, 3));
|
|
runner.registerDialog(new ChooseAmountTestableDialog(isYou, "up to", 0, 0, 5));
|
|
//
|
|
runner.registerDialog(new ChooseAmountTestableDialog(isYou, "up to, invalid", 1, 0, 0));
|
|
runner.registerDialog(new ChooseAmountTestableDialog(isYou, "up to", 1, 0, 1));
|
|
runner.registerDialog(new ChooseAmountTestableDialog(isYou, "up to", 1, 0, 3));
|
|
runner.registerDialog(new ChooseAmountTestableDialog(isYou, "up to", 1, 0, 5));
|
|
//
|
|
runner.registerDialog(new ChooseAmountTestableDialog(isYou, "up to, invalid", 2, 0, 0));
|
|
runner.registerDialog(new ChooseAmountTestableDialog(isYou, "up to", 2, 0, 1));
|
|
runner.registerDialog(new ChooseAmountTestableDialog(isYou, "up to", 2, 0, 3));
|
|
runner.registerDialog(new ChooseAmountTestableDialog(isYou, "up to", 2, 0, 5));
|
|
//
|
|
runner.registerDialog(new ChooseAmountTestableDialog(isYou, "up to, invalid", 3, 0, 0));
|
|
runner.registerDialog(new ChooseAmountTestableDialog(isYou, "up to", 3, 0, 1));
|
|
runner.registerDialog(new ChooseAmountTestableDialog(isYou, "up to", 3, 0, 3));
|
|
runner.registerDialog(new ChooseAmountTestableDialog(isYou, "up to", 3, 0, 5));
|
|
//
|
|
runner.registerDialog(new ChooseAmountTestableDialog(isYou, "up to, invalid", 5, 0, 0));
|
|
runner.registerDialog(new ChooseAmountTestableDialog(isYou, "up to", 5, 0, 1));
|
|
runner.registerDialog(new ChooseAmountTestableDialog(isYou, "up to", 5, 0, 3));
|
|
runner.registerDialog(new ChooseAmountTestableDialog(isYou, "up to", 5, 0, 5));
|
|
|
|
// need target
|
|
runner.registerDialog(new ChooseAmountTestableDialog(isYou, "need", 0, 1, 1));
|
|
runner.registerDialog(new ChooseAmountTestableDialog(isYou, "need", 0, 1, 3));
|
|
runner.registerDialog(new ChooseAmountTestableDialog(isYou, "need", 0, 1, 5));
|
|
//
|
|
runner.registerDialog(new ChooseAmountTestableDialog(isYou, "need", 1, 1, 1));
|
|
runner.registerDialog(new ChooseAmountTestableDialog(isYou, "need", 1, 1, 3));
|
|
runner.registerDialog(new ChooseAmountTestableDialog(isYou, "need", 1, 1, 5));
|
|
//
|
|
runner.registerDialog(new ChooseAmountTestableDialog(isYou, "need", 2, 1, 1));
|
|
runner.registerDialog(new ChooseAmountTestableDialog(isYou, "need", 2, 1, 3));
|
|
runner.registerDialog(new ChooseAmountTestableDialog(isYou, "need", 2, 1, 5));
|
|
//
|
|
runner.registerDialog(new ChooseAmountTestableDialog(isYou, "need", 3, 1, 1));
|
|
runner.registerDialog(new ChooseAmountTestableDialog(isYou, "need", 3, 1, 3));
|
|
runner.registerDialog(new ChooseAmountTestableDialog(isYou, "need", 3, 1, 5));
|
|
//
|
|
runner.registerDialog(new ChooseAmountTestableDialog(isYou, "need", 5, 1, 1));
|
|
runner.registerDialog(new ChooseAmountTestableDialog(isYou, "need", 5, 1, 3));
|
|
runner.registerDialog(new ChooseAmountTestableDialog(isYou, "need", 5, 1, 5));
|
|
}
|
|
}
|
|
}
|