Class GameState
java.lang.Object
it.polimi.ingsw.server.event_sourcing.Aggregate
it.polimi.ingsw.server.model.game_logic.GameState
- All Implemented Interfaces:
GameStateCommonInterface
- Direct Known Subclasses:
ExpertGameState
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected List<Archipelago>protected intprotected Archipelagoprotected intprivate intprivate intprotected Roundprotected List<SchoolBoard>protected NumberOfPlayersStrategyFields inherited from class it.polimi.ingsw.server.event_sourcing.Aggregate
created, id, repository, version -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidvoidApplies an event, given the Event to apply This method will call using reflection the appropriate handler that manage the eventassignProfessor(Color professor) The method gets a color in input and checks if the current player should get the professor corresponding to the inputted color and if another player should lose the corresponding professorThis method checks the winning conditions and returns a map linking every schoolBord ID to a boolean indicating if the schoolBoard is a winner or notprotected voidThis method is used to select the correct strategy according to the number of playersprotected booleancompareCurrentPlayersStudentsNumberWithOthersMax(int currentPlayerNumberOfStudentsInDiningRoomLane, int otherSchoolBoardsMaxStudentsInDiningRoomLane) voidconquerArchipelago(int schoolBoardId) The current player conquers the archipelago mother nature is currently in, placing a tower of his own color and substituting any tower that was previously placed on that archipelagovoidprotected ArchipelagocreateArchipelago(int code) This method creates an archipelago with the inputted codevoidfillCloud(int cloudIndex) This method gets int cloudIndex in input identifying a cloud and fills the cloud with students taken from the studentSupplyvoidfillCloudHandler(FillCloudEvent event) voidFills every cloud with students //@throws FullCloudException if one or more of the clouds are not completely empty before being refilledThis method returns the current ActionPhaseSubTurn in which the gameState is currently inprotected intprotected Optional<Archipelago>getArchipelagoFromIslandCodes(List<Integer> archipelagoIslandCodes) getArchipelagoFromSingleIslandCode(int archipelagoIslandCode) protected SchoolBoardintThis method returns the current player schoolBoardIdintgetInfluence(List<Integer> archipelagoIslandCodes) This method gets an archipelago in input and returns a map where every entry links a schoolBoard with its influence on the inputted archipelagointgetMostInfluentSchoolBoardId(List<Integer> archipelagoIslandCodes) This method verifies if there is a schoolBoard that is more influent than all the others on the archipelago on which motherNature is, and returns its schoolBoardIdprivate Archipelagointintintintintprivate intgetNumberOfTowersPlaced(int schoolBoardId) protected Archipelagoprotected SchoolBoardgetSchoolBoardFromSchoolBoardId(int schoolBoardId) This method returns the corresponding schoolBoard to the inputted schoolBoardIdgetSchoolBoardIDFromTowerColor(TowerColor towerColor) This method returns the list of schoolBoards that have the inputted towerColorThis method returns a set containing all the schoolBoard IDs contained in this gameStateThis method returns a map that links every schoolBoard to the card it played in this roundgetTowerColorFromSchoolBoardId(Integer schoolBoardId) This method returns an Optional wrapping the towerColor of the inputted schoolBoardIdvoidgrabStudentsFromCloud(int cloudIndex) The current player grabs all the students from a cloud and puts them in the entrancevoidvoidvoidvoidinitGameState(InitGameStateEvent event) This method initializes the gameState in all its parts according to the game's rulesprivate List<Archipelago>This method initializes all the archipelagos adding motherNature and the students as the rulebook commandsThis method initializes the List of Lists of Color representing the cloudsprotected List<SchoolBoard>This method initializes the schoolBoards according to the appropriate strategy depending on the number of players.booleanThis method returns true if this is the last round, false otherwisebooleanlightify()This method returns the light version of the GameState, with all the useful information to be sent over the networkbooleanMerges the archipelago mother nature is currently on with the archipelago on the right (one step clockwise with respect to mother nature's position)booleanbooleanMerges the archipelago mother nature is currently in with the archipelago on the left (one step counter-clockwise with respect to mother nature's position)booleanvoidmoveMotherNatureNStepsClockwise(int numberOfSteps) Shifts mother nature's position by the provided numberOfStepsvoidvoidShifts mother nature's position one step clockwisevoidmoveStudentFromEntranceToArchipelago(Color student, List<Integer> archipelagoIslandCodes) The current player moves a student from the entrance to an archipelagovoidvoidvoidmoveStudentFromEntranceToDiningRoom(Color student) The current player moves a student from the entrance to the dining roomprivate booleanvoidThe current player plays the given cardvoidplayCardHandler(PlayCardEvent event) voidvoidvoidvoidresetSchoolBoardIdsToCardsPlayerThisRoundHandler(ResetSchoolBoardIdsToCardsPlayerThisRoundEvent event) voidsetActionPhaseSubTurn(ActionPhaseSubTurn actionPhaseSubTurn) This method sets the ActionPhaseSubTurn to the inputted actionPhaseSubTurnvoidvoidsetCurrentPhase(Phase currentPhase) This method sets the current phase of the turnvoidvoidsetCurrentPlayerSchoolBoardId(int schoolBoardId) voidvoidThis method sets the last round flag to truevoidsetMotherNaturePositionForTesting(Archipelago motherNaturePosition) voidsetRoundOrder(List<Integer> roundOrder) voidprivate voidupdateSeed(Event event) Methods inherited from class it.polimi.ingsw.server.event_sourcing.Aggregate
createSnapshot, getCurrentState, loadFromUuid, rollbackMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface it.polimi.ingsw.server.model.game_logic.GameStateCommonInterface
assignProfessorsAfterEffect, getAvailableCharacters, playCharacterLock, playColorDoesntCount, playGetProfessorsWithSameStudents, playMoveMotherNatureToAnyArchipelago, playPutOneStudentFromCharacterToArchipelago, playPutOneStudentFromCharacterToDiningRoom, playPutThreeStudentsInTheBag, playSwapThreeStudentsBetweenCharacterAndEntrance, playSwapTwoStudentsBetweenEntranceAndDiningRoom, playTowersDontCount, playTwoAdditionalInfluence, playTwoAdditionalSteps, refillCharacter, resetCharacterPlayedThisTurn, resetColorThatDoesntCountForAllArchipelagos, setTowersInfluenceForAllArchipelagos, unlockMotherNaturePosition, wasCharacterPlayedInCurrentTurn
-
Field Details
-
numberOfPlayers
protected int numberOfPlayers -
strategy
-
numberOfStudentsInEachCloud
private int numberOfStudentsInEachCloud -
numberOfStudentsInTheEntrance
private int numberOfStudentsInTheEntrance -
round
-
schoolBoardIdsToCardPlayedThisRound
-
schoolBoardIdsToLastCardPlayed
-
archipelagos
-
schoolBoards
-
clouds
-
studentFactory
-
motherNaturePosition
-
currentPlayerSchoolBoardId
protected int currentPlayerSchoolBoardId
-
-
Constructor Details
-
GameState
-
GameState
- Parameters:
numberOfPlayers- number of players in the game, must be between 2 (inclusive) and 4 (inclusive)- Throws:
IllegalArgumentException- if the argument representing the number of players is not between 2 and 4GameStateInitializationFailureException- if there is a problem in the initialization of the archipelagos or the schoolBoards, or the clouds.
-
-
Method Details
-
initGameState
This method initializes the gameState in all its parts according to the game's rules- Parameters:
event- is the event linked the initialization- Throws:
GameStateInitializationFailureException- if an error occurs during the initialization
-
chooseStrategy
protected void chooseStrategy()This method is used to select the correct strategy according to the number of players -
initializeClouds
This method initializes the List of Lists of Color representing the clouds -
initializeArchipelagos
This method initializes all the archipelagos adding motherNature and the students as the rulebook commands- Returns:
- a List of Archipelago containing all the already initialized and ready to use archipelagos of the game
- Throws:
EmptyStudentSupplyException- if the studentSupply representing the bag is empty
-
createArchipelago
This method creates an archipelago with the inputted code- Parameters:
code- is the starting islandCode of the archipelago- Returns:
- the newly created archipelago
-
initializeSchoolBoards
This method initializes the schoolBoards according to the appropriate strategy depending on the number of players.- Returns:
- a List of SchoolBoard containing the already initialized schoolBoards, students in the entrance included.
- Throws:
EmptyStudentSupplyException- if the studentSupply representing the bag is empty and cannot fulfill the initialization process
-
playCard
The current player plays the given card- Parameters:
card- the card to be played by the current player- Throws:
CardIsNotInTheDeckException- if the current player does not actually own the card to be played.InvalidCardPlayedException- if another player already played the same card in this round, and it is not the final round.
-
playCardHandler
public void playCardHandler(PlayCardEvent event) throws CardIsNotInTheDeckException, InvalidCardPlayedException -
apply
Description copied from class:AggregateApplies an event, given the Event to apply This method will call using reflection the appropriate handler that manage the event- Overrides:
applyin classAggregate- Parameters:
event- to apply- Throws:
EventSourcingException- if there is some problem finding the appropriate handler
-
fillCloud
This method gets int cloudIndex in input identifying a cloud and fills the cloud with students taken from the studentSupply- Parameters:
cloudIndex- is the index of the cloud to fill with students- Throws:
IllegalArgumentException- if the cloudIndex parameter is not validEmptyStudentSupplyException- if the student supply representing the bag cannot fulfill the request for students
-
fillCloudHandler
public void fillCloudHandler(FillCloudEvent event) throws EmptyStudentSupplyException, IllegalArgumentException -
addEvent
-
updateSeed
-
fillClouds
Fills every cloud with students //@throws FullCloudException if one or more of the clouds are not completely empty before being refilled- Throws:
EmptyStudentSupplyException- if the studentSupply cannot fulfill the demand for students to refill all the clouds
-
grabStudentsFromCloud
The current player grabs all the students from a cloud and puts them in the entrance- Parameters:
cloudIndex- is the index of the cloud to pick the students from- Throws:
EmptyCloudException- if the cloud is empty
-
grabStudentsFromCloudHandler
public void grabStudentsFromCloudHandler(GrabStudentsFromCloudEvent event) throws EmptyCloudException - Throws:
EmptyCloudException
-
moveStudentFromEntranceToDiningRoom
public void moveStudentFromEntranceToDiningRoom(Color student) throws StudentNotInTheEntranceException, FullDiningRoomLaneException The current player moves a student from the entrance to the dining room- Parameters:
student- represents a student that the player wants to move from the entrance to the diningRoom- Throws:
IllegalArgumentException- if(student == null)StudentNotInTheEntranceException- if the student that the player is trying to move is not actually in the entranceFullDiningRoomLaneException
-
moveStudentFromEntranceToDiningHandler
public void moveStudentFromEntranceToDiningHandler(MoveStudentsFromEntranceToDiningEvent event) throws StudentNotInTheEntranceException, FullDiningRoomLaneException -
assignProfessor
The method gets a color in input and checks if the current player should get the professor corresponding to the inputted color and if another player should lose the corresponding professor- Parameters:
professor- indicates the color of the professor the player should get and/or remove from another player
-
assignProfessorHandler
-
compareCurrentPlayersStudentsNumberWithOthersMax
protected boolean compareCurrentPlayersStudentsNumberWithOthersMax(int currentPlayerNumberOfStudentsInDiningRoomLane, int otherSchoolBoardsMaxStudentsInDiningRoomLane) -
moveStudentFromEntranceToArchipelago
public void moveStudentFromEntranceToArchipelago(Color student, List<Integer> archipelagoIslandCodes) throws StudentNotInTheEntranceException The current player moves a student from the entrance to an archipelago- Parameters:
student- represents a student of a certain color that the player wants to move from the entrance to an archipelagoarchipelagoIslandCodes- represents the islandCodes of the archipelago into which the student is being moved- Throws:
IllegalArgumentException- if(student == null || archipelagoIslandCodes == null || archipelagoIslandCodes contains null || archipelagoIslandCodes is not an identifier of an actual archipelago)StudentNotInTheEntranceException- if the student that the player is trying to move is not actually in the entrance
-
moveStudentFromEntranceToArchipelagoHandler
public void moveStudentFromEntranceToArchipelagoHandler(MoveStudentFromEntranceToArchipelagoEvent event) throws StudentNotInTheEntranceException - Throws:
StudentNotInTheEntranceException
-
moveMotherNatureOneStepClockwise
public void moveMotherNatureOneStepClockwise()Shifts mother nature's position one step clockwise -
moveMotherNatureNStepsClockwise
Shifts mother nature's position by the provided numberOfSteps- Parameters:
numberOfSteps- has to be a positive integer- Throws:
InvalidNumberOfStepsException- if (numberOfSteps invalid input: '<'= 0 || numberOfSteps > maxStepsAllowed) where maxStepsAllowed depends on the card played in the round
-
moveMotherNatureNStepsClockwiseHandler
public void moveMotherNatureNStepsClockwiseHandler(MoveMotherNatureNStepsClockwiseEvent event) throws InvalidNumberOfStepsException - Throws:
InvalidNumberOfStepsException
-
conquerArchipelago
public void conquerArchipelago(int schoolBoardId) The current player conquers the archipelago mother nature is currently in, placing a tower of his own color and substituting any tower that was previously placed on that archipelago -
conquerArchipelagoHandler
-
mergeWithPrevious
public boolean mergeWithPrevious()Merges the archipelago mother nature is currently in with the archipelago on the left (one step counter-clockwise with respect to mother nature's position)- Returns:
- true if the archipelagos merged, false otherwise.
-
mergeWithPreviousHandler
-
mergeWithNext
public boolean mergeWithNext()Merges the archipelago mother nature is currently on with the archipelago on the right (one step clockwise with respect to mother nature's position)- Returns:
- true if the archipelagos merged, false otherwise.
-
mergeWithNextHandler
-
checkWinners
This method checks the winning conditions and returns a map linking every schoolBord ID to a boolean indicating if the schoolBoard is a winner or not- Returns:
- a map schoolBoardId -> isWinner
-
onlyThreeArchipelagoLeft
private boolean onlyThreeArchipelagoLeft() -
setRoundOrder
-
setRoundOrderHandler
-
resetRoundIterator
public void resetRoundIterator() -
resetRoundIteratorHandler
-
increaseRoundCount
public void increaseRoundCount() -
increaseRoundCountHandler
-
getCurrentRound
public int getCurrentRound() -
setCurrentPhase
This method sets the current phase of the turn- Throws:
IllegalArgumentException- if(currentPhase == null)
-
setCurrentPhaseHandler
-
setCurrentPlayerSchoolBoardId
public void setCurrentPlayerSchoolBoardId(int schoolBoardId) - Parameters:
schoolBoardId- has to be a valid id of an existing schoolBoard
-
setCurrentPlayerSchoolBoardIdHandler
-
setLastRoundTrue
public void setLastRoundTrue()This method sets the last round flag to true -
getSchoolBoardIDFromTowerColor
This method returns the list of schoolBoards that have the inputted towerColor- Parameters:
towerColor- is the towerColor of interest- Returns:
- a list of integer representing the list of schoolBoards that have the inputted towerColor
-
getNumberOfTowersPlaced
private int getNumberOfTowersPlaced(int schoolBoardId) -
getAllowedStepsNumber
protected int getAllowedStepsNumber() -
getSchoolBoardFromSchoolBoardId
This method returns the corresponding schoolBoard to the inputted schoolBoardId- Parameters:
schoolBoardId- has to be an existing schoolBoardId- Returns:
- the reference to the schoolBoard corresponding to the inputted schoolBoardId
-
getPreviousArchipelago
-
getNextArchipelago
-
getArchipelagoFromIslandCodes
-
getArchipelagoFromSingleIslandCode
-
getCurrentPlayerSchoolBoard
-
getInfluence
This method gets an archipelago in input and returns a map where every entry links a schoolBoard with its influence on the inputted archipelago- Parameters:
archipelagoIslandCodes- is a List of Integer uniquely identifying an archipelago- Returns:
- a Map Integer, Integer where the key is the schoolBoardId and the value is the influence on the inputted archipelago
-
isLastTurnInThisRound
public boolean isLastTurnInThisRound() -
getNextTurn
public int getNextTurn() -
getNextTurnHandler
-
getNumberOfStudentsInTheEntrance
public int getNumberOfStudentsInTheEntrance() -
getInitialNumberOfStudentsInTheEntrance
public int getInitialNumberOfStudentsInTheEntrance() -
getNumberOfMovableStudents
public int getNumberOfMovableStudents() -
getCurrentPhase
-
getMotherNaturePositionIslandCodes
-
getClouds
-
getNumberOfPlayers
public int getNumberOfPlayers() -
getSchoolBoardIds
This method returns a set containing all the schoolBoard IDs contained in this gameState- Returns:
- a Set of Integer containing all the schoolBoard IDs contained in this gameState
-
getSchoolBoardIdsToCardPlayedThisRound
This method returns a map that links every schoolBoard to the card it played in this round- Returns:
- a map that links every schoolBoard to the card it played in this round
-
resetSchoolBoardIdsToCardsPlayerThisRound
public void resetSchoolBoardIdsToCardsPlayerThisRound() -
resetSchoolBoardIdsToCardsPlayerThisRoundHandler
public void resetSchoolBoardIdsToCardsPlayerThisRoundHandler(ResetSchoolBoardIdsToCardsPlayerThisRoundEvent event) -
getCurrentPlayerSchoolBoardId
public int getCurrentPlayerSchoolBoardId()This method returns the current player schoolBoardId- Returns:
- an int representing the current player schoolBoard ID
-
setActionPhaseSubTurn
This method sets the ActionPhaseSubTurn to the inputted actionPhaseSubTurn- Parameters:
actionPhaseSubTurn- is the sub-turn the gameState will be changed to
-
setActionPhaseSubTurnHandler
-
getActionPhaseSubTurn
This method returns the current ActionPhaseSubTurn in which the gameState is currently in- Returns:
- an ActionPhaseSubTurn representing the current ActionPhaseSubTurn in which the gameState is currently in
-
getTowerColorFromSchoolBoardId
This method returns an Optional wrapping the towerColor of the inputted schoolBoardId- Parameters:
schoolBoardId- is the ID that represents a schoolBoard- Returns:
- the towerColor of the inputted schoolBoardId, if the schoolBoardId is valid, an empty Optional otherwise
-
isLastRound
public boolean isLastRound()This method returns true if this is the last round, false otherwise- Returns:
- true if this is the last round, false otherwise
-
lightify
This method returns the light version of the GameState, with all the useful information to be sent over the network- Returns:
- a LightGameState representing the light version of the GameState, with all the useful information to be sent over the network
-
getMostInfluentSchoolBoardId
This method verifies if there is a schoolBoard that is more influent than all the others on the archipelago on which motherNature is, and returns its schoolBoardId- Returns:
- an integer representing the schoolBoardId of the most influent player on the archipelago on which motherNature is
-
setMotherNaturePositionForTesting
-
getCurrentPlayerSchoolBoardForTesting
-
getArchipelagosForTesting
-
getSchoolBoardIdsToCardsPlayedThisRoundForTesting
-