Fix: GameTest and Game
This commit is contained in:
@@ -589,16 +589,20 @@ public class Game implements Serializable {
|
|||||||
{
|
{
|
||||||
OptionalCardQueue.add(e.getKey());
|
OptionalCardQueue.add(e.getKey());
|
||||||
}
|
}
|
||||||
currentState.PlayerUpdate(OptionalCardQueue.poll(), null);
|
Player optionalPlayer = OptionalCardQueue.poll();
|
||||||
if(currentState.getCurrentPlayer()==null)
|
|
||||||
{
|
if (optionalPlayer != null) {
|
||||||
currentState.GameStageUpdate(GameStages.RESOLVING_EVENT);
|
currentState.PlayerUpdate(optionalPlayer, null);
|
||||||
if(currentState.getRound()<10)
|
return;
|
||||||
{
|
|
||||||
nextRound();
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
currentState.GameStageUpdate(GameStages.RESOLVING_EVENT);
|
||||||
|
|
||||||
|
if (currentState.getRound() < 10) {
|
||||||
|
nextRound();
|
||||||
|
currentState.PlayerUpdate(orderLogicCard.pull(), null);
|
||||||
|
currentState.GameStageUpdate(GameStages.SLOT_CHOICE);
|
||||||
|
} else {
|
||||||
EventResolution();
|
EventResolution();
|
||||||
currentState.GameStageUpdate(GameStages.ENDING);
|
currentState.GameStageUpdate(GameStages.ENDING);
|
||||||
endGame();
|
endGame();
|
||||||
@@ -606,9 +610,8 @@ public class Game implements Serializable {
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GameStages.OPTIONAL_CARD_EFFECT == currentState.getGameStage()) {
|
if (GameStages.OPTIONAL_CARD_EFFECT == currentState.getGameStage()) {
|
||||||
Player optionalPlayer = OptionalCardQueue.poll();
|
Player optionalPlayer = OptionalCardQueue.poll();
|
||||||
|
|
||||||
@@ -621,12 +624,16 @@ public class Game implements Serializable {
|
|||||||
|
|
||||||
if (currentState.getRound() < 10) {
|
if (currentState.getRound() < 10) {
|
||||||
nextRound();
|
nextRound();
|
||||||
|
currentState.PlayerUpdate(orderLogicCard.pull(), null);
|
||||||
|
currentState.GameStageUpdate(GameStages.SLOT_CHOICE);
|
||||||
} else {
|
} else {
|
||||||
EventResolution();
|
EventResolution();
|
||||||
currentState.GameStageUpdate(GameStages.ENDING);
|
currentState.GameStageUpdate(GameStages.ENDING);
|
||||||
endGame();
|
endGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -954,32 +954,75 @@ class GameTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void fullGameShouldEndAfterTenRoundsUsingOnlyPublicGameFlow() {
|
void fullGameShouldEndAfterTenRoundsForTwoThreeAndFourPlayersUsingOnlyPublicGameFlow() {
|
||||||
Game game = new Game(3);
|
for (int nPlayers : new int[]{2, 3, 4}) {
|
||||||
|
Game game = new Game(nPlayers);
|
||||||
|
|
||||||
assertTrue(game.addPlayer(new Player("p1")));
|
for (int i = 1; i <= nPlayers; i++) {
|
||||||
assertTrue(game.addPlayer(new Player("p2")));
|
assertTrue(game.addPlayer(new Player("p" + nPlayers + "_" + i)));
|
||||||
assertTrue(game.addPlayer(new Player("p3")));
|
}
|
||||||
|
|
||||||
assertEquals(GameStages.SLOT_CHOICE, game.getCurrentState().getGameStage());
|
assertEquals(GameStages.SLOT_CHOICE, game.getCurrentState().getGameStage());
|
||||||
|
assertEquals(1, game.getCurrentState().getRound());
|
||||||
|
assertNotNull(game.getCurrentState().getCurrentPlayer());
|
||||||
|
|
||||||
int guard = 0;
|
int guard = 0;
|
||||||
|
|
||||||
while (game.getCurrentState().getGameStage() != GameStages.ENDED && guard < 20) {
|
while (game.getCurrentState().getGameStage() != GameStages.ENDED && guard < 15) {
|
||||||
guard++;
|
guard++;
|
||||||
|
|
||||||
|
int roundBefore = game.getCurrentState().getRound();
|
||||||
|
|
||||||
playOneFullRound(game);
|
playOneFullRound(game);
|
||||||
|
|
||||||
assertTrue(
|
if (roundBefore < 10) {
|
||||||
game.getCurrentState().getGameStage() == GameStages.SLOT_CHOICE
|
assertEquals(
|
||||||
|| game.getCurrentState().getGameStage() == GameStages.ENDED,
|
GameStages.SLOT_CHOICE,
|
||||||
"After a full round, the game should either start the next slot choice phase or end."
|
game.getCurrentState().getGameStage(),
|
||||||
|
"After a non-final round, the game must return to SLOT_CHOICE."
|
||||||
|
);
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
roundBefore + 1,
|
||||||
|
game.getCurrentState().getRound(),
|
||||||
|
"The round number must increase by one after each completed round."
|
||||||
|
);
|
||||||
|
|
||||||
|
assertNotNull(
|
||||||
|
game.getCurrentState().getCurrentPlayer(),
|
||||||
|
"At the beginning of the next round there must be a current player."
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
assertEquals(
|
||||||
|
GameStages.ENDED,
|
||||||
|
game.getCurrentState().getGameStage(),
|
||||||
|
"After round 10, the game must end."
|
||||||
|
);
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
10,
|
||||||
|
game.getCurrentState().getRound(),
|
||||||
|
"The game must end at round 10."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
assertTrue(guard < 20, "Possible infinite loop while playing the full game.");
|
assertTrue(
|
||||||
assertEquals(GameStages.ENDED, game.getCurrentState().getGameStage());
|
guard < 15,
|
||||||
assertEquals(10, game.getCurrentState().getRound());
|
"Possible infinite loop while playing the full game with " + nPlayers + " players."
|
||||||
|
);
|
||||||
|
assertEquals(
|
||||||
|
GameStages.ENDED,
|
||||||
|
game.getCurrentState().getGameStage(),
|
||||||
|
"The game must end after round 10 with " + nPlayers + " players."
|
||||||
|
);
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
10,
|
||||||
|
game.getCurrentState().getRound(),
|
||||||
|
"The game must end at round 10 with " + nPlayers + " players."
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -1039,23 +1082,46 @@ class GameTest {
|
|||||||
completeSlotChoice(game);
|
completeSlotChoice(game);
|
||||||
resolveActionsUntilOptionalCardEffect(game);
|
resolveActionsUntilOptionalCardEffect(game);
|
||||||
|
|
||||||
int guard = 0;
|
resolveOptionalPhaseIfPresent(game);
|
||||||
|
|
||||||
while (game.getCurrentState().getGameStage() == GameStages.OPTIONAL_CARD_EFFECT && guard < 10) {
|
|
||||||
guard++;
|
|
||||||
|
|
||||||
Player current = game.getCurrentState().getCurrentPlayer();
|
|
||||||
assertNotNull(current);
|
|
||||||
|
|
||||||
assertTrue(game.NoOptionalCard(current));
|
|
||||||
}
|
|
||||||
|
|
||||||
assertTrue(guard < 10, "Possible infinite loop during optional phase.");
|
|
||||||
|
|
||||||
assertEquals(GameStages.SLOT_CHOICE, game.getCurrentState().getGameStage());
|
assertEquals(GameStages.SLOT_CHOICE, game.getCurrentState().getGameStage());
|
||||||
assertEquals(roundBefore + 1, game.getCurrentState().getRound());
|
assertEquals(roundBefore + 1, game.getCurrentState().getRound());
|
||||||
assertNotNull(game.getCurrentState().getCurrentPlayer());
|
assertNotNull(game.getCurrentState().getCurrentPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void fourPlayerGameShouldAllowPlayingSlotG() {
|
||||||
|
Game game = new Game(4);
|
||||||
|
|
||||||
|
addPlayers(game, 4, "slot_g_");
|
||||||
|
|
||||||
|
Player playerOnG = completeSlotChoiceAndAdvanceToPlayerOnSlot(game, 'G');
|
||||||
|
|
||||||
|
assertNotNull(playerOnG);
|
||||||
|
assertEquals(GameStages.RESOLVING_ACTIONS, game.getCurrentState().getGameStage());
|
||||||
|
assertEquals(playerOnG, game.getCurrentState().getCurrentPlayer());
|
||||||
|
assertEquals('G', game.getCurrentState().getSlot().getSlotId());
|
||||||
|
|
||||||
|
assertEquals(1, game.getCurrentState().getNLower());
|
||||||
|
assertEquals(2, game.getCurrentState().getNUpper());
|
||||||
|
|
||||||
|
resolveOneMandatoryAction(game);
|
||||||
|
assertEquals(0, game.getCurrentState().getNLower());
|
||||||
|
assertEquals(2, game.getCurrentState().getNUpper());
|
||||||
|
|
||||||
|
resolveOneMandatoryAction(game);
|
||||||
|
assertEquals(0, game.getCurrentState().getNLower());
|
||||||
|
assertEquals(1, game.getCurrentState().getNUpper());
|
||||||
|
|
||||||
|
resolveOneMandatoryAction(game);
|
||||||
|
|
||||||
|
assertFalse(
|
||||||
|
game.getCurrentState().getGameStage() == GameStages.RESOLVING_ACTIONS
|
||||||
|
&& playerOnG.equals(game.getCurrentState().getCurrentPlayer())
|
||||||
|
&& game.getCurrentState().getSlot().getSlotId() == 'G',
|
||||||
|
"After resolving all actions of slot G, the game must not still be resolving slot G for the same player."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user