From 5f3c70c8b3309fec114c5d3bab55d3a92f653319 Mon Sep 17 00:00:00 2001 From: AleandroPagani Date: Sat, 11 Apr 2026 18:44:53 +0200 Subject: [PATCH] daje --- .../Model/Cards/TribeCards/EventCard.java | 5 + .../ingsw/gc14/Model/GamePackage/Board.java | 120 ++------------- .../ingsw/gc14/Model/Orders/Order2.java | 1 - .../java/it/polimi/ingsw/gc14/Model/Slot.java | 1 + .../gc14/Model/GamePackage/BoardTest.java | 145 +++++++++++++++--- 5 files changed, 145 insertions(+), 127 deletions(-) diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/EventCard.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/EventCard.java index d77c945..549d5fb 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/EventCard.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/TribeCards/EventCard.java @@ -23,6 +23,11 @@ public abstract class EventCard extends TribeCard { @Override public abstract TribeCard clone(); + @Override + public String toString() { + return super.toString()+" "+type.toString(); + } + public abstract void activateEvent (ArrayList playerList); // End Functions } diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/GamePackage/Board.java b/src/main/java/it/polimi/ingsw/gc14/Model/GamePackage/Board.java index 764eb47..5eb8da9 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/GamePackage/Board.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/GamePackage/Board.java @@ -11,69 +11,28 @@ import it.polimi.ingsw.gc14.Model.Slot; import java.util.*; import java.util.stream.Collectors; -/** - * Board manages all the elements during the game as decks, upper and lower rows, totems, tiles... - */ public class Board { - /** - * slotList contains the ordered list of slots (tiles). These changes based on the number of players. - * Each slot (tile) has special action as drawing from the upper/lower row or taking food. - */ private List slotList; - - /** tribeDeck is the deck from where you draw tribe cards as characters and events. */ private Queue tribeDeck; - - /** The upper row of tribe cards. There must be (num. of players + 4) character cards + Event cards */ public List 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 get in the lower row, the event effect will be activated at the wnd of the round. - */ public List lowerListTribe; - - /** Contains all the building cards of the upper list. When a new era starts, all its building cards are placed here */ public List upperListBuilding; - - /** Contains all the building cards of the upper list. When a new era starts, the old era's buildings are moved from the upper to the lower list */ public List lowerListBuilding; - - /** Number of players */ private int nTotem; - - /** Current era of the game */ private int era; - - /** - * Creates and return a new list containing the slots (tiles) of the game - * - * @return a copy of the slot list - */ public List getSlotList(){ return slotList.stream().map(x->new Slot(x.getSlotId())).collect(Collectors.toList()); } + public Queue getTribeDeck() {return new LinkedList<>(tribeDeck);} - /** - * Creates and initialize a new board: - * - Generate the slotList using a method of DecksCreator - * - Generate the tribeDeck - * - Populate the lower list (if there is an event card, it's added to the upper list) - * - Populate the upper list - * - Generate the buildingDeck using a method of DecksCreator - * - * @param nTotem the number of players - */ public Board(int nTotem) { this.nTotem = nTotem; this.slotList = DecksCreator.loadSlotDeck().stream().filter(x->x.getNMinPlayer()<=nTotem).sorted(Comparator.comparingInt(Slot::getSlotId)).toList(); upperListTribe=new ArrayList<>(); lowerListTribe=new ArrayList<>(); lowerListBuilding=new ArrayList<>(); - tribeDeck=getTribeDeck(nTotem); + tribeDeck=generateTribeDeck(nTotem); era=1; - for(int i=0;i getTribeDeck(int nPlayers) { + private Queue generateTribeDeck(int nPlayers) { ArrayList era1= DecksCreator.loadTribeDeckByEra(1).stream().filter(x->x.getNMin()<=nPlayers).collect(Collectors.toCollection(ArrayList::new)); ArrayList era2= DecksCreator.loadTribeDeckByEra(2).stream().filter(x->x.getNMin()<=nPlayers).collect(Collectors.toCollection(ArrayList::new)); ArrayList era3= DecksCreator.loadTribeDeckByEra(3).stream().filter(x->x.getNMin()<=nPlayers).collect(Collectors.toCollection(ArrayList::new)); @@ -130,58 +77,22 @@ public class Board { return tribeDeck_temp; } - /** @return the queue of events from the lower list that need to be activated */ public Queue getPendingEvents(){ return lowerListTribe.stream().filter(TribeCard::IsEventCard).map(x->(EventCard)x).collect(Collectors.toCollection(LinkedList::new)); } - /** - * Take the selected card from the upper tribe list of the board - * - * @param tribeCard is the card to remove - * @return true if succeed in removing the card - */ public boolean removeUpperTribeCard(TribeCard tribeCard) { return upperListTribe.remove(tribeCard); } - - /** - * Take the selected card from the lower tribe list of the board - * - * @param tribeCard is the card to remove - * @return true if succeed in removing the card - */ public boolean removeLowerTribeCard(TribeCard tribeCard) { - return lowerListTribe.remove(tribeCard); + return upperListTribe.remove(tribeCard); } - - /** - * Take the selected card from the upper building list of the board - * - * @param buildingCard is the card to remove - * @return true if succeed in removing the card - */ public boolean removeUpperBuildingCard(BuildingCard buildingCard) { - return upperListBuilding.remove(buildingCard); + return upperListTribe.remove(buildingCard); } - - /** - * Take the selected card from the lower building list of the board - * - * @param buildingCard is the card to remove - * @return true if succeed in removing the card - */ public boolean removeLowerBuildingCard(BuildingCard buildingCard) { - return lowerListBuilding.remove(buildingCard); + return upperListTribe.remove(buildingCard); } - - /** - * Goes to the next round. - * - Clear the lower tribe row - * - Moves the upper tribe row to the lower one - * - Populate the upper tribe row - * - */ public int nextRound() { lowerListTribe.clear(); lowerListTribe.addAll(upperListTribe); @@ -195,23 +106,22 @@ public class Board { } upperListTribe.add(tempCard); } + for(int i=upperListTribe.size();i buildingCards= new ArrayList<>(DecksCreator.loadBuildingDeckByEra(era)); + List buildingCards=DecksCreator.loadBuildingDeckByEra(era); Collections.shuffle(buildingCards); if(era==2) { diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Orders/Order2.java b/src/main/java/it/polimi/ingsw/gc14/Model/Orders/Order2.java index 29cb63b..ffbf893 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Orders/Order2.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Orders/Order2.java @@ -3,7 +3,6 @@ package it.polimi.ingsw.gc14.Model.Orders; import it.polimi.ingsw.gc14.Model.Cards.BuildingCard; import it.polimi.ingsw.gc14.Model.OrderLogicCard; import it.polimi.ingsw.gc14.Model.Player; -import jdk.jshell.spi.ExecutionControl; import java.util.*; diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Slot.java b/src/main/java/it/polimi/ingsw/gc14/Model/Slot.java index aedb04a..083e9f9 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Slot.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Slot.java @@ -82,6 +82,7 @@ public class Slot { public String toString() { return ("SlotID: "+this.getSlotId()+"\nNUpper: "+this.getNUpper()+"\nNLower: "+this.getNLower()+"\nFood: "+this.getFood()+"\nNMinPlayer: "+this.getNMinPlayer()+"\n"); } + // End Constructors // Functions diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/GamePackage/BoardTest.java b/src/test/java/it/polimi/ingsw/gc14/Model/GamePackage/BoardTest.java index e7c1f22..7deb44d 100644 --- a/src/test/java/it/polimi/ingsw/gc14/Model/GamePackage/BoardTest.java +++ b/src/test/java/it/polimi/ingsw/gc14/Model/GamePackage/BoardTest.java @@ -1,54 +1,157 @@ package it.polimi.ingsw.gc14.Model.GamePackage; +import it.polimi.ingsw.gc14.Model.Cards.BuildingCard; +import it.polimi.ingsw.gc14.Model.Cards.TribeCard; +import it.polimi.ingsw.gc14.Model.Cards.TribeCards.EventCard; +import it.polimi.ingsw.gc14.Model.Player; +import it.polimi.ingsw.gc14.Model.Slot; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; + import static org.junit.jupiter.api.Assertions.*; class BoardTest { @Test + @DisplayName("Slot initialization") void getSlotList() { - //Board board = new Board(3); - //assertEquals("Ciao", board.getSlotList().toString()); + // 0 players + Board b0 = new Board(0); + assertEquals('B', b0.getSlotList().get(0).getSlotId()); + assertEquals('C', b0.getSlotList().get(1).getSlotId()); + assertEquals('E', b0.getSlotList().get(2).getSlotId()); + assertEquals('F', b0.getSlotList().get(3).getSlotId()); + + // 1 players + Board b1 = new Board(1); + assertEquals('B', b1.getSlotList().get(0).getSlotId()); + assertEquals('C', b1.getSlotList().get(1).getSlotId()); + assertEquals('E', b1.getSlotList().get(2).getSlotId()); + assertEquals('F', b1.getSlotList().get(3).getSlotId()); + + // 2 players + Board b2 = new Board(2); + assertEquals('B', b2.getSlotList().get(0).getSlotId()); + assertEquals('C', b2.getSlotList().get(1).getSlotId()); + assertEquals('E', b2.getSlotList().get(2).getSlotId()); + assertEquals('F', b2.getSlotList().get(3).getSlotId()); + + // 3 players + Board b3 = new Board(3); + assertEquals('B', b3.getSlotList().get(0).getSlotId()); + assertEquals('C', b3.getSlotList().get(1).getSlotId()); + assertEquals('D', b3.getSlotList().get(2).getSlotId()); + assertEquals('E', b3.getSlotList().get(3).getSlotId()); + assertEquals('F', b3.getSlotList().get(4).getSlotId()); + + // 4 players + Board b4 = new Board(4); + assertEquals('B', b4.getSlotList().get(0).getSlotId()); + assertEquals('C', b4.getSlotList().get(1).getSlotId()); + assertEquals('D', b4.getSlotList().get(2).getSlotId()); + assertEquals('E', b4.getSlotList().get(3).getSlotId()); + assertEquals('F', b4.getSlotList().get(4).getSlotId()); + assertEquals('G', b4.getSlotList().get(5).getSlotId()); + + // 5 players + Board b5 = new Board(5); + assertEquals('A', b5.getSlotList().get(0).getSlotId()); + assertEquals('B', b5.getSlotList().get(1).getSlotId()); + assertEquals('C', b5.getSlotList().get(2).getSlotId()); + assertEquals('D', b5.getSlotList().get(3).getSlotId()); + assertEquals('E', b5.getSlotList().get(4).getSlotId()); + assertEquals('F', b5.getSlotList().get(5).getSlotId()); + assertEquals('G', b5.getSlotList().get(6).getSlotId()); } @Test + @DisplayName("Testing constructor") + void testConstructor() { + + } + + // TODO non ho idea di come testare delle estrazioni randomiche + @Test + @DisplayName("Testing constructor") + void generateTribeDeck() { + + } + + @Test + @DisplayName("get events testing") void getPendingEvents() { + Board bd = new Board(0); + + Queue eventQueue = new LinkedList<>(); + for (TribeCard card : bd.lowerListTribe) { + if (card.IsEventCard()) { + eventQueue.add((EventCard) card); + } + } + + assertEquals(eventQueue, bd.getPendingEvents()); } @Test - void containsUpperTribeCard() { - } - - @Test + @DisplayName("Removing a card from upper row of tribe cards") void removeUpperTribeCard() { + Board bd = new Board(3); + + List before = bd.upperListTribe; + TribeCard cardToRemove = before.get(2); + + before.remove(2); + bd.removeUpperTribeCard(cardToRemove); + + assertEquals(before, bd.upperListTribe); } @Test - void containsLowerTribeCard() { - } - - @Test + @DisplayName("Removing a card from lower row of tribe cards") void removeLowerTribeCard() { + Board bd = new Board(3); + + List before = bd.lowerListTribe; + TribeCard cardToRemove = before.get(2); + + before.remove(2); + bd.removeLowerTribeCard(cardToRemove); + + assertEquals(before, bd.lowerListTribe); } @Test - void containsUpperBuildingCard() { - } - - @Test + @DisplayName("Removing a card from upper row of building cards") void removeUpperBuildingCard() { + Board bd = new Board(3); + + List before = bd.upperListBuilding; + BuildingCard cardToRemove = before.get(0); + + before.remove(0); + bd.removeUpperBuildingCard(cardToRemove); + + assertEquals(before, bd.upperListBuilding); } @Test - void containsLowerBuildingCard() { - } - - @Test + @DisplayName("Removing a card from lower row of building cards") void removeLowerBuildingCard() { + Board bd = new Board(3); + bd.nextEra(); + + List before = bd.lowerListBuilding; + BuildingCard cardToRemove = before.get(0); + + before.remove(0); + bd.removeUpperBuildingCard(cardToRemove); + + assertEquals(before, bd.lowerListBuilding); } - @Test - void nextRound() { - } + } \ No newline at end of file