Fix: full model refactor

This commit is contained in:
2026-06-14 12:28:53 +02:00
parent 9a931bfc1b
commit 85f2dd9208
24 changed files with 311 additions and 253 deletions
@@ -349,7 +349,7 @@ public class GameEventProcessor {
* @return a new {@link ArrayList} of disconnected usernames.
*/
private ArrayList<String> buildDisconnectedList(Game game) {
return game.disconnectedPlayers.entrySet().stream()
return game.getDisconnectedPlayers().entrySet().stream()
.filter(Map.Entry::getValue)
.map(e -> e.getKey().getUserName())
.collect(Collectors.toCollection(ArrayList::new));
@@ -53,7 +53,7 @@ public class DecksCreator {
InputStream is = DecksCreator.class.getResourceAsStream(resourcePath);
if (is == null) {
throw new RuntimeException("File non trovato: " + resourcePath);
throw new RuntimeException("Resource file not found: " + resourcePath);
}
try (Reader reader = new InputStreamReader(is)) {
@@ -64,7 +64,7 @@ public class DecksCreator {
}
return cards;
} catch (IOException e) {
throw new RuntimeException("Errore caricamento mazzo: " + resourcePath, e);
throw new RuntimeException("Error loading deck: " + resourcePath, e);
}
}
@@ -94,7 +94,7 @@ public class DecksCreator {
InputStream is = DecksCreator.class.getResourceAsStream(resourcePath);
if (is == null) {
throw new RuntimeException("File non trovato: " + resourcePath);
throw new RuntimeException("Resource file not found: " + resourcePath);
}
try (Reader reader = new InputStreamReader(is)) {
@@ -105,7 +105,7 @@ public class DecksCreator {
}
return cards;
} catch (IOException e) {
throw new RuntimeException("Errore caricamento mazzo: " + resourcePath, e);
throw new RuntimeException("Error loading deck: " + resourcePath, e);
}
}
@@ -143,7 +143,7 @@ public class DecksCreator {
case "Hunt" -> new Hunt(def.id,era,p[0]);
case "CavePaintings" -> new CavePaintings(def.id,era,p[0],p[1],p[2]);
case "ShamanicRitual" -> new ShamanicRitual(def.id,era,p[0],p[1]);
default -> throw new IllegalArgumentException("Tipo sconosciuto: " + def.type);
default -> throw new IllegalArgumentException("Unknown event type: " + def.type);
};
}
return switch (def.type) {
@@ -153,29 +153,29 @@ public class DecksCreator {
case "Builder" -> switch (p.length) {
case 2 -> new Builder(def.id,era, p[0], p[1]);
case 3 -> new Builder(def.id,era, p[0], p[1], p[2]);
default -> throw new IllegalArgumentException("Builder: parametri non validi");
default -> throw new IllegalArgumentException("Builder: invalid parameters");
};
case "Gatherer" -> switch (p.length) {
case 0 -> new Gatherer(def.id,era);
case 1 -> new Gatherer(def.id,era, p[0]);
default -> throw new IllegalArgumentException("Gatherer: parametri non validi");
default -> throw new IllegalArgumentException("Gatherer: invalid parameters");
};
case "Artist" -> switch (p.length) {
case 0 -> new Artist(def.id,era);
case 1 -> new Artist(def.id,era, p[0]);
default -> throw new IllegalArgumentException("Artist: parametri non validi");
default -> throw new IllegalArgumentException("Artist: invalid parameters");
};
case "Inventor" -> switch (p.length) {
case 1 -> new Inventor(def.id,era, p[0]);
case 2 -> new Inventor(def.id,era, p[0], p[1]);
default -> throw new IllegalArgumentException("Inventor: parametri non validi");
default -> throw new IllegalArgumentException("Inventor: invalid parameters");
};
case "Shaman" -> switch (p.length) {
case 1 -> new Shaman(def.id,era, p[0]);
case 2 -> new Shaman(def.id,era, p[0], p[1]);
default -> throw new IllegalArgumentException("Shaman: parametri non validi");
default -> throw new IllegalArgumentException("Shaman: invalid parameters");
};
default -> throw new IllegalArgumentException("Tipo sconosciuto: " + def.type);
default -> throw new IllegalArgumentException("Unknown card type: " + def.type);
};
}
@@ -212,7 +212,7 @@ public class DecksCreator {
int era;
boolean armed;
boolean isEvent;
List<Object> params; // Object per gestire boolean e int misti
List<Object> params; // Object to support mixed boolean and numeric parameters from JSON
}
/**
@@ -225,6 +225,6 @@ public class DecksCreator {
int era;
int price;
int prestigeValue;
List<Object> params; // Object per gestire boolean e int misti
List<Object> params; // Object to support mixed boolean and numeric parameters from JSON
}
}
@@ -84,7 +84,7 @@ public class Game implements Serializable {
* @return {@code true} if the choice is applied successfully, {@code false} otherwise.
*/
public synchronized boolean totemChoice(Player player,Totems totem) {
if(!currentState.getGameStage().equals(GameStages.TOTEM_CHOICE))
if(currentState.getGameStage() != GameStages.TOTEM_CHOICE)
return false;
if(!getCurrentState().getCurrentPlayer().equals(player))
return false;
@@ -120,8 +120,18 @@ public class Game implements Serializable {
/**
* Map tracking the players who are currently disconnected.
* Key: player; value: {@code true} if currently disconnected, {@code false} if reconnected.
*/
public Map<Player,Boolean> disconnectedPlayers = new HashMap<>();
private Map<Player,Boolean> disconnectedPlayers = new HashMap<>();
/**
* Returns an unmodifiable view of the disconnected-players map.
*
* @return map from player to disconnection status.
*/
public Map<Player,Boolean> getDisconnectedPlayers() {
return Collections.unmodifiableMap(disconnectedPlayers);
}
/**
* Marks the specified player as disconnected and updates the game flow accordingly.
@@ -142,13 +152,13 @@ public class Game implements Serializable {
return false;
}
disconnectedPlayers.put(player,true);
if (currentState.getGameStage().equals(GameStages.WAITING)) {
if (currentState.getGameStage() == GameStages.WAITING) {
playersList.remove(player);
totemChoiceQueue.remove(player);
return true;
}
if(currentState.getCurrentPlayer().equals(player)) {
if (!currentState.getGameStage().equals(GameStages.TOTEM_CHOICE)) {
if (currentState.getGameStage() != GameStages.TOTEM_CHOICE) {
nextPlayerSetup();
return true;
}
@@ -184,15 +194,15 @@ public class Game implements Serializable {
return false;
}
disconnectedPlayers.put(player,false);
if(currentState.getGameStage().equals(GameStages.SLOT_CHOICE) )
if(currentState.getGameStage() == GameStages.SLOT_CHOICE)
{
disconnectedPlayers.remove(player);
if(!orderLogicCard.players.contains(player))
if(!orderLogicCard.containsInQueue(player))
{
orderLogicCard.pushNoEffect(player);
}
}
else if(currentState.getGameStage().equals(GameStages.RES_ACTIONS)) {
else if(currentState.getGameStage() == GameStages.RES_ACTIONS) {
if(slotMap.containsValue(player))
{
disconnectedPlayers.remove(player);
@@ -247,7 +257,7 @@ public class Game implements Serializable {
/**
* The queue of players involved in optional card resolution.
*/
private Queue<Player> OptionalCardQueue;
private Queue<Player> optionalCardQueue;
/**
* The order logic card associated with this game.
@@ -274,39 +284,39 @@ public class Game implements Serializable {
public Board getBoard() {return board;}
/**
* Returns clones of the upper tribe cards currently available on the board.
* Returns a copy of the upper tribe cards currently available on the board.
*
* @return a list containing clones of the upper tribe cards currently available on the board.
* @return a new list containing the upper tribe cards currently on the board.
*/
public ArrayList<TribeCard> getUpperListTribeCards() {
return (ArrayList<TribeCard>)board.upperListTribe;
return new ArrayList<>(board.getUpperListTribe());
}
/**
* Returns clones of the lower tribe cards currently available on the board.
* Returns a copy of the lower tribe cards currently available on the board.
*
* @return a list containing clones of the lower tribe cards currently available on the board.
* @return a new list containing the lower tribe cards currently on the board.
*/
public ArrayList<TribeCard> getLowerListTribeCards() {
return (ArrayList<TribeCard> )board.lowerListTribe;
return new ArrayList<>(board.getLowerListTribe());
}
/**
* Returns clones of the upper building cards currently available on the board.
* Returns a copy of the upper building cards currently available on the board.
*
* @return a list containing clones of the upper building cards currently available on the board.
* @return a new list containing the upper building cards currently on the board.
*/
public ArrayList<BuildingCard> getUpperListBuilding() {
return (ArrayList<BuildingCard>)board.upperListBuilding;
return new ArrayList<>(board.getUpperListBuilding());
}
/**
* Returns clones of the lower building cards currently available on the board.
* Returns a copy of the lower building cards currently available on the board.
*
* @return a list containing clones of the lower building cards currently available on the board.
* @return a new list containing the lower building cards currently on the board.
*/
public ArrayList<BuildingCard> getLowerListBuilding() {
return (ArrayList<BuildingCard>) board.lowerListBuilding;
return new ArrayList<>(board.getLowerListBuilding());
}
/**
@@ -316,7 +326,7 @@ public class Game implements Serializable {
*/
public CurrentState getCurrentState() {
return currentState;
};
}
/**
* Returns the player with the specified username, if present.
@@ -357,7 +367,7 @@ public class Game implements Serializable {
}
currentState= new CurrentState();
playersList = new ArrayList<>();
OptionalCardQueue = new LinkedList<>();
optionalCardQueue = new LinkedList<>();
}
/**
@@ -482,7 +492,7 @@ public class Game implements Serializable {
* @return {@code true} if the draw succeeds, {@code false} otherwise.
*/
public boolean drawUpperTribeCardByIndex(Player player,int cardIndex) {
if( cardIndex<0 || cardIndex >=board.upperListTribe.size())
if( cardIndex<0 || cardIndex >=board.getUpperListTribe().size())
return false;
if(currentState.getGameStage()!= GameStages.RES_ACTIONS && currentState.getGameStage()!=GameStages.OPT_CARD_E)
{
@@ -494,7 +504,7 @@ public class Game implements Serializable {
}
if(currentState.getNUpper() <1 && currentState.getGameStage()==GameStages.RES_ACTIONS)
return false;
TribeCard tribeCard = board.upperListTribe.get(cardIndex);
TribeCard tribeCard = board.getUpperListTribe().get(cardIndex);
if(tribeCard.isEventCard())
return false;
@@ -525,7 +535,7 @@ public class Game implements Serializable {
* @return {@code true} if the skip succeeds, {@code false} otherwise.
*/
public boolean skipTurn(Player player) {
if(currentState.getGameStage()!= GameStages.RES_ACTIONS && !currentState.getGameStage().equals(GameStages.OPT_CARD_E))
if(currentState.getGameStage() != GameStages.RES_ACTIONS && currentState.getGameStage() != GameStages.OPT_CARD_E)
{
return false;
}
@@ -565,7 +575,7 @@ public class Game implements Serializable {
* @return {@code true} if the draw succeeds, {@code false} otherwise.
*/
public boolean drawLowerTribeCardByIndex(Player player, int cardIndex) {
if( cardIndex<0 || cardIndex >=board.lowerListTribe.size())
if( cardIndex<0 || cardIndex >=board.getLowerListTribe().size())
return false;
if(currentState.getGameStage()!= GameStages.RES_ACTIONS)
{
@@ -579,7 +589,7 @@ public class Game implements Serializable {
if(currentState.getNLower() <1)
return false;
TribeCard tribeCard = board.lowerListTribe.get(cardIndex);
TribeCard tribeCard = board.getLowerListTribe().get(cardIndex);
if(tribeCard.isEventCard())
return false;
@@ -606,7 +616,7 @@ public class Game implements Serializable {
* @return {@code true} if the draw succeeds, {@code false} otherwise.
*/
public boolean drawUpperBuildingCardByIndex(Player player,int cardIndex) {
if( cardIndex<0 || cardIndex >=board.upperListBuilding.size())
if( cardIndex<0 || cardIndex >=board.getUpperListBuilding().size())
return false;
if(currentState.getGameStage()!= GameStages.RES_ACTIONS && currentState.getGameStage()!=GameStages.OPT_CARD_E)
{
@@ -616,7 +626,7 @@ public class Game implements Serializable {
{
return false;
}
BuildingCard buildingCard = board.upperListBuilding.get(cardIndex);
BuildingCard buildingCard = board.getUpperListBuilding().get(cardIndex);
if(currentState.getNUpper() <1 && currentState.getGameStage()==GameStages.RES_ACTIONS)
return false;
if(!buildingCard.buy(player))
@@ -624,7 +634,7 @@ public class Game implements Serializable {
return false;
}
board.removeUpperBuildingCard(buildingCard);
if(currentState.getGameStage().equals(GameStages.RES_ACTIONS))
if(currentState.getGameStage() == GameStages.RES_ACTIONS)
{
currentState.upperDrawn();
if((currentState.getNLower() ==0 ||( !hasDrawableDown() && getLowerListBuilding().isEmpty())) && ((currentState.getNUpper() ==0)||(!hasDrawableUp() && getUpperListBuilding().isEmpty())))
@@ -650,7 +660,7 @@ public class Game implements Serializable {
* @return {@code true} if the draw succeeds, {@code false} otherwise.
*/
public boolean drawLowerBuildingCardByIndex(Player player,int cardIndex) {
if( cardIndex<0 || cardIndex >=board.lowerListBuilding.size())
if( cardIndex<0 || cardIndex >=board.getLowerListBuilding().size())
return false;
if(currentState.getGameStage()!= GameStages.RES_ACTIONS)
{
@@ -661,7 +671,7 @@ public class Game implements Serializable {
{
return false;
}
BuildingCard buildingCard = board.lowerListBuilding.get(cardIndex);
BuildingCard buildingCard = board.getLowerListBuilding().get(cardIndex);
if(currentState.getNLower() <1)
return false;
if(buildingCard.buy(player))
@@ -788,7 +798,7 @@ public class Game implements Serializable {
}
if (GameStages.OPT_CARD_E == currentState.getGameStage()) {
Player optionalPlayer = OptionalCardQueue.poll();
Player optionalPlayer = optionalCardQueue.poll();
if (optionalPlayer != null) {
currentState.playerUpdate(optionalPlayer, null);
@@ -821,7 +831,7 @@ public class Game implements Serializable {
private synchronized void transitionToOptionalOrNextRound() {
currentState.gameStageUpdate(GameStages.OPT_CARD_E);
OptionalCardQueue = new LinkedList<>();
optionalCardQueue = new LinkedList<>();
for (Player p :playersList) {
long count = p.getBuildingCards().stream().filter(x -> x.getEffectId() == 12).count();
if (count > 0) {
@@ -829,11 +839,11 @@ public class Game implements Serializable {
{
continue;
}
OptionalCardQueue.add(p);
optionalCardQueue.add(p);
}
}
Player optionalPlayer = OptionalCardQueue.poll();
Player optionalPlayer = optionalCardQueue.poll();
if (optionalPlayer != null) {
currentState.playerUpdate(optionalPlayer, null);
@@ -847,8 +857,7 @@ public class Game implements Serializable {
orderLogicCard.pushNoEffect(entry.getKey());
disconnectedPlayers.remove(entry.getKey());
} else {
orderLogicCard.players.removeIf(x -> x.equals(entry.getKey()));
orderLogicCard.playerList.removeIf(x -> x.player.equals(entry.getKey()));
orderLogicCard.removeFromQueue(entry.getKey());
}
}
currentState.playerUpdate(orderLogicCard.pull(), null);
@@ -927,7 +936,7 @@ public class Game implements Serializable {
*/
private void endGame() {
Queue<EventCard> events;
events=Stream.concat(board.lowerListTribe.stream().filter(TribeCard::isEventCard),board.upperListTribe.stream().filter(TribeCard::isEventCard)).map(x->((EventCard)x)).collect(Collectors.toCollection(LinkedList::new));
events=Stream.concat(board.getLowerListTribe().stream().filter(TribeCard::isEventCard),board.getUpperListTribe().stream().filter(TribeCard::isEventCard)).map(x->((EventCard)x)).collect(Collectors.toCollection(LinkedList::new));
ArrayList<EventCard>sustenance=events.stream().filter(x->x.getType().equals(EventType.SUSTENANCE)).collect(Collectors.toCollection(ArrayList::new));
events.removeAll(sustenance);
events.forEach(event->event.activateEvent(playersList));
@@ -985,7 +994,7 @@ public class Game implements Serializable {
currentState = new CurrentState();
playersList = new ArrayList<>();
OptionalCardQueue = new LinkedList<>();
optionalCardQueue = new LinkedList<>();
return true;
}
@@ -29,20 +29,48 @@ public class Board implements Serializable {
* The upper row of tribe cards. It contains a total of
* {@code nTotem + 4} tribe cards, which may include both character and event cards.
*/
public List<TribeCard> upperListTribe;
private List<TribeCard> upperListTribe;
/**
* The lower row of the tribe card. During the first round, there will be (num. of players + 1) character cards.
* During the following rounds, lower row will be emptied and populated with upper row's cards.
* When an Event card gets in the lower row, the event effect will be activated at the end of the round.
*/
public List<TribeCard> lowerListTribe;
private List<TribeCard> lowerListTribe;
/** Contains all the building cards of the upper list. When a new era starts, all its building cards are placed here */
public List<BuildingCard> upperListBuilding;
/** Contains all the building cards of the upper list. When a new era starts, all its building cards are placed here. */
private List<BuildingCard> upperListBuilding;
/** Contains all the building cards of the lower list. When a new era starts, the old era's buildings are moved from the upper to the lower list */
public List<BuildingCard> lowerListBuilding;
/** Contains all the building cards of the lower list. When a new era starts, the old era's buildings are moved from the upper to the lower list. */
private List<BuildingCard> lowerListBuilding;
/**
* Returns the upper row of tribe cards.
*
* @return the live upper tribe card list.
*/
public List<TribeCard> getUpperListTribe() { return upperListTribe; }
/**
* Returns the lower row of tribe cards.
*
* @return the live lower tribe card list.
*/
public List<TribeCard> getLowerListTribe() { return lowerListTribe; }
/**
* Returns the upper row of building cards.
*
* @return the live upper building card list.
*/
public List<BuildingCard> getUpperListBuilding() { return upperListBuilding; }
/**
* Returns the lower row of building cards.
*
* @return the live lower building card list.
*/
public List<BuildingCard> getLowerListBuilding() { return lowerListBuilding; }
private final ArrayList<List<BuildingCard>> buildingCardsAllEras;
@@ -244,6 +272,7 @@ public class Board implements Serializable {
for(int i=0;i<nTotem+4;i++)
{
if (tribeDeck.isEmpty()) break;
TribeCard tempCard = tribeDeck.remove();
if(tempCard.getEra()!=era)
{
@@ -151,10 +151,10 @@ public class CurrentState implements Serializable {
/**
* Updates the current game stage.
*
* @param GameStage the new game stage.
* @param stage the new game stage.
*/
public void gameStageUpdate(GameStages gameStage){
this.gameStage = gameStage;
public void gameStageUpdate(GameStages stage){
this.gameStage = stage;
}
// endregion setters
@@ -179,12 +179,12 @@ public class CurrentState implements Serializable {
// region Functions
/**
* Updates the current player and slot.
* If the specified slot is {@code null}, the numbers of upper and lower cards are both set to 0.
* Otherwise, the numbers of upper and lower cards are updated using the values of the specified slot.
* Updates the current player, slot, and available draws.
* If {@code slot} is {@code null}, both {@link #nUpper} and {@link #nLower} are reset to 0.
* Otherwise they are set from the slot's values.
*
* @param player the new current player.
* @param slot the new current slot.
* @param slot the new current slot, or {@code null} when no slot is active.
*/
public void playerUpdate(Player player, Slot slot){
this.player = player;
@@ -36,7 +36,7 @@ public enum GameStages {
RES_EVENT("Event"),
/**
* Stage in which end-of-round or end-of-game operations are processed.
* Stage in which end-of-game scoring and ranking are computed.
*/
ENDING("Ending"),
@@ -1,10 +0,0 @@
package it.polimi.ingsw.gc14.Model;
/** Standalone entry point used for local model testing. */
public class Main {
/** @param args unused. */
public static void main(String[] args) {
}
}
@@ -107,7 +107,7 @@ public class MiniModel implements Serializable {
this.slotPlayerMap = slotPlayerMap;
this.orderLogicCard = orderLogicCard;
this.currentState = currentState;
this.players = new HashMap<>();
this.players = new LinkedHashMap<>();
this.availableTotems = availableTotems;
this.standingPlayers = new ArrayList<>();
this.upperListTribeCards = upperListTribeCards;
@@ -20,12 +20,22 @@ public abstract class OrderLogicCard implements Serializable {
/**
* The queue of {@link Player Players} associated with this order logic card.
*/
public Queue<Player> players;
private Queue<Player> players;
/**
* The list of {@link Player Players} associated with this order logic card.
* The list of {@link OrderPlayer} entries tracking turn order and played status.
* Protected so subclasses can read it for display purposes (e.g., {@link #toString()}).
*/
public List<OrderPlayer> playerList;
protected List<OrderPlayer> playerList;
/**
* Returns an unmodifiable view of the player order list.
*
* @return the list of {@link OrderPlayer} entries in turn order.
*/
public List<OrderPlayer> getPlayerList() {
return Collections.unmodifiableList(playerList);
}
/** Total number of players in this game. */
protected final int nPlayers;
@@ -33,9 +43,13 @@ public abstract class OrderLogicCard implements Serializable {
/**
* Creates an order logic card with the specified list of players.
* The input list is shuffled before being inserted into the queue.
*
* <p>The input list is shuffled in place to establish a random initial turn order.
* This is intentional: the caller's list (typically {@code Game.playersList}) is
* reordered so that the game's canonical player sequence reflects the randomised order.
*
* @param players the list of players associated with this order logic card.
* <strong>The list is mutated (shuffled) by this constructor.</strong>
*/
public OrderLogicCard(ArrayList<Player> players) {
Collections.shuffle(players);
@@ -52,14 +66,11 @@ public abstract class OrderLogicCard implements Serializable {
*/
public void push(Player player) {
effect(player, players.size());
if(players.size()==0)
{
if (players.size() == 0) {
playerList.clear();
}
playerList.add(new OrderPlayer(player, false));
players.add(player);
}
/**
@@ -72,7 +83,7 @@ public abstract class OrderLogicCard implements Serializable {
*/
public void pushNoEffect(Player player) {
players.removeIf(x -> player.getUserName().equals(x.getUserName()));
playerList.removeIf(x->player.getUserName().equals(x.player.getUserName()));
playerList.removeIf(x -> player.getUserName().equals(x.getPlayer().getUserName()));
playerList.add(new OrderPlayer(player, false));
players.add(player);
}
@@ -87,9 +98,8 @@ public abstract class OrderLogicCard implements Serializable {
*/
public Player pull() {
for (OrderPlayer p : playerList) {
if(p.played==false)
{
p.played=true;
if (!p.isPlayed()) {
p.markAsPlayed();
break;
}
}
@@ -122,10 +132,30 @@ public abstract class OrderLogicCard implements Serializable {
*
* @param player the player to whom the building effect is applied.
*/
protected void buildingEffect(Player player)
{
for(BuildingCard b : player.getBuildingCards().stream().filter(x->x.getEffectId()==3).toList())
player.addFood(1);
protected void buildingEffect(Player player) {
long count = player.getBuildingCards().stream().filter(x -> x.getEffectId() == 3).count();
player.addFood((int) count);
}
/**
* Returns whether the given player is currently present in the turn queue.
*
* @param player the player to look up.
* @return {@code true} if the player is in the queue; {@code false} otherwise.
*/
public boolean containsInQueue(Player player) {
return players.contains(player);
}
/**
* Removes the given player from both the turn queue and the order list.
* No-op if the player is not present.
*
* @param player the player to remove.
*/
public void removeFromQueue(Player player) {
players.removeIf(x -> x.equals(player));
playerList.removeIf(x -> x.getPlayer().equals(player));
}
/**
@@ -137,11 +167,10 @@ public abstract class OrderLogicCard implements Serializable {
* username is present in the order list.
* @see Player
*/
public int getPosition(String username)
{
public int getPosition(String username) {
int pos = 0;
for (OrderPlayer p : playerList) {
if (p.player.getUserName().equals(username))
if (p.getPlayer().getUserName().equals(username))
return pos;
pos++;
}
@@ -70,10 +70,10 @@ public class Order2 extends OrderLogicCard {
for(int i=0;i<2;i++)
{
try {
if(playerList.get(i).played)
if(playerList.get(i).isPlayed())
stringUp.add("");
else
stringUp.add(playerList.get(i).player.getTotem() != null ? playerList.get(i).player.getTotem().toString() : playerList.get(i).player.getUserName());
stringUp.add(playerList.get(i).getPlayer().getTotem() != null ? playerList.get(i).getPlayer().getTotem().toString() : playerList.get(i).getPlayer().getUserName());
}
catch (IndexOutOfBoundsException e) {
stringUp.add("");
@@ -74,10 +74,10 @@ public class Order3 extends OrderLogicCard {
for(int i=0;i<3;i++)
{
try {
if(playerList.get(i).played)
if(playerList.get(i).isPlayed())
stringUp.add("");
else
stringUp.add(i + ". " + (playerList.get(i).player.getTotem() != null ? playerList.get(i).player.getTotem().toString() : playerList.get(i).player.getUserName()));
stringUp.add(i + ". " + (playerList.get(i).getPlayer().getTotem() != null ? playerList.get(i).getPlayer().getTotem().toString() : playerList.get(i).getPlayer().getUserName()));
}
catch (IndexOutOfBoundsException e) {
stringUp.add("");
@@ -80,10 +80,10 @@ public class Order4 extends OrderLogicCard {
for(int i=0;i<4;i++)
{
try {
if(playerList.get(i).played)
if(playerList.get(i).isPlayed())
stringUp.add("");
else
stringUp.add(i + ". " + (playerList.get(i).player.getTotem() != null ? playerList.get(i).player.getTotem().toString() : playerList.get(i).player.getUserName()));
stringUp.add(i + ". " + (playerList.get(i).getPlayer().getTotem() != null ? playerList.get(i).getPlayer().getTotem().toString() : playerList.get(i).getPlayer().getUserName()));
}
catch (IndexOutOfBoundsException e) {
stringUp.add("");
@@ -81,10 +81,10 @@ public class Order5 extends OrderLogicCard {
for(int i=0;i<5;i++)
{
try {
if(playerList.get(i).played)
if(playerList.get(i).isPlayed())
stringUp.add("");
else
stringUp.add(i + ". " + (playerList.get(i).player.getTotem() != null ? playerList.get(i).player.getTotem().toString() : playerList.get(i).player.getUserName()));
stringUp.add(i + ". " + (playerList.get(i).getPlayer().getTotem() != null ? playerList.get(i).getPlayer().getTotem().toString() : playerList.get(i).getPlayer().getUserName()));
}
catch (IndexOutOfBoundsException e) {
stringUp.add("");
@@ -15,12 +15,37 @@ public class OrderPlayer implements Serializable {
/**
* The player associated with this order entry.
*/
public Player player;
private final Player player;
/**
* Indicates whether the player has already played.
*/
public boolean played;
private boolean played;
/**
* Returns the player associated with this order entry.
*
* @return the player.
*/
public Player getPlayer() {
return player;
}
/**
* Returns whether the player has already played in this order sequence.
*
* @return {@code true} if the player has played; {@code false} otherwise.
*/
public boolean isPlayed() {
return played;
}
/**
* Marks this player as having played in the current order sequence.
*/
public void markAsPlayed() {
this.played = true;
}
/**
* Creates an order entry for the specified player.
@@ -39,13 +39,13 @@ public abstract class PlayableCard implements Serializable {
/**
* Creates a playable card with the specified era.
*
* @param Era the era of the playable card.
* @throws IllegalArgumentException if {@code Era <= 0} or {@code Era >= 4}.
* @param era the era of the playable card.
* @throws IllegalArgumentException if {@code era <= 0} or {@code era >= 4}.
*/
public PlayableCard (int Era) throws IllegalArgumentException{
public PlayableCard(int era) throws IllegalArgumentException {
idIMG = "-1";
if (Era>0 && Era<4) {
this.era = Era;
if (era > 0 && era < 4) {
this.era = era;
} else {
throw new IllegalArgumentException();
}
@@ -55,22 +55,22 @@ public abstract class PlayableCard implements Serializable {
* Creates a playable card with the specified image id and era.
*
* @param idIMG the image identifier of the playable card.
* @param Era the era of the playable card.
* @throws IllegalArgumentException if {@code Era <= 0} or {@code Era >= 4}.
* @param era the era of the playable card.
* @throws IllegalArgumentException if {@code era <= 0} or {@code era >= 4}.
*/
public PlayableCard (String idIMG,int Era) throws IllegalArgumentException{
public PlayableCard(String idIMG, int era) throws IllegalArgumentException {
this.idIMG = idIMG;
if (Era>0 && Era<4) {
this.era = Era;
if (era > 0 && era < 4) {
this.era = era;
} else {
throw new IllegalArgumentException();
}
}
/**
* Returns the string representation of this playable card.
* Returns a string representation of this playable card.
*
* @return the string representation of this playable card.
* @return a string representation of this playable card.
*/
@Override
public String toString() {
@@ -78,14 +78,11 @@ public abstract class PlayableCard implements Serializable {
}
/**
* Prints a string representation of this {@code PlayableCard}. This specific variation is used in the {@code Game}'s
* toString to print a more detailed version (in this specific case the two methods are equal).
* @return {@code String} - a string representation of this {@code PlayableCard}.
* @see it.polimi.ingsw.gc14.Model.Game Game
* @see it.polimi.ingsw.gc14.Model.GamePackage.Board Board
* Returns a compact string representation used when rendering the board in the TUI.
*
* @return a compact board representation of this card.
*/
public String toStringBoard()
{
public String toStringBoard() {
return ":";
}
}
@@ -20,7 +20,7 @@ public class Player implements Serializable {
/**
* The maximum length allowed for the username string.
*/
private static final int MAX_VALUE = 32;
private static final int MAX_USERNAME_LENGTH = 32;
/**
* Identifier for the {@code Player} when displaying the game through the GUI.
@@ -135,11 +135,8 @@ public class Player implements Serializable {
// region Setters
/**
* Adds {@code Value} amount of {@code Food} to the Player.
* @param value The amount of {@code Food} to be added.
* Should be positive for expected results
* (otherwise the method will subtract the absolute
* value of {@code Value}).
* Adds {@code value} amount of Food to the Player.
* @param value The amount of Food to be added. Should be non-negative.
* @see #foodValue
*/
public void addFood(int value){
@@ -156,20 +153,15 @@ public class Player implements Serializable {
}
/**
* Removes {@code Value} amount of {@code Food} from the Player.
* Note: {@link #foodValue} cannot be negative, so the method returns
* {@code false} if {@code Value} is greater than the amount of {@code Food}
* the Player possesses, and {@code true} otherwise.
* Removes {@code value} amount of Food from the Player.
* {@link #foodValue} cannot go negative: returns {@code false} if
* {@code value} exceeds the current food and leaves the value unchanged.
*
* @param value The amount of {@code Food} to be removed.
* Should be positive for expected results
* (otherwise the method will add the absolute
* value of {@code Value}).
* @return {@code Boolean} - {@code true} if the Food is successfully removed,
* {@code false} otherwise.
* @param value The amount of Food to be removed. Should be non-negative.
* @return {@code true} if the Food is successfully removed, {@code false} otherwise.
* @see #foodValue
*/
public Boolean removeFood(int value){
public boolean removeFood(int value){
if(value > this.foodValue){
return false;
}
@@ -178,28 +170,20 @@ public class Player implements Serializable {
}
/**
* Adds {@code Value} amount of {@code Prestige} to the Player.
* @param value The amount of {@code Prestige} to be added.
* Should be positive for expected results
* (otherwise the method will subtract the absolute
* value of {@code Value}).
* Adds {@code value} amount of Prestige to the Player.
* @param value The amount of Prestige to be added. Should be non-negative.
* @see #prestigeValue
*/
public void addPrestige(int value){
this.prestigeValue += value;
}
/**
* Removes {@code Value} amount of {@code Prestige} to the Player.
* @param value The amount of {@code Prestige} to be removed.
* Should be positive for expected results
* (otherwise the method will add the absolute
* value of {@code Value}).
* Removes {@code value} amount of Prestige from the Player.
* @param value The amount of Prestige to be removed. Should be non-negative.
* @see #prestigeValue
*/
public void removePrestige(int value){
this.prestigeValue -= value;
}
@@ -211,15 +195,15 @@ public class Player implements Serializable {
* Constructor for the class {@code Player}. Each Player is uniquely identified by the {@link #userName}.
*
* @param userName Unique String identifier for a Player.
* @throws IllegalArgumentException when {@code UserName} is empty or exceeds {@link #MAX_VALUE},
* @throws IllegalArgumentException when {@code userName} is empty or exceeds {@link #MAX_USERNAME_LENGTH},
* with message:
* <pre>{@code UserName is empty or exceeds maximum permitted length.}</pre>
*
* @see #userName
* @see #MAX_VALUE
* @see #MAX_USERNAME_LENGTH
*/
public Player(String userName) throws IllegalArgumentException {
if(userName.isEmpty() || userName.length() > MAX_VALUE) {
if(userName.isEmpty() || userName.length() > MAX_USERNAME_LENGTH) {
throw new IllegalArgumentException("UserName is empty or exceeds maximum permitted length.");
}
this.userName = userName;
@@ -80,9 +80,6 @@ public class Slot implements Serializable {
}
// End getters
// Setters
// End setters
// Constructors
/**
@@ -157,15 +154,15 @@ public class Slot implements Serializable {
/**
* Prints a string representation of this {@code Slot}. This specific variation is used in the {@code Game}'s
* toString to print a more detailed version for the TUI implementation.
* <p>includes:
* <li>{@link #slotId SlotId}
* <li>{@link #NUpper NUpper}
* <li>{@link #NLower NLower}
* <li>{@link #Food Food}
* </p>
* @return {@code String} - a string representation of this {@code Slot}.
* Returns a compact string representation of this {@code Slot} for the TUI.
* <p>Includes:
* <ul>
* <li>{@link #slotId}</li>
* <li>{@link #nUpper} (shown as symbols)</li>
* <li>{@link #nLower} (shown as symbols)</li>
* <li>{@link #food} (if non-zero)</li>
* </ul>
* @return a compact TUI string representation of this {@code Slot}.
* @see it.polimi.ingsw.gc14.Model.Game Game
* @see it.polimi.ingsw.gc14.Model.GamePackage.Board Board
*/
@@ -179,8 +176,6 @@ public class Slot implements Serializable {
return s.toString();
}
// End Constructors
// Functions
@Override
@@ -129,7 +129,7 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer {
System.out.println("Reconnected player: " + username);
startWatchdog(username);
Game game = controller.getModel();
callback.onGameInit(new MiniModel(game.getSlotMap(), game.getOrderLogicCard(), game.getCurrentState(), game.getPlayers(), game.getAvailableTotems(), game.getUpperListTribeCards(), game.getLowerListTribeCards(), game.getUpperListBuilding(), game.getLowerListBuilding(), game.disconnectedPlayers.entrySet().stream().filter(Map.Entry::getValue).map(x -> x.getKey().getUserName()).collect(Collectors.toCollection(ArrayList::new))));
callback.onGameInit(new MiniModel(game.getSlotMap(), game.getOrderLogicCard(), game.getCurrentState(), game.getPlayers(), game.getAvailableTotems(), game.getUpperListTribeCards(), game.getLowerListTribeCards(), game.getUpperListBuilding(), game.getLowerListBuilding(), game.getDisconnectedPlayers().entrySet().stream().filter(Map.Entry::getValue).map(x -> x.getKey().getUserName()).collect(Collectors.toCollection(ArrayList::new))));
System.out.println("Model sent: " + username);
actionQueue.add(new ReconnectPlayer(username));
return null;
@@ -266,7 +266,7 @@ public class TCPServer {
game.getCurrentState(),
game.getPlayers(),
game.getAvailableTotems(),
game.getUpperListTribeCards(), game.getLowerListTribeCards(), game.getUpperListBuilding(), game.getLowerListBuilding(), game.disconnectedPlayers.entrySet().stream().filter(Map.Entry::getValue).map(x -> x.getKey().getUserName()).collect(Collectors.toCollection(ArrayList::new))
game.getUpperListTribeCards(), game.getLowerListTribeCards(), game.getUpperListBuilding(), game.getLowerListBuilding(), game.getDisconnectedPlayers().entrySet().stream().filter(Map.Entry::getValue).map(x -> x.getKey().getUserName()).collect(Collectors.toCollection(ArrayList::new))
));
Thread thread = new Thread(handler);
@@ -98,7 +98,7 @@ public class ServerLauncher {
game.getPlayers(), game.getAvailableTotems(),
game.getUpperListTribeCards(), game.getLowerListTribeCards(),
game.getUpperListBuilding(), game.getLowerListBuilding(),
game.disconnectedPlayers.entrySet().stream()
game.getDisconnectedPlayers().entrySet().stream()
.filter(Map.Entry::getValue)
.map(e -> e.getKey().getUserName())
.collect(Collectors.toCollection(ArrayList::new))
@@ -161,7 +161,7 @@ public class ServerLauncher {
Game game = saveManager.load();
if (game == null) return;
long disconnectedCount = game.disconnectedPlayers.entrySet().stream()
long disconnectedCount = game.getDisconnectedPlayers().entrySet().stream()
.filter(Map.Entry::getValue).count();
if (disconnectedCount >= game.getNPlayers() - 1) {
@@ -173,7 +173,7 @@ public class ServerLauncher {
gameController.setModel(game);
playerList.setLimit(game.getNPlayers());
for (Map.Entry<Player, Boolean> entry : game.disconnectedPlayers.entrySet()) {
for (Map.Entry<Player, Boolean> entry : game.getDisconnectedPlayers().entrySet()) {
if (entry.getValue()) {
playerList.put(entry.getKey().getUserName(), false);
}
@@ -608,16 +608,16 @@ public class MainFXMLController {
overlay.setPickOnBounds(false);
overlay.setMouseTransparent(true);
for (int i = 0; i < controller.miniModel.orderLogicCard.playerList.size(); i++) {
OrderPlayer op = controller.miniModel.orderLogicCard.playerList.get(i);
for (int i = 0; i < controller.miniModel.orderLogicCard.getPlayerList().size(); i++) {
OrderPlayer op = controller.miniModel.orderLogicCard.getPlayerList().get(i);
// Carica immagine totem come in createSlot
ImageView totem = new ImageView(loadImage(
"/GUIImages/Totems/totem_" + op.player.getTotem().toString().toLowerCase(Locale.ROOT) + ".png"
"/GUIImages/Totems/totem_" + op.getPlayer().getTotem().toString().toLowerCase(Locale.ROOT) + ".png"
));
totem.setPreserveRatio(true);
if (op.played) {
if (op.isPlayed()) {
totem.setVisible(false);
}
@@ -263,8 +263,8 @@ class GameControllerTest {
assertTrue(controller.disconnectedPlayer(current.getUserName()));
assertTrue(game.disconnectedPlayers.containsKey(current));
assertTrue(game.disconnectedPlayers.get(current));
assertTrue(game.getDisconnectedPlayers().containsKey(current));
assertTrue(game.getDisconnectedPlayers().get(current));
}
@Test
@@ -75,7 +75,7 @@ class BoardTest {
Board bd3 = new Board(3);
Board bd4 = new Board(4);
Board bd5 = new Board(5);
for(TribeCard tribe : bd2.upperListTribe)
for(TribeCard tribe : bd2.getUpperListTribe())
{
System.out.println(tribe.getIdIMG() +" "+tribe.toStringBoard());
assertNotEquals("-1",tribe.getIdIMG());
@@ -102,12 +102,12 @@ class BoardTest {
assertEquals(96 - (numPlayer+4) - (numPlayer+1), bd.getTribeDeckSize()); // Verifica che dal mazzo TribeDeck venga pescato il numero corretto di carte
assertEquals(numPlayer+1, bd.lowerListTribe.size()); // Verifica che la dimensione della lista inferiore sia corretta
assertTrue(bd.lowerListTribe.stream().noneMatch(card -> card.isEventCard())); // Verifica che non ci siano EventCard dentro alla lista inferiore
assertEquals(numPlayer+1, bd.getLowerListTribe().size()); // Verifica che la dimensione della lista inferiore sia corretta
assertTrue(bd.getLowerListTribe().stream().noneMatch(card -> card.isEventCard())); // Verifica che non ci siano EventCard dentro alla lista inferiore
assertEquals(numPlayer+4, bd.upperListTribe.size()); // Verifica che la dimensione della lista superiore sia corretta
assertEquals(numPlayer+4, bd.getUpperListTribe().size()); // Verifica che la dimensione della lista superiore sia corretta
assertEquals(2, bd.upperListBuilding.size()); // Verifica che ci sia il giusto numero di buildings (2 edifici per 3+ giocatori)
assertEquals(2, bd.getUpperListBuilding().size()); // Verifica che ci sia il giusto numero di buildings (2 edifici per 3+ giocatori)
}
@Test
@@ -116,7 +116,7 @@ class BoardTest {
Board bd = new Board(0);
Queue<EventCard> eventQueue = new LinkedList<>();
for (TribeCard card : bd.lowerListTribe) {
for (TribeCard card : bd.getLowerListTribe()) {
if (card.isEventCard()) {
eventQueue.add((EventCard) card);
}
@@ -130,13 +130,13 @@ class BoardTest {
void removeUpperTribeCard() {
Board bd = new Board(3);
List<TribeCard> before = new ArrayList<>( bd.upperListTribe);
List<TribeCard> before = new ArrayList<>( bd.getUpperListTribe());
TribeCard cardToRemove = before.get(0);
assertEquals(cardToRemove, before.remove(0));
assertTrue( bd.removeUpperTribeCard(cardToRemove));
assertEquals(before, bd.upperListTribe);
assertEquals(before, bd.getUpperListTribe());
}
@Test
@@ -144,13 +144,13 @@ class BoardTest {
void removeLowerTribeCard() {
Board bd = new Board(3);
List<TribeCard> before = new ArrayList<>(bd.lowerListTribe);
List<TribeCard> before = new ArrayList<>(bd.getLowerListTribe());
TribeCard cardToRemove = before.get(0);
assertEquals(cardToRemove, before.remove(0));
assertTrue( bd.removeLowerTribeCard(cardToRemove));
assertEquals(before, bd.lowerListTribe);
assertEquals(before, bd.getLowerListTribe());
}
@Test
@@ -158,13 +158,13 @@ class BoardTest {
void removeUpperBuildingCard() {
Board bd = new Board(3);
List<BuildingCard> before = new ArrayList<>(bd.upperListBuilding);
List<BuildingCard> before = new ArrayList<>(bd.getUpperListBuilding());
BuildingCard cardToRemove = before.get(0);
assertEquals(cardToRemove, before.remove(0));
assertTrue( bd.removeUpperBuildingCard(cardToRemove));
assertEquals(before, bd.upperListBuilding);
assertEquals(before, bd.getUpperListBuilding());
}
@Test
@@ -176,11 +176,11 @@ class BoardTest {
bd.nextRound(); // Skip to era 2
}
List<BuildingCard> before = new ArrayList<>( bd.lowerListBuilding);
List<BuildingCard> before = new ArrayList<>( bd.getLowerListBuilding());
BuildingCard cardToRemove = before.get(0);
assertEquals(cardToRemove, before.remove(0));
assertTrue(bd.removeLowerBuildingCard(cardToRemove));
assertEquals(before, bd.lowerListBuilding);
assertEquals(before, bd.getLowerListBuilding());
}
@Test
@@ -188,13 +188,13 @@ class BoardTest {
void nextRound() {
int numPlayer = 3;
Board bd = new Board(numPlayer);
assertTrue(!bd.lowerListTribe.isEmpty());
List<TribeCard> upperListBefore = new ArrayList<>(bd.upperListTribe);
assertTrue(!bd.getLowerListTribe().isEmpty());
List<TribeCard> upperListBefore = new ArrayList<>(bd.getUpperListTribe());
bd.nextRound();
assertEquals(upperListBefore, bd.lowerListTribe); // Verifica che la lista superiore è stata spostata sotto
assertNotEquals(upperListBefore, bd.upperListTribe); // Verifica che la lista superiore sia stata cambiata
assertEquals(numPlayer+4, bd.upperListTribe.size()); // Verifica che la nuova dimensione della lista superiore sia corretta
assertEquals(upperListBefore, bd.getLowerListTribe()); // Verifica che la lista superiore è stata spostata sotto
assertNotEquals(upperListBefore, bd.getUpperListTribe()); // Verifica che la lista superiore sia stata cambiata
assertEquals(numPlayer+4, bd.getUpperListTribe().size()); // Verifica che la nuova dimensione della lista superiore sia corretta
}
@Test
@@ -209,31 +209,31 @@ class BoardTest {
// Era 2, nTotem <= 3
numPlayer = 3;
Board bd1 = new Board(numPlayer);
upperListBefore = new ArrayList<>(bd1.upperListBuilding);
upperListBefore = new ArrayList<>(bd1.getUpperListBuilding());
for (int i=0;i<3;i++) {
bd1.nextRound(); // Skip to era 2
}
assertEquals(2, bd1.getEra());
assertEquals(upperListBefore, bd1.lowerListBuilding);
assertNotEquals(upperListBefore, bd1.upperListBuilding);
assertEquals(2, bd1.upperListBuilding.size());
assertTrue(bd1.upperListBuilding.stream().allMatch(x->x.getEra()==2));
assertTrue(bd1.lowerListBuilding.stream().allMatch(x->x.getEra()==1));
assertEquals(upperListBefore, bd1.getLowerListBuilding());
assertNotEquals(upperListBefore, bd1.getUpperListBuilding());
assertEquals(2, bd1.getUpperListBuilding().size());
assertTrue(bd1.getUpperListBuilding().stream().allMatch(x->x.getEra()==2));
assertTrue(bd1.getLowerListBuilding().stream().allMatch(x->x.getEra()==1));
// Era 2, nTotem > 3
numPlayer = 4;
Board bd2 = new Board(numPlayer);
upperListBefore = new ArrayList<>(bd2.upperListBuilding);
upperListBefore = new ArrayList<>(bd2.getUpperListBuilding());
for (int i=0;i<3;i++) {
bd2.nextRound(); // Skip to era 2
}
assertEquals(2, bd2.getEra());
assertEquals(upperListBefore, bd2.lowerListBuilding);
assertNotEquals(upperListBefore, bd2.upperListBuilding);
assertEquals(3, bd2.upperListBuilding.size());
assertTrue(bd2.upperListBuilding.stream().allMatch(x->x.getEra()==2));
assertTrue(bd2.lowerListBuilding.stream().allMatch(x->x.getEra()==1));
assertEquals(upperListBefore, bd2.getLowerListBuilding());
assertNotEquals(upperListBefore, bd2.getUpperListBuilding());
assertEquals(3, bd2.getUpperListBuilding().size());
assertTrue(bd2.getUpperListBuilding().stream().allMatch(x->x.getEra()==2));
assertTrue(bd2.getLowerListBuilding().stream().allMatch(x->x.getEra()==1));
// Era 3, nTotem == 2
numPlayer = 2;
@@ -241,16 +241,16 @@ class BoardTest {
for (int i=0;i<3;i++) {
bd3.nextRound(); // Skip to era 2
}
upperListBefore = new ArrayList<>(bd3.upperListBuilding); // We need to take the list of the era 2
upperListBefore = new ArrayList<>(bd3.getUpperListBuilding()); // We need to take the list of the era 2
for (int i=0;i<3;i++) {
bd3.nextRound(); // Skip to era 3
}
assertEquals(3, bd3.getEra());
assertEquals(upperListBefore, bd3.lowerListBuilding);
assertNotEquals(upperListBefore, bd3.upperListBuilding);
assertEquals(3, bd3.upperListBuilding.size());
assertTrue(bd3.upperListBuilding.stream().allMatch(x->x.getEra()==3));
assertTrue(bd3.lowerListBuilding.stream().allMatch(x->x.getEra()==2));
assertEquals(upperListBefore, bd3.getLowerListBuilding());
assertNotEquals(upperListBefore, bd3.getUpperListBuilding());
assertEquals(3, bd3.getUpperListBuilding().size());
assertTrue(bd3.getUpperListBuilding().stream().allMatch(x->x.getEra()==3));
assertTrue(bd3.getLowerListBuilding().stream().allMatch(x->x.getEra()==2));
// Era 3, nTotem == 5
@@ -259,16 +259,16 @@ class BoardTest {
for (int i=0;i<3;i++) {
bd4.nextRound(); // Skip to era 2
}
upperListBefore = new ArrayList<>(bd4.upperListBuilding); // We need to take the list of the era 2
upperListBefore = new ArrayList<>(bd4.getUpperListBuilding()); // We need to take the list of the era 2
for (int i=0;i<3;i++) {
bd4.nextRound(); // Skip to era 3
}
assertEquals(3, bd4.getEra());
assertEquals(upperListBefore, bd4.lowerListBuilding);
assertNotEquals(upperListBefore, bd4.upperListBuilding);
assertEquals(5, bd4.upperListBuilding.size());
assertTrue(bd4.upperListBuilding.stream().allMatch(x->x.getEra()==3));
assertTrue(bd4.lowerListBuilding.stream().allMatch(x->x.getEra()==2));
assertEquals(upperListBefore, bd4.getLowerListBuilding());
assertNotEquals(upperListBefore, bd4.getUpperListBuilding());
assertEquals(5, bd4.getUpperListBuilding().size());
assertTrue(bd4.getUpperListBuilding().stream().allMatch(x->x.getEra()==3));
assertTrue(bd4.getLowerListBuilding().stream().allMatch(x->x.getEra()==2));
// Era 3, nTotem != 2, 5
@@ -277,16 +277,16 @@ class BoardTest {
for (int i=0;i<3;i++) {
bd5.nextRound(); // Skip to era 2
}
upperListBefore = new ArrayList<>(bd5.upperListBuilding); // We need to take the list of the era 2
upperListBefore = new ArrayList<>(bd5.getUpperListBuilding()); // We need to take the list of the era 2
for (int i=0;i<3;i++) {
bd5.nextRound(); // Skip to era 3
}
assertEquals(3, bd5.getEra());
assertEquals(upperListBefore, bd5.lowerListBuilding);
assertNotEquals(upperListBefore, bd5.upperListBuilding);
assertEquals(4, bd5.upperListBuilding.size());
assertTrue(bd5.upperListBuilding.stream().allMatch(x->x.getEra()==3));
assertTrue(bd5.lowerListBuilding.stream().allMatch(x->x.getEra()==2));
assertEquals(upperListBefore, bd5.getLowerListBuilding());
assertNotEquals(upperListBefore, bd5.getUpperListBuilding());
assertEquals(4, bd5.getUpperListBuilding().size());
assertTrue(bd5.getUpperListBuilding().stream().allMatch(x->x.getEra()==3));
assertTrue(bd5.getLowerListBuilding().stream().allMatch(x->x.getEra()==2));
}
@@ -1341,8 +1341,8 @@ class GameTest {
assertTrue(game.disconnectedPlayer(current));
assertTrue(game.disconnectedPlayers.containsKey(current));
assertTrue(game.disconnectedPlayers.get(current));
assertTrue(game.getDisconnectedPlayers().containsKey(current));
assertTrue(game.getDisconnectedPlayers().get(current));
assertNotEquals(current, game.getCurrentState().getCurrentPlayer());
}
@@ -1367,10 +1367,10 @@ class GameTest {
Player current = game.getCurrentState().getCurrentPlayer();
assertTrue(game.disconnectedPlayer(current));
assertTrue(game.disconnectedPlayers.containsKey(current));
assertTrue(game.getDisconnectedPlayers().containsKey(current));
assertTrue(game.reconnectPlayer(current));
assertFalse(game.disconnectedPlayers.containsKey(current));
assertFalse(game.getDisconnectedPlayers().containsKey(current));
}
@Test
@@ -1382,11 +1382,11 @@ class GameTest {
Player current = game.getCurrentState().getCurrentPlayer();
assertTrue(game.disconnectedPlayer(current));
assertFalse(game.disconnectedPlayers.isEmpty());
assertFalse(game.getDisconnectedPlayers().isEmpty());
game.clearDisconnected();
assertTrue(game.disconnectedPlayers.isEmpty());
assertTrue(game.getDisconnectedPlayers().isEmpty());
}
@Test