This commit is contained in:
tool4ever
2022-11-27 23:51:42 +01:00
committed by GitHub
parent 0517613fd3
commit 57c8644469
28 changed files with 95 additions and 100 deletions

View File

@@ -34,7 +34,6 @@ public class SimulationTest {
private static boolean initialized = false;
protected Game initAndCreateGame() {
if (!initialized) {
GuiBase.setInterface(new GuiDesktop());
FModel.initialize(null, new Function<ForgePreferences, Void>() {

View File

@@ -28,7 +28,7 @@ public class ComprehensiveRulesSection103 extends BaseGameSimulationTest {
);
runGame( gameWrapper, PlayerSpecification.PLAYER_2, 1 );
}
@Test
public void test_103_7a_first_player_skips_draw_step_of_first_turn() {
GameWrapper gameWrapper = new GameWrapper(

View File

@@ -35,7 +35,7 @@ public class ComprehensiveRulesSection104 extends BaseGameSimulationTest {
);
runGame( gameWrapper, PlayerSpecification.PLAYER_1, 3 );
}
@Test
public void test_104_2b_effect_may_state_that_player_wins() {
GameWrapper gameWrapper = new GameWrapper(
@@ -47,7 +47,7 @@ public class ComprehensiveRulesSection104 extends BaseGameSimulationTest {
);
runGame( gameWrapper, PlayerSpecification.PLAYER_2, 2 );
}
@Test
public void test_104_3b_player_with_zero_life_loses_the_game() {
GameWrapper gameWrapper = new GameWrapper(
@@ -58,7 +58,7 @@ public class ComprehensiveRulesSection104 extends BaseGameSimulationTest {
);
runGame( gameWrapper, PlayerSpecification.PLAYER_1, 1 );
}
@Test
public void test_104_3b_player_with_less_than_zero_life_loses_the_game() {
GameWrapper gameWrapper = new GameWrapper(
@@ -69,7 +69,7 @@ public class ComprehensiveRulesSection104 extends BaseGameSimulationTest {
);
runGame( gameWrapper, PlayerSpecification.PLAYER_1, 1 );
}
@Test
public void test_104_3b_player_with_less_than_zero_life_loses_the_game_only_when_a_player_receives_priority() {
//The Lightning Helix targeting himself theoretically drops him to -1, but he's back up to 2 before he could lose
@@ -88,7 +88,7 @@ public class ComprehensiveRulesSection104 extends BaseGameSimulationTest {
);
runGame( gameWrapper, PlayerSpecification.PLAYER_1, 1 );
}
@Test
public void test_104_3b_player_with_less_than_zero_life_loses_the_game_only_when_a_player_receives_priority_variant_with_combat() {
//Player 2 has 2 life, then takes 3 combat damage but also gains 2 life from lifelink
@@ -113,13 +113,13 @@ public class ComprehensiveRulesSection104 extends BaseGameSimulationTest {
);
runGame( gameWrapper, PlayerSpecification.PLAYER_2, 1 );
}
@Test
public void test_104_3c_player_who_draws_card_with_empty_library_loses() {
GameWrapper gameWrapper = new GameWrapper( null, null );
runGame( gameWrapper, PlayerSpecification.PLAYER_1, 2 );
}
@Test
public void test_104_3c_player_who_draws_more_cards_than_library_contains_draw_as_much_as_possible_and_loses() {
GameWrapper gameWrapper = new GameWrapper(
@@ -137,7 +137,7 @@ public class ComprehensiveRulesSection104 extends BaseGameSimulationTest {
new CardAssertAction( new CardSpecificationBuilder( "Mountain" ).owner( PlayerSpecification.PLAYER_1 ).hand() )
);
}
@Test
public void test_104_3d_player_with_ten_poison_counters_loses() {
GameWrapper gameWrapper = new GameWrapper(
@@ -148,7 +148,7 @@ public class ComprehensiveRulesSection104 extends BaseGameSimulationTest {
);
runGame( gameWrapper, PlayerSpecification.PLAYER_1, 1 );
}
@Test
public void test_104_3d_player_with_more_than_ten_poison_counters_loses() {
GameWrapper gameWrapper = new GameWrapper(
@@ -159,7 +159,7 @@ public class ComprehensiveRulesSection104 extends BaseGameSimulationTest {
);
runGame( gameWrapper, PlayerSpecification.PLAYER_1, 1 );
}
@Test
public void test_104_3e_effect_may_state_that_player_loses() {
GameWrapper gameWrapper = new GameWrapper(
@@ -176,7 +176,7 @@ public class ComprehensiveRulesSection104 extends BaseGameSimulationTest {
);
runGame( gameWrapper, PlayerSpecification.PLAYER_2, 2 );
}
@Test( enabled = false )//TODO fails, so disable for now. Note that it seems to really be an issue with Forge and this rule, as commenting out the Laboratory Maniac line below (so there's just a loss, not a win), correctly triggers the loss
public void test_104_3f_if_a_player_would_win_and_lose_simultaneously_he_loses() {
/* http://community.wizards.com/content/forum-topic/3199056

View File

@@ -14,7 +14,7 @@ public class CardSpecification implements Specification<Card> {
private final PlayerSpecification owner;
private final PlayerSpecification controller;
private final CardSpecification target;
/*package-local*/ CardSpecification( final String name, final ZoneType zoneType, final PlayerSpecification owner, final PlayerSpecification controller, final CardSpecification target ) {
this.name = name;
this.zoneType = zoneType;
@@ -22,23 +22,23 @@ public class CardSpecification implements Specification<Card> {
this.controller = controller;
this.target = target;
}
public String getName() {
return name;
}
public ZoneType getZoneType() {
return zoneType;
}
public PlayerSpecification getOwner() {
return owner;
}
public PlayerSpecification getController() {
return controller;
}
public CardSpecification getTarget() {
return target;
}

View File

@@ -11,47 +11,47 @@ public class CardSpecificationBuilder {
private PlayerSpecification owner;
private PlayerSpecification controller;
private CardSpecification target;
public CardSpecificationBuilder( final String name ) {
this.name = name;
}
public CardSpecificationBuilder zone( final ZoneType zoneType ) {
this.zoneType = zoneType;
return this;
}
public CardSpecificationBuilder hand() {
return zone( ZoneType.Hand );
}
public CardSpecificationBuilder battlefield() {
return zone( ZoneType.Battlefield );
}
public CardSpecificationBuilder library() {
return zone( ZoneType.Library );
}
public CardSpecificationBuilder graveyard() {
return zone( ZoneType.Graveyard );
}
public CardSpecificationBuilder owner( final PlayerSpecification owner ) {
this.owner = owner;
return this;
}
public CardSpecificationBuilder controller( final PlayerSpecification controller ) {
this.controller = controller;
return this;
}
public CardSpecificationBuilder target( final CardSpecification target ) {
this.target = target;
return this;
}
public CardSpecification build() {
if( StringUtils.isBlank( name ) ) {
throw new IllegalStateException( "Must have a name [" + name + "]" );

View File

@@ -10,16 +10,16 @@ import forge.gamesimulationtests.util.player.PlayerSpecification;
public class GameStateSpecification {
private final List<CardSpecification> cards;
private final Map<String,PlayerSpecification> playerFacts;
/*package*protected*/ GameStateSpecification( final List<CardSpecification> cards, final Map<String,PlayerSpecification> playerFacts ) {
this.cards = cards;
this.playerFacts = playerFacts;
}
public List<CardSpecification> getCards() {
return cards;
}
public Collection<PlayerSpecification> getPlayerFacts() {
return playerFacts.values();
}

View File

@@ -14,21 +14,21 @@ import forge.gamesimulationtests.util.player.PlayerSpecificationBuilder;
public class GameStateSpecificationBuilder {
private final List<CardSpecification> cards;
private final Map<String,PlayerSpecification> playerFacts;
public GameStateSpecificationBuilder() {
cards = new ArrayList<>();
playerFacts = new HashMap<>();
}
public GameStateSpecificationBuilder addCard( final CardSpecification cardSpecification ) {
cards.add( cardSpecification );
return this;
}
public GameStateSpecificationBuilder addCard( final CardSpecificationBuilder cardSpecification ) {
return addCard( cardSpecification.build() );
}
public GameStateSpecificationBuilder addPlayerFact( final PlayerSpecification playerSpecification ) {
if( playerFacts.containsKey( playerSpecification.getName() ) ) {
throw new IllegalStateException( "If you want to specify multiple things about the same player, do it in 1 call" );
@@ -36,11 +36,11 @@ public class GameStateSpecificationBuilder {
playerFacts.put( playerSpecification.getName(), playerSpecification );
return this;
}
public GameStateSpecificationBuilder addPlayerFact( final PlayerSpecificationBuilder playerSpecification ) {
return addPlayerFact( playerSpecification.build() );
}
public GameStateSpecification build() {
return new GameStateSpecification( Collections.unmodifiableList( cards ), Collections.unmodifiableMap( playerFacts ) );
}

View File

@@ -9,25 +9,25 @@ public class PlayerSpecification implements Specification<Player> {
public static final String PLAYER_2_NAME = "Player 2";
public static final PlayerSpecification PLAYER_1 = PlayerSpecificationBuilder.player1().build();
public static final PlayerSpecification PLAYER_2 = PlayerSpecificationBuilder.player2().build();
private final String name;
private final Integer life;
private final Integer poison;
/*package-local*/ PlayerSpecification( final String name, final Integer life, final Integer poison ) {
this.name = name;
this.life = life;
this.poison = poison;
}
public String getName() {
return name;
}
public Integer getLife() {
return life;
}
public Integer getPoison() {
return poison;
}

View File

@@ -6,29 +6,29 @@ public class PlayerSpecificationBuilder {
private final String name;
private Integer life;
private Integer poison;
public PlayerSpecificationBuilder( final String name ) {
this.name = name;
}
public static PlayerSpecificationBuilder player1() {
return new PlayerSpecificationBuilder( PlayerSpecification.PLAYER_1_NAME );
}
public static PlayerSpecificationBuilder player2() {
return new PlayerSpecificationBuilder( PlayerSpecification.PLAYER_2_NAME );
}
public PlayerSpecificationBuilder life( final Integer life ) {
this.life = life;
return this;
}
public PlayerSpecificationBuilder poison( final Integer poison ) {
this.poison = poison;
return this;
}
public PlayerSpecification build() {
if( StringUtils.isBlank( name ) ) {
throw new IllegalStateException( "Must have a name [" + name + "]" );

View File

@@ -8,7 +8,7 @@ import forge.game.phase.PhaseType;
public class ActionPreCondition {
private Integer requiredTurn;
private PhaseType requiredPhaseType;
public boolean isApplicable( Game game ) {
if( requiredTurn != null ) {
if( requiredTurn != game.getPhaseHandler().getTurn() ) {
@@ -21,12 +21,12 @@ public class ActionPreCondition {
return requiredPhaseType == null || requiredPhaseType == game.getPhaseHandler().getPhase();
}
public ActionPreCondition turn( int turn ) {
requiredTurn = turn;
return this;
}
public ActionPreCondition phase( PhaseType phaseType ) {
requiredPhaseType = phaseType;
return this;

View File

@@ -29,7 +29,7 @@ public class ActivateAbilityAction extends BasePlayerAction {
if( abilities.size() > 1 ) {
throw new IllegalStateException( "Multiple abilities found for " + actualCardWithAbility );
}
SpellAbility ability = abilities.get( 0 );
game.getStack().add( ability );
}

View File

@@ -6,19 +6,19 @@ import forge.gamesimulationtests.util.player.PlayerSpecification;
public abstract class BasePlayerAction {
private final PlayerSpecification player;
private ActionPreCondition preCondition;
protected BasePlayerAction( PlayerSpecification player ) {
this.player = player;
}
public PlayerSpecification getPlayer() {
return player;
}
public boolean isApplicable( Game game ) {
return preCondition == null || preCondition.isApplicable( game );
}
public BasePlayerAction when( ActionPreCondition preCondition ) {
this.preCondition = preCondition;
return this;

View File

@@ -9,13 +9,13 @@ import forge.gamesimulationtests.util.player.PlayerSpecification;
public class DeclareAttackersAction extends BasePlayerAction {
private final Map<CardSpecification, PlayerSpecification> playerAttackAssignments;
private final Map<CardSpecification, CardSpecification> planeswalkerAttackAssignments;
public DeclareAttackersAction( PlayerSpecification player ) {
super( player );
playerAttackAssignments = new HashMap<>();
planeswalkerAttackAssignments = new HashMap<>();
}
/**
* Attack the only opponent
*/
@@ -23,12 +23,12 @@ public class DeclareAttackersAction extends BasePlayerAction {
playerAttackAssignments.put( attacker, null );
return this;
}
public DeclareAttackersAction attack( CardSpecification attacker, PlayerSpecification player ) {
playerAttackAssignments.put( attacker, player );
return this;
}
public DeclareAttackersAction attack( CardSpecification attacker, CardSpecification planeswalker ) {
planeswalkerAttackAssignments.put( attacker, planeswalker );
return this;

View File

@@ -8,17 +8,17 @@ import forge.gamesimulationtests.util.player.PlayerSpecification;
public class DeclareBlockersAction extends BasePlayerAction {
private final Multimap<CardSpecification, CardSpecification> blockingAssignments;
public DeclareBlockersAction( PlayerSpecification player ) {
super( player );
blockingAssignments = ArrayListMultimap.create();
}
public DeclareBlockersAction block( CardSpecification attacker, CardSpecification blocker ) {
blockingAssignments.put( attacker, blocker );
return this;
}
public Multimap<CardSpecification, CardSpecification> getBlockingAssignments() {
return blockingAssignments;
}

View File

@@ -13,48 +13,48 @@ import forge.gamesimulationtests.util.playeractions.testactions.TestAction;
public class PlayerActions {
private final List<BasePlayerAction> playerActions;
public PlayerActions( List<? extends BasePlayerAction> playerActions ) {
this.playerActions = new LinkedList<>(playerActions);
}
public PlayerActions( BasePlayerAction... basePlayerActions ) {
this( Arrays.asList( basePlayerActions ) );
}
@SuppressWarnings("unchecked")
public <T> T getNextActionIfApplicable( Player player, Game game, Class<T> actionType ) {
if( playerActions.isEmpty() ) {
return null;
}
final BasePlayerAction nextAction = playerActions.get( 0 );
if( nextAction instanceof TestAction && isRightPlayer( player, game, nextAction ) && isApplicable( nextAction, game ) ) {
playerActions.remove( 0 );
( ( TestAction ) nextAction ).perform( game, player );
return getNextActionIfApplicable( player, game, actionType );
}
if( actionType.isAssignableFrom( nextAction.getClass() ) && isRightPlayer( player, game, nextAction ) && isApplicable( nextAction, game ) ) {
playerActions.remove( 0 );
return ( T ) nextAction;
}
return null;
}
private boolean isApplicable( BasePlayerAction action, Game game ) {
return action != null && action.isApplicable( game );
}
private boolean isRightPlayer( Player player, Game game, BasePlayerAction action ) {
return action.getPlayer() == null || player.equals( PlayerSpecificationHandler.INSTANCE.find( game, action.getPlayer() ) );
}
public boolean isEmpty() {
return playerActions.isEmpty();
}
@Override
public String toString() {
return "PlayerActions : [" + StringUtils.join( playerActions, ", " ) + "]";

View File

@@ -7,9 +7,9 @@ public abstract class AssertAction extends TestAction {
public AssertAction() {
super( null );//AssertActions may be about a player, but they're not really actions taken by a player...
}
public abstract void performAssertion( Game game );
@Override
public void perform( Game game, Player player ) {
performAssertion( game );

View File

@@ -11,11 +11,11 @@ import forge.gamesimulationtests.util.card.CardSpecificationHandler;
public class CardAssertAction extends AssertAction {
private final CardSpecification cardRequirements;
public CardAssertAction( final CardSpecification cardRequirements ) {
this.cardRequirements = cardRequirements;
}
public CardAssertAction( final CardSpecificationBuilder cardRequirements ) {
this( cardRequirements.build() );
}

View File

@@ -8,7 +8,7 @@ public class EndTestAction extends TestAction {
public EndTestAction( PlayerSpecification player ) {
super( player );
}
public void endTest( Player player ) {
player.concede();
}

View File

@@ -11,11 +11,11 @@ import forge.gamesimulationtests.util.player.PlayerSpecificationHandler;
public class PlayerAssertAction extends AssertAction {
private final PlayerSpecification playerRequirements;
public PlayerAssertAction( final PlayerSpecification playerRequirements ) {
this.playerRequirements = playerRequirements;
}
public PlayerAssertAction( final PlayerSpecificationBuilder playerRequirements ) {
this( playerRequirements.build() );
}

View File

@@ -9,6 +9,6 @@ public abstract class TestAction extends BasePlayerAction {
public TestAction( PlayerSpecification player ) {
super( player );
}
public abstract void perform( Game game, Player player );
}

View File

@@ -28,7 +28,7 @@ public class DeckHintsTest {
void setupTest() {
GuiBase.setInterface(new GuiDesktop());
}
/**
* Card test.
*/
@@ -153,7 +153,6 @@ public class DeckHintsTest {
Assert.assertEquals(1, hints.filter(list).size());
}
/**
* Create a CardPrinted from the given filename.
*