Add: Improve game flow and endgame tests
This commit is contained in:
@@ -5,6 +5,9 @@ import it.polimi.ingsw.gc14.Model.Cards.TribeCard;
|
|||||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Character;
|
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Character;
|
||||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType;
|
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType;
|
||||||
import it.polimi.ingsw.gc14.Model.GamePackage.GameStages;
|
import it.polimi.ingsw.gc14.Model.GamePackage.GameStages;
|
||||||
|
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters.Artist;
|
||||||
|
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters.Builder;
|
||||||
|
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters.Inventor;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.Timeout;
|
import org.junit.jupiter.api.Timeout;
|
||||||
|
|
||||||
@@ -77,9 +80,8 @@ class GameTest {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!game.getLowerListBuilding().isEmpty()) {
|
if (!game.getLowerListBuilding().isEmpty()
|
||||||
current.addFood(100);
|
&& game.DrawLowerBuildingCardByIndex(current, 0)) {
|
||||||
assertTrue(game.DrawLowerBuildingCardByIndex(current, 0));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,9 +97,8 @@ class GameTest {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!game.getUpperListBuilding().isEmpty()) {
|
if (!game.getUpperListBuilding().isEmpty()
|
||||||
current.addFood(100);
|
&& game.DrawUpperBuildingCardByIndex(current, 0)) {
|
||||||
assertTrue(game.DrawUpperBuildingCardByIndex(current, 0));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -294,7 +295,7 @@ class GameTest {
|
|||||||
assertTrue(game.addPlayer(p3));
|
assertTrue(game.addPlayer(p3));
|
||||||
|
|
||||||
Queue<Player> players = new LinkedList<>();
|
Queue<Player> players = new LinkedList<>();
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < game.getNPlayers(); i++) {
|
||||||
players.add(game.getCurrentState().getCurrentPlayer());
|
players.add(game.getCurrentState().getCurrentPlayer());
|
||||||
assertTrue(game.SlotChoiceByIndex(game.getCurrentState().getCurrentPlayer(), i));
|
assertTrue(game.SlotChoiceByIndex(game.getCurrentState().getCurrentPlayer(), i));
|
||||||
}
|
}
|
||||||
@@ -337,11 +338,14 @@ class GameTest {
|
|||||||
assertFalse(game.DrawUpperTribeCardByIndex(temp_player, eventIndex));
|
assertFalse(game.DrawUpperTribeCardByIndex(temp_player, eventIndex));
|
||||||
}
|
}
|
||||||
|
|
||||||
temp_player.addFood(100);
|
|
||||||
|
|
||||||
assertFalse(game.getUpperListBuilding().isEmpty());
|
assertFalse(game.getUpperListBuilding().isEmpty());
|
||||||
|
|
||||||
|
temp_player.builders.clear();
|
||||||
|
|
||||||
index = 0;
|
index = 0;
|
||||||
|
BuildingCard selectedBuilding = game.getUpperListBuilding().get(index);
|
||||||
|
temp_player.addFood(selectedBuilding.getPrice());
|
||||||
|
|
||||||
assertTrue(game.DrawUpperBuildingCardByIndex(temp_player, index));
|
assertTrue(game.DrawUpperBuildingCardByIndex(temp_player, index));
|
||||||
|
|
||||||
int remainingTribeIndex = firstNonEventIndexOrMinusOne(game.getUpperListTribeCards());
|
int remainingTribeIndex = firstNonEventIndexOrMinusOne(game.getUpperListTribeCards());
|
||||||
@@ -445,15 +449,30 @@ class GameTest {
|
|||||||
|
|
||||||
assertFalse(game.getUpperListBuilding().isEmpty());
|
assertFalse(game.getUpperListBuilding().isEmpty());
|
||||||
|
|
||||||
current.addFood(100);
|
current.builders.clear();
|
||||||
|
|
||||||
|
BuildingCard selectedBuilding = game.getUpperListBuilding().get(0);
|
||||||
|
int expectedCost = selectedBuilding.getPrice();
|
||||||
|
|
||||||
|
current.addFood(expectedCost);
|
||||||
|
|
||||||
int foodBefore = current.getFoodValue();
|
|
||||||
int buildingsBefore = current.buildingCards.size();
|
int buildingsBefore = current.buildingCards.size();
|
||||||
|
int upperBuildingsBefore = game.getUpperListBuilding().size();
|
||||||
|
int foodBefore = current.getFoodValue();
|
||||||
|
|
||||||
assertTrue(game.PickOptionalBuildingCard(current, 0));
|
assertTrue(game.PickOptionalBuildingCard(current, 0));
|
||||||
|
|
||||||
assertTrue(current.getFoodValue() < foodBefore);
|
|
||||||
assertEquals(buildingsBefore + 1, current.buildingCards.size());
|
assertEquals(buildingsBefore + 1, current.buildingCards.size());
|
||||||
|
assertEquals(upperBuildingsBefore - 1, game.getUpperListBuilding().size());
|
||||||
|
|
||||||
|
assertTrue(current.buildingCards.stream()
|
||||||
|
.anyMatch(building ->
|
||||||
|
building.getPrice() == selectedBuilding.getPrice()
|
||||||
|
&& building.getPrestigeValue() == selectedBuilding.getPrestigeValue()
|
||||||
|
&& building.getEffectId() == selectedBuilding.getEffectId()
|
||||||
|
));
|
||||||
|
|
||||||
|
assertEquals(foodBefore - expectedCost, current.getFoodValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -807,6 +826,8 @@ class GameTest {
|
|||||||
assertTrue(current.removeFood(1));
|
assertTrue(current.removeFood(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
current.builders.clear();
|
||||||
|
|
||||||
assertEquals(0, current.getFoodValue());
|
assertEquals(0, current.getFoodValue());
|
||||||
|
|
||||||
assertFalse(
|
assertFalse(
|
||||||
@@ -816,6 +837,7 @@ class GameTest {
|
|||||||
|
|
||||||
assertFalse(game.PickOptionalBuildingCard(current, 0));
|
assertFalse(game.PickOptionalBuildingCard(current, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void toStringModel() {
|
void toStringModel() {
|
||||||
Game game=new Game(5);
|
Game game=new Game(5);
|
||||||
@@ -832,8 +854,8 @@ class GameTest {
|
|||||||
assertTrue(game.addPlayer(p5));
|
assertTrue(game.addPlayer(p5));
|
||||||
|
|
||||||
Queue<Player>players=new LinkedList<>();
|
Queue<Player>players=new LinkedList<>();
|
||||||
for(int i=0;i<3;i++) {
|
for (int i = 0; i < game.getNPlayers(); i++) {
|
||||||
players.add( game.getCurrentState().getCurrentPlayer());
|
players.add(game.getCurrentState().getCurrentPlayer());
|
||||||
assertTrue(game.SlotChoiceByIndex(game.getCurrentState().getCurrentPlayer(), i));
|
assertTrue(game.SlotChoiceByIndex(game.getCurrentState().getCurrentPlayer(), i));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -864,7 +886,12 @@ class GameTest {
|
|||||||
if (game.getCurrentState().getNLower() > 0
|
if (game.getCurrentState().getNLower() > 0
|
||||||
&& !game.getLowerListBuilding().isEmpty()) {
|
&& !game.getLowerListBuilding().isEmpty()) {
|
||||||
|
|
||||||
current.addFood(100);
|
current.builders.clear();
|
||||||
|
|
||||||
|
BuildingCard selectedBuilding = game.getLowerListBuilding().get(0);
|
||||||
|
int expectedCost = selectedBuilding.getPrice();
|
||||||
|
|
||||||
|
current.addFood(expectedCost);
|
||||||
|
|
||||||
int buildingsBefore = current.buildingCards.size();
|
int buildingsBefore = current.buildingCards.size();
|
||||||
int lowerBuildingsBefore = game.getLowerListBuilding().size();
|
int lowerBuildingsBefore = game.getLowerListBuilding().size();
|
||||||
@@ -877,8 +904,16 @@ class GameTest {
|
|||||||
|
|
||||||
assertEquals(buildingsBefore + 1, current.buildingCards.size());
|
assertEquals(buildingsBefore + 1, current.buildingCards.size());
|
||||||
assertEquals(lowerBuildingsBefore - 1, game.getLowerListBuilding().size());
|
assertEquals(lowerBuildingsBefore - 1, game.getLowerListBuilding().size());
|
||||||
assertTrue(current.getFoodValue() < foodBefore);
|
assertTrue(current.buildingCards.stream()
|
||||||
|
.anyMatch(building ->
|
||||||
|
building.getPrice() == selectedBuilding.getPrice()
|
||||||
|
&& building.getPrestigeValue() == selectedBuilding.getPrestigeValue()
|
||||||
|
&& building.getEffectId() == selectedBuilding.getEffectId()
|
||||||
|
));
|
||||||
|
assertTrue(
|
||||||
|
current.getFoodValue() >= foodBefore - expectedCost,
|
||||||
|
"After buying the building, food should not be lower than the price paid because later effects may add food."
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -908,14 +943,16 @@ class GameTest {
|
|||||||
Player current = game.getCurrentState().getCurrentPlayer();
|
Player current = game.getCurrentState().getCurrentPlayer();
|
||||||
|
|
||||||
if (game.getCurrentState().getNUpper() > 0
|
if (game.getCurrentState().getNUpper() > 0
|
||||||
&& !game.getUpperListBuilding().isEmpty()
|
&& !game.getUpperListBuilding().isEmpty()) {
|
||||||
&& current.builders.isEmpty()) {
|
|
||||||
|
|
||||||
while (current.getFoodValue() > 0) {
|
while (current.getFoodValue() > 0) {
|
||||||
assertTrue(current.removeFood(1));
|
assertTrue(current.removeFood(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
current.builders.clear();
|
||||||
|
|
||||||
assertEquals(0, current.getFoodValue());
|
assertEquals(0, current.getFoodValue());
|
||||||
|
|
||||||
assertFalse(game.DrawUpperBuildingCardByIndex(current, 0));
|
assertFalse(game.DrawUpperBuildingCardByIndex(current, 0));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -923,7 +960,7 @@ class GameTest {
|
|||||||
resolveOneMandatoryAction(game);
|
resolveOneMandatoryAction(game);
|
||||||
}
|
}
|
||||||
|
|
||||||
fail("No upper building draw state reached with a player without builders.");
|
fail("No upper building draw state reached.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -952,4 +989,110 @@ class GameTest {
|
|||||||
|
|
||||||
assertEquals(firstChooser, game.getCurrentState().getCurrentPlayer());
|
assertEquals(firstChooser, game.getCurrentState().getCurrentPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Timeout(value = 20, unit = TimeUnit.SECONDS)
|
||||||
|
void endGameShouldNotCrashWhenTriggeredAfterRoundTen() {
|
||||||
|
Game game = new Game(3);
|
||||||
|
|
||||||
|
List<Player> players = addPlayers(game, 3, "end_game_");
|
||||||
|
|
||||||
|
giveOptionalEffectToAllPlayers(players.get(0), players.get(1), players.get(2));
|
||||||
|
|
||||||
|
while (game.getCurrentState().getRound() < 10) {
|
||||||
|
playOneFullRound(game);
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals(10, game.getCurrentState().getRound());
|
||||||
|
assertEquals(GameStages.SLOT_CHOICE, game.getCurrentState().getGameStage());
|
||||||
|
|
||||||
|
completeSlotChoice(game);
|
||||||
|
resolveAllMandatoryActions(game);
|
||||||
|
|
||||||
|
assertEquals(GameStages.OPTIONAL_CARD_EFFECT, game.getCurrentState().getGameStage());
|
||||||
|
|
||||||
|
assertDoesNotThrow(() -> resolveOptionalPhaseIfPresent(game));
|
||||||
|
|
||||||
|
assertEquals(GameStages.ENDED, game.getCurrentState().getGameStage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Timeout(value = 20, unit = TimeUnit.SECONDS)
|
||||||
|
void endGameShouldAddBuildingPrestigeValues() {
|
||||||
|
Game game = new Game(3);
|
||||||
|
|
||||||
|
List<Player> players = addPlayers(game, 3, "building_prestige_");
|
||||||
|
|
||||||
|
giveOptionalEffectToAllPlayers(players.get(0), players.get(1), players.get(2));
|
||||||
|
|
||||||
|
while (game.getCurrentState().getRound() < 10) {
|
||||||
|
playOneFullRound(game);
|
||||||
|
}
|
||||||
|
|
||||||
|
completeSlotChoice(game);
|
||||||
|
resolveAllMandatoryActions(game);
|
||||||
|
|
||||||
|
assertEquals(GameStages.OPTIONAL_CARD_EFFECT, game.getCurrentState().getGameStage());
|
||||||
|
|
||||||
|
Player player = players.get(0);
|
||||||
|
|
||||||
|
int prestigeBefore = player.getPrestigeValue();
|
||||||
|
|
||||||
|
player.buildingCards.add(new BuildingCard(12, 1, 1, 7));
|
||||||
|
player.buildingCards.add(new BuildingCard(12, 1, 1, 5));
|
||||||
|
|
||||||
|
int expectedMinimumIncrease = 7 + 5;
|
||||||
|
|
||||||
|
resolveOptionalPhaseIfPresent(game);
|
||||||
|
|
||||||
|
assertEquals(GameStages.ENDED, game.getCurrentState().getGameStage());
|
||||||
|
|
||||||
|
assertTrue(
|
||||||
|
player.getPrestigeValue() >= prestigeBefore + expectedMinimumIncrease,
|
||||||
|
"Final scoring should add at least the prestige values of the two added building cards."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Timeout(value = 20, unit = TimeUnit.SECONDS)
|
||||||
|
void endGameShouldApplyFinalCharacterPrestigeBonuses() {
|
||||||
|
Game game = new Game(3);
|
||||||
|
|
||||||
|
List<Player> players = addPlayers(game, 3, "final_characters_");
|
||||||
|
giveOptionalEffectToAllPlayers(players.get(0), players.get(1), players.get(2));
|
||||||
|
|
||||||
|
while (game.getCurrentState().getRound() < 10) {
|
||||||
|
playOneFullRound(game);
|
||||||
|
}
|
||||||
|
|
||||||
|
completeSlotChoice(game);
|
||||||
|
resolveAllMandatoryActions(game);
|
||||||
|
|
||||||
|
assertEquals(GameStages.OPTIONAL_CARD_EFFECT, game.getCurrentState().getGameStage());
|
||||||
|
|
||||||
|
Player player = players.get(0);
|
||||||
|
assertNotNull(player);
|
||||||
|
|
||||||
|
int prestigeBefore = player.getPrestigeValue();
|
||||||
|
|
||||||
|
player.builders.add(new Builder(1, 0, 4));
|
||||||
|
|
||||||
|
player.inventors.add(new Inventor(1, 0));
|
||||||
|
player.inventors.add(new Inventor(1, 1));
|
||||||
|
|
||||||
|
player.artists.add(new Artist(1));
|
||||||
|
player.artists.add(new Artist(1));
|
||||||
|
|
||||||
|
int expectedMinimumIncrease = 4 + 4 + 10;
|
||||||
|
|
||||||
|
resolveOptionalPhaseIfPresent(game);
|
||||||
|
|
||||||
|
assertEquals(GameStages.ENDED, game.getCurrentState().getGameStage());
|
||||||
|
|
||||||
|
assertTrue(
|
||||||
|
player.getPrestigeValue() >= prestigeBefore + expectedMinimumIncrease,
|
||||||
|
"Final scoring should add at least builder prestige, inventor bonus, and artist pair bonus."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user