mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 02:30:08 -08:00
- 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
6.3 KiB
Java
111 lines
6.3 KiB
Java
package mage.utils.testers;
|
|
|
|
import mage.abilities.Ability;
|
|
import mage.cards.Card;
|
|
import mage.cards.Cards;
|
|
import mage.cards.CardsImpl;
|
|
import mage.constants.Outcome;
|
|
import mage.constants.SubType;
|
|
import mage.filter.FilterCard;
|
|
import mage.filter.StaticFilters;
|
|
import mage.game.Game;
|
|
import mage.players.Player;
|
|
import mage.target.TargetCard;
|
|
import mage.target.Targets;
|
|
import mage.target.common.TargetCardInHand;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.List;
|
|
import java.util.stream.Collectors;
|
|
|
|
/**
|
|
* Part of testable game dialogs
|
|
* <p>
|
|
* Supported methods:
|
|
* - player.choose(cards)
|
|
* - player.chooseTarget(cards)
|
|
*
|
|
* @author JayDi85
|
|
*/
|
|
class ChooseCardsTestableDialog extends BaseTestableDialog {
|
|
|
|
TargetCard target;
|
|
boolean isTargetChoice; // how to choose - by xxx.choose or xxx.chooseTarget
|
|
boolean isYou; // who choose - you or opponent
|
|
|
|
public ChooseCardsTestableDialog(boolean isTargetChoice, boolean notTarget, boolean isYou, String name, TargetCard target) {
|
|
super(String.format("%s(%s, %s, cards)",
|
|
isTargetChoice ? "player.chooseTarget" : "player.choose",
|
|
isYou ? "you" : "AI",
|
|
notTarget ? "not target" : "target"), name, target.toString());
|
|
this.isTargetChoice = isTargetChoice;
|
|
this.target = target.withNotTarget(notTarget);
|
|
this.isYou = isYou;
|
|
}
|
|
|
|
@Override
|
|
public List<String> showDialog(Player player, Ability source, Game game, Player opponent) {
|
|
TargetCard choosingTarget = this.target.copy();
|
|
Player choosingPlayer = this.isYou ? player : opponent;
|
|
|
|
// make sure hand go first, so user can test diff type of targets
|
|
List<Card> all = new ArrayList<>();
|
|
all.addAll(choosingPlayer.getHand().getCards(game));
|
|
//all.addAll(choosingPlayer.getLibrary().getCards(game));
|
|
Cards choosingCards = new CardsImpl(all.stream().limit(100).collect(Collectors.toList()));
|
|
|
|
boolean chooseRes;
|
|
if (this.isTargetChoice) {
|
|
chooseRes = choosingPlayer.chooseTarget(Outcome.Benefit, choosingCards, choosingTarget, source, game);
|
|
} else {
|
|
chooseRes = choosingPlayer.choose(Outcome.Benefit, choosingCards, 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 7 cards in hand and 1 draw
|
|
// so it's better to use target limits like 0, 1, 3, 9, max
|
|
|
|
FilterCard anyCard = StaticFilters.FILTER_CARD;
|
|
FilterCard impossibleCard = new FilterCard();
|
|
impossibleCard.add(SubType.TROOPER.getPredicate());
|
|
|
|
List<Boolean> notTargets = Arrays.asList(false, true);
|
|
List<Boolean> isYous = Arrays.asList(false, true);
|
|
List<Boolean> isTargetChoices = Arrays.asList(false, true);
|
|
for (boolean notTarget : notTargets) {
|
|
for (boolean isYou : isYous) {
|
|
for (boolean isTargetChoice : isTargetChoices) {
|
|
runner.registerDialog(new ChooseCardsTestableDialog(isTargetChoice, notTarget, isYou, "hand 0, X=0", new TargetCardInHand(0, 0, anyCard)));
|
|
runner.registerDialog(new ChooseCardsTestableDialog(isTargetChoice, notTarget, isYou, "hand 1", new TargetCardInHand(1, anyCard)));
|
|
runner.registerDialog(new ChooseCardsTestableDialog(isTargetChoice, notTarget, isYou, "hand 3", new TargetCardInHand(3, anyCard)));
|
|
runner.registerDialog(new ChooseCardsTestableDialog(isTargetChoice, notTarget, isYou, "hand 9", new TargetCardInHand(9, anyCard)));
|
|
runner.registerDialog(new ChooseCardsTestableDialog(isTargetChoice, notTarget, isYou, "hand 0-1", new TargetCardInHand(0, 1, anyCard)));
|
|
runner.registerDialog(new ChooseCardsTestableDialog(isTargetChoice, notTarget, isYou, "hand 0-3", new TargetCardInHand(0, 3, anyCard)));
|
|
runner.registerDialog(new ChooseCardsTestableDialog(isTargetChoice, notTarget, isYou, "hand 0-9", new TargetCardInHand(0, 9, anyCard)));
|
|
runner.registerDialog(new ChooseCardsTestableDialog(isTargetChoice, notTarget, isYou, "hand any", new TargetCardInHand(0, Integer.MAX_VALUE, anyCard)));
|
|
runner.registerDialog(new ChooseCardsTestableDialog(isTargetChoice, notTarget, isYou, "hand 1-3", new TargetCardInHand(1, 3, anyCard)));
|
|
runner.registerDialog(new ChooseCardsTestableDialog(isTargetChoice, notTarget, isYou, "hand 2-3", new TargetCardInHand(2, 3, anyCard)));
|
|
runner.registerDialog(new ChooseCardsTestableDialog(isTargetChoice, notTarget, isYou, "hand 2-9", new TargetCardInHand(2, 9, anyCard)));
|
|
runner.registerDialog(new ChooseCardsTestableDialog(isTargetChoice, notTarget, isYou, "hand 8-9", new TargetCardInHand(8, 9, anyCard)));
|
|
//
|
|
runner.registerDialog(new ChooseCardsTestableDialog(isTargetChoice, notTarget, isYou, "impossible 0, X=0", new TargetCardInHand(0, impossibleCard)));
|
|
runner.registerDialog(new ChooseCardsTestableDialog(isTargetChoice, notTarget, isYou, "impossible 1", new TargetCardInHand(1, impossibleCard)));
|
|
runner.registerDialog(new ChooseCardsTestableDialog(isTargetChoice, notTarget, isYou, "impossible 3", new TargetCardInHand(3, impossibleCard)));
|
|
runner.registerDialog(new ChooseCardsTestableDialog(isTargetChoice, notTarget, isYou, "impossible 0-1", new TargetCardInHand(0, 1, impossibleCard)));
|
|
runner.registerDialog(new ChooseCardsTestableDialog(isTargetChoice, notTarget, isYou, "impossible 0-3", new TargetCardInHand(0, 3, impossibleCard)));
|
|
runner.registerDialog(new ChooseCardsTestableDialog(isTargetChoice, notTarget, isYou, "impossible any", new TargetCardInHand(0, Integer.MAX_VALUE, impossibleCard)));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|