mirror of
https://github.com/magefree/mage.git
synced 2025-12-23 12:02:01 -08:00
Updated TestPlayer + Tests to deal with duplicate initial turns
This commit is contained in:
parent
5431895ad8
commit
f97fc6f708
2 changed files with 25 additions and 10 deletions
|
|
@ -120,6 +120,10 @@ public class TestPlayer implements Player {
|
||||||
|
|
||||||
private String[] groupsForTargetHandling = null;
|
private String[] groupsForTargetHandling = null;
|
||||||
|
|
||||||
|
// Tracks the initial turns (turn 0s) both players are given at the start of the game.
|
||||||
|
// Before actual turns start. Needed for checking attacker/blocker legality in the tests
|
||||||
|
private static int initialTurns = 0;
|
||||||
|
|
||||||
public TestPlayer(ComputerPlayer computerPlayer) {
|
public TestPlayer(ComputerPlayer computerPlayer) {
|
||||||
this.computerPlayer = computerPlayer;
|
this.computerPlayer = computerPlayer;
|
||||||
AIPlayer = false;
|
AIPlayer = false;
|
||||||
|
|
@ -170,6 +174,10 @@ public class TestPlayer implements Player {
|
||||||
this.maxCallsWithoutAction = maxCallsWithoutAction;
|
this.maxCallsWithoutAction = maxCallsWithoutAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setInitialTurns(int turns) {
|
||||||
|
initialTurns = turns;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private Permanent findPermanent(FilterPermanent filter, String name, UUID controllerID, Game game) {
|
private Permanent findPermanent(FilterPermanent filter, String name, UUID controllerID, Game game) {
|
||||||
return findPermanent(filter, name, controllerID, game, true);
|
return findPermanent(filter, name, controllerID, game, true);
|
||||||
|
|
@ -214,7 +222,7 @@ public class TestPlayer implements Player {
|
||||||
return null;
|
return null;
|
||||||
} else if (allPermanents.size() - 1 < index) {
|
} else if (allPermanents.size() - 1 < index) {
|
||||||
if (failOnNotFound)
|
if (failOnNotFound)
|
||||||
throw new AssertionError("Cannot find " + filteredName + ":" + index + " that match the filter criteria \"" + filter.getMessage() + "\"" + ".\n Only " + allPermanents.size() + " called " + filteredName + " found for this controller(zero indexed).");
|
throw new AssertionError("Cannot find " + filteredName + ":" + index + " that match the filter criteria \"" + filter.getMessage() + "\"" + ".\nOnly " + allPermanents.size() + " called " + filteredName + " found for this controller(zero indexed).");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return allPermanents.get(index);
|
return allPermanents.get(index);
|
||||||
|
|
@ -548,7 +556,15 @@ public class TestPlayer implements Player {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkLegalMovesThisAttack(Game game) {
|
/*
|
||||||
|
* Iterates through each player on the current turn and asserts if they can attack or block legally this turn
|
||||||
|
*/
|
||||||
|
private void checkLegalMovesThisTurn(Game game) {
|
||||||
|
// Each player is given priority before actual turns start for e.g. leylines and pre-game initialisation
|
||||||
|
if(initialTurns < game.getPlayers().size()) {
|
||||||
|
initialTurns++;
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Check actions for next turn are going to be valid
|
// Check actions for next turn are going to be valid
|
||||||
int turnNum = game.getTurnNum();
|
int turnNum = game.getTurnNum();
|
||||||
// Loop through all game players and check if they are allowed to attack/block this turn
|
// Loop through all game players and check if they are allowed to attack/block this turn
|
||||||
|
|
@ -580,8 +596,6 @@ public class TestPlayer implements Player {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void selectAttackers(Game game, UUID attackingPlayerId) {
|
public void selectAttackers(Game game, UUID attackingPlayerId) {
|
||||||
// Check if attackers and blocks are legal this turn
|
|
||||||
checkLegalMovesThisAttack(game);
|
|
||||||
// Loop through players and validate can attack/block this turn
|
// Loop through players and validate can attack/block this turn
|
||||||
UUID defenderId = null;
|
UUID defenderId = null;
|
||||||
for (PlayerAction action : actions) {
|
for (PlayerAction action : actions) {
|
||||||
|
|
@ -637,11 +651,6 @@ public class TestPlayer implements Player {
|
||||||
@Override
|
@Override
|
||||||
public void selectBlockers(Game game, UUID defendingPlayerId) {
|
public void selectBlockers(Game game, UUID defendingPlayerId) {
|
||||||
|
|
||||||
if(game.getActivePlayerId().equals(defendingPlayerId)) {
|
|
||||||
String playerName = game.getPlayer(defendingPlayerId).getName();
|
|
||||||
throw new UnsupportedOperationException(playerName + " can't block as it's their turn");
|
|
||||||
}
|
|
||||||
|
|
||||||
UUID opponentId = game.getOpponents(computerPlayer.getId()).iterator().next();
|
UUID opponentId = game.getOpponents(computerPlayer.getId()).iterator().next();
|
||||||
// Map of Blocker reference -> list of creatures blocked
|
// Map of Blocker reference -> list of creatures blocked
|
||||||
Map<MageObjectReference, List<MageObjectReference>> blockedCreaturesByCreature = new HashMap<>();
|
Map<MageObjectReference, List<MageObjectReference>> blockedCreaturesByCreature = new HashMap<>();
|
||||||
|
|
@ -1215,11 +1224,13 @@ public class TestPlayer implements Player {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(Game game) {
|
public void init(Game game) {
|
||||||
|
initialTurns = 0;
|
||||||
computerPlayer.init(game);
|
computerPlayer.init(game);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(Game game, boolean testMode) {
|
public void init(Game game, boolean testMode) {
|
||||||
|
initialTurns = 0;
|
||||||
computerPlayer.init(game, testMode);
|
computerPlayer.init(game, testMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1240,6 +1251,7 @@ public class TestPlayer implements Player {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void beginTurn(Game game) {
|
public void beginTurn(Game game) {
|
||||||
|
checkLegalMovesThisTurn(game);
|
||||||
computerPlayer.beginTurn(game);
|
computerPlayer.beginTurn(game);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2296,3 +2308,4 @@ public class TestPlayer implements Player {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,6 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
|
||||||
currentGame = createNewGameAndPlayers();
|
currentGame = createNewGameAndPlayers();
|
||||||
|
|
||||||
activePlayer = playerA;
|
activePlayer = playerA;
|
||||||
|
|
||||||
stopOnTurn = 2;
|
stopOnTurn = 2;
|
||||||
stopAtStep = PhaseStep.UNTAP;
|
stopAtStep = PhaseStep.UNTAP;
|
||||||
|
|
||||||
|
|
@ -132,9 +131,12 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
|
||||||
getHandCards(testPlayer).clear();
|
getHandCards(testPlayer).clear();
|
||||||
getBattlefieldCards(testPlayer).clear();
|
getBattlefieldCards(testPlayer).clear();
|
||||||
getGraveCards(testPlayer).clear();
|
getGraveCards(testPlayer).clear();
|
||||||
|
// Reset the turn counter for tests
|
||||||
|
((TestPlayer) player).setInitialTurns(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
gameOptions = new GameOptions();
|
gameOptions = new GameOptions();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract protected Game createNewGameAndPlayers() throws GameException, FileNotFoundException;
|
abstract protected Game createNewGameAndPlayers() throws GameException, FileNotFoundException;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue