Class ExpertGameState
java.lang.Object
it.polimi.ingsw.server.event_sourcing.Aggregate
it.polimi.ingsw.server.model.game_logic.GameState
it.polimi.ingsw.server.model.game_logic.ExpertGameState
- All Implemented Interfaces:
GameStateCommonInterface
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final List<PlayableCharacter>protected PlayableCharacterFields inherited from class it.polimi.ingsw.server.model.game_logic.GameState
archipelagos, clouds, currentPlayerSchoolBoardId, motherNaturePosition, numberOfPlayers, round, schoolBoardIdsToCardPlayedThisRound, schoolBoardIdsToLastCardPlayed, schoolBoards, strategy, studentFactoryFields inherited from class it.polimi.ingsw.server.event_sourcing.Aggregate
created, id, repository, version -
Constructor Summary
ConstructorsModifierConstructorDescriptionExpertGameState(int playersNumber) protectedExpertGameState(int playersNumber, List<PlayableCharacter> availableCharacters) ONLY FOR TESTING -
Method Summary
Modifier and TypeMethodDescriptionvoidThis method resets the ownership (with the normal rules) of every professor after the effect of the character is finishedprotected voidThis method assigns the professors after the activation of the effect of the character with ID 2protected voidThis method chooses the appropriate strategy according to the number of playersprotected booleancompareCurrentPlayersStudentsNumberWithOthersMax(int currentPlayerNumberOfStudentsInDiningRoomLane, int otherSchoolBoardsMaxStudentsInDiningRoomLane) protected ExpertArchipelagocreateArchipelago(int code) This method created an archipelago for the expert modevoidGenerates the snapshot and saves the Aggregate updated information to the repositoryprivate voidThis method randomly extracts 3 different characters with which the game will be played.private intprotected intgetInfluence(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 archipelagoprotected List<SchoolBoard>This method initializes the schoolBoards according to the appropriate strategy depending on the number of players.lightify()This method returns the light version of the GameState, with all the useful information to be sent over the networkprivate voidlockArchipelago(Archipelago archipelagoToLock) private voidvoidplayCharacterLock(int archipelagoIslandCode) This method executes the effect of the character with ID 5.voidplayColorDoesntCount(Color color) This method executes the effect of the character with ID 9.voidThis method executes the effect of the character with ID 2.booleanplayMoveMotherNatureToAnyArchipelago(int archipelagoIslandCode) This method executes the effect of the character with ID 3.voidplayPutOneStudentFromCharacterToArchipelago(Color color, int archipelagoIslandCode) This method executes the effect of the character with ID 1.voidThis method executes the effect of the character with ID 11.voidThis method executes the effect of the character with ID 12.voidplaySwapThreeStudentsBetweenCharacterAndEntrance(List<Color> studentsFromCharacter, List<Color> studentsFromEntrance) This method executes the effect of the character with ID 7.voidplaySwapTwoStudentsBetweenEntranceAndDiningRoom(List<Color> studentFromEntrance, List<Color> studentsFromDiningRoom) This method executes the effect of the character with ID 10.voidThis method executes the effect of the character with ID 6.voidThis method executes the effect of the character with ID 8.voidThis method executes the effect of the character with ID 4.private voidputOneStudentFromCharacterToDiningRoom(PlayableCharacter selectedCharacter, Color student) private voidputThreeStudentsInTheBag(Color color) voidThis method refills the PlayableCHaracter that was played during the turnprivate voidrefillGivenCharacter(PlayableCharacter playableCharacter) This method refills the PlayableCharactersWithStudents that may have been used during a turnvoidvoidrollback()Recreates the aggregate based on the last snapshot, deletes all the events vit aggregate version > snapshot versionprivate voidvoidsetTowersInfluenceForAllArchipelagos(boolean doTowersCount) voidThis method unlocks the archipelago onto which mother nature terminates its movementbooleanMethods inherited from class it.polimi.ingsw.server.model.game_logic.GameState
apply, assignProfessor, assignProfessorHandler, checkWinners, conquerArchipelago, conquerArchipelagoHandler, fillCloud, fillCloudHandler, fillClouds, getActionPhaseSubTurn, getArchipelagoFromIslandCodes, getArchipelagoFromSingleIslandCode, getArchipelagosForTesting, getClouds, getCurrentPhase, getCurrentPlayerSchoolBoard, getCurrentPlayerSchoolBoardForTesting, getCurrentPlayerSchoolBoardId, getCurrentRound, getInitialNumberOfStudentsInTheEntrance, getMostInfluentSchoolBoardId, getMotherNaturePositionIslandCodes, getNextTurn, getNextTurnHandler, getNumberOfMovableStudents, getNumberOfPlayers, getNumberOfStudentsInTheEntrance, getPreviousArchipelago, getSchoolBoardFromSchoolBoardId, getSchoolBoardIDFromTowerColor, getSchoolBoardIds, getSchoolBoardIdsToCardPlayedThisRound, getSchoolBoardIdsToCardsPlayedThisRoundForTesting, getTowerColorFromSchoolBoardId, grabStudentsFromCloud, grabStudentsFromCloudHandler, increaseRoundCount, increaseRoundCountHandler, initGameState, isLastRound, isLastTurnInThisRound, mergeWithNext, mergeWithNextHandler, mergeWithPrevious, mergeWithPreviousHandler, moveMotherNatureNStepsClockwise, moveMotherNatureNStepsClockwiseHandler, moveMotherNatureOneStepClockwise, moveStudentFromEntranceToArchipelago, moveStudentFromEntranceToArchipelagoHandler, moveStudentFromEntranceToDiningHandler, moveStudentFromEntranceToDiningRoom, playCard, playCardHandler, resetRoundIterator, resetRoundIteratorHandler, resetSchoolBoardIdsToCardsPlayerThisRound, resetSchoolBoardIdsToCardsPlayerThisRoundHandler, setActionPhaseSubTurn, setActionPhaseSubTurnHandler, setCurrentPhase, setCurrentPhaseHandler, setCurrentPlayerSchoolBoardId, setCurrentPlayerSchoolBoardIdHandler, setLastRoundTrue, setMotherNaturePositionForTesting, setRoundOrder, setRoundOrderHandlerMethods inherited from class it.polimi.ingsw.server.event_sourcing.Aggregate
getCurrentState, loadFromUuid
-
Field Details
-
availableCharacters
-
characterPlayedInCurrentTurn
-
-
Constructor Details
-
ExpertGameState
- Parameters:
playersNumber- 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.
-
ExpertGameState
protected ExpertGameState(int playersNumber, List<PlayableCharacter> availableCharacters) throws GameStateInitializationFailureException, EmptyStudentSupplyException ONLY FOR TESTING
-
-
Method Details
-
chooseStrategy
protected void chooseStrategy()This method chooses the appropriate strategy according to the number of players- Overrides:
chooseStrategyin classGameState
-
createArchipelago
This method created an archipelago for the expert mode- Overrides:
createArchipelagoin classGameState- 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.- Overrides:
initializeSchoolBoardsin classGameState- 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
-
extractCharacters
This method randomly extracts 3 different characters with which the game will be played.- Throws:
EmptyStudentSupplyException
-
refillGivenCharacter
private void refillGivenCharacter(PlayableCharacter playableCharacter) throws EmptyStudentSupplyException This method refills the PlayableCharactersWithStudents that may have been used during a turn- Parameters:
playableCharacter- is the PlayableCharacter to be refilled- Throws:
EmptyStudentSupplyException- if the student supply is empty and the refill couldn't be completed
-
refillCharacter
This method refills the PlayableCHaracter that was played during the turn- Throws:
EmptyStudentSupplyException- if the student supply is empty and the refill couldn't be completed
-
playPutOneStudentFromCharacterToArchipelago
public void playPutOneStudentFromCharacterToArchipelago(Color color, int archipelagoIslandCode) throws MoveNotAvailableException, InvalidArchipelagoIdException, StudentNotOnCharacterException, NotEnoughCoinsException This method executes the effect of the character with ID 1. It takes one student from the character and puts it on the inputted archipelago- Parameters:
color- represents the student to be movedarchipelagoIslandCode- represent the archipelago onto which the inputted student will be moved- Throws:
MoveNotAvailableException- if the move is not available in the gameInvalidArchipelagoIdException- if the inputted archipelago code is invalidStudentNotOnCharacterException- if the inputted student is not actually present on characterNotEnoughCoinsException- if the player doesn't have enough coins to activate the character
-
playGetProfessorsWithSameStudents
public void playGetProfessorsWithSameStudents() throws MoveNotAvailableException, NotEnoughCoinsExceptionThis method executes the effect of the character with ID 2. It allows the player to take control of the a professor even if he has the same number of students on the corresponding diningRoom table- Throws:
MoveNotAvailableException- if the move is not available in the gameNotEnoughCoinsException- if the player doesn't have enough coins to activate the character
-
compareCurrentPlayersStudentsNumberWithOthersMax
protected boolean compareCurrentPlayersStudentsNumberWithOthersMax(int currentPlayerNumberOfStudentsInDiningRoomLane, int otherSchoolBoardsMaxStudentsInDiningRoomLane) - Overrides:
compareCurrentPlayersStudentsNumberWithOthersMaxin classGameState
-
assignProfessorsWithEffect
protected void assignProfessorsWithEffect()This method assigns the professors after the activation of the effect of the character with ID 2 -
assignProfessorsAfterEffect
public void assignProfessorsAfterEffect()This method resets the ownership (with the normal rules) of every professor after the effect of the character is finished -
playMoveMotherNatureToAnyArchipelago
public boolean playMoveMotherNatureToAnyArchipelago(int archipelagoIslandCode) throws InvalidArchipelagoIdException, MoveNotAvailableException, NotEnoughCoinsException This method executes the effect of the character with ID 3. It allows the player to move mother nature to any archipelago.- Parameters:
archipelagoIslandCode- represent an archipelago through one of its codes- Returns:
- true if the archipelagos merged as a result, false otherwise
- Throws:
InvalidArchipelagoIdException- if the inputted archipelago code is invalidMoveNotAvailableException- if the move is not available in the gameNotEnoughCoinsException- if the player doesn't have enough coins to activate the character
-
playTwoAdditionalSteps
This method executes the effect of the character with ID 4. It allows the player to move mother nature for 2 additional steps.- Throws:
MoveNotAvailableException- if the move is not available in the gameNotEnoughCoinsException- if the player doesn't have enough coins to activate the character
-
getAdditionalSteps
private int getAdditionalSteps() -
getAllowedStepsNumber
protected int getAllowedStepsNumber()- Overrides:
getAllowedStepsNumberin classGameState
-
lockArchipelago
private void lockArchipelago(Archipelago archipelagoToLock) throws ArchipelagoAlreadyLockedException - Parameters:
archipelagoToLock- is the archipelago that will be locked- Throws:
ArchipelagoAlreadyLockedException- if the inputted Archipelago is already locked
-
playCharacterLock
public void playCharacterLock(int archipelagoIslandCode) throws NoAvailableLockException, InvalidArchipelagoIdException, ArchipelagoAlreadyLockedException, MoveNotAvailableException, NotEnoughCoinsException This method executes the effect of the character with ID 5. It allows the player to lock an archipelago of choice.- Parameters:
archipelagoIslandCode- represent an archipelago through one of its codes- Throws:
NoAvailableLockException- if there are no locks available on the characterInvalidArchipelagoIdException- if the inputted archipelago code is invalidArchipelagoAlreadyLockedException- if the inputted Archipelago is already lockedMoveNotAvailableException- if the move is not available in the gameNotEnoughCoinsException- if the player doesn't have enough coins to activate the character
-
unlockMotherNaturePosition
public void unlockMotherNaturePosition()This method unlocks the archipelago onto which mother nature terminates its movement -
setTowersInfluenceForAllArchipelagos
public void setTowersInfluenceForAllArchipelagos(boolean doTowersCount) - Parameters:
doTowersCount- is true if the towers will have to count during the influence calculation, false otherwise
-
playTowersDontCount
This method executes the effect of the character with ID 6. It sets the influence given by the towers on every archipelago to zero.- Throws:
MoveNotAvailableException- if the move is not available in the gameNotEnoughCoinsException- if the player doesn't have enough coins to activate the character
-
playSwapThreeStudentsBetweenCharacterAndEntrance
public void playSwapThreeStudentsBetweenCharacterAndEntrance(List<Color> studentsFromCharacter, List<Color> studentsFromEntrance) throws InvalidStudentListsLengthException, MoveNotAvailableException, StudentNotOnCharacterException, StudentNotInTheEntranceException, NotEnoughCoinsException This method executes the effect of the character with ID 7. It allows the player to swap up to three students between its schoolBoard's entrance and the character- Parameters:
studentsFromCharacter- is a list representing the students to get from the characterstudentsFromEntrance- is a list representing the students to give from the entrance- Throws:
InvalidStudentListsLengthException- if the two inputted lists have different lengthsStudentNotOnCharacterException- if one of the elements of studentsFromCharacter is not actually present on the characterStudentNotInTheEntranceException- if one of the elements of studentsFromCharacter is not actually present in the entranceMoveNotAvailableException- if the move is not available in the gameNotEnoughCoinsException- if the player doesn't have enough coins to activate the character
-
playTwoAdditionalInfluence
This method executes the effect of the character with ID 8. It allows the player to get 2 additional units of influence during the influence calculation.- Throws:
MoveNotAvailableException- if the move is not available in the gameNotEnoughCoinsException- if the player doesn't have enough coins to activate the character
-
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- Overrides:
getInfluencein classGameState- 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
-
setColorThatDoesntCountForAllArchipelagos
-
playColorDoesntCount
public void playColorDoesntCount(Color color) throws MoveNotAvailableException, NotEnoughCoinsException This method executes the effect of the character with ID 9. It allows the player to choose a color that won't count during the influence calculation.- Parameters:
color- is the color that won't count during the influence calculation- Throws:
MoveNotAvailableException- if the move is not available in the gameNotEnoughCoinsException- if the player doesn't have enough coins to activate the character
-
resetColorThatDoesntCountForAllArchipelagos
public void resetColorThatDoesntCountForAllArchipelagos() -
playSwapTwoStudentsBetweenEntranceAndDiningRoom
public void playSwapTwoStudentsBetweenEntranceAndDiningRoom(List<Color> studentFromEntrance, List<Color> studentsFromDiningRoom) throws InvalidStudentListsLengthException, MoveNotAvailableException, StudentNotInTheEntranceException, FullDiningRoomLaneException, StudentsNotInTheDiningRoomException, NotEnoughCoinsException This method executes the effect of the character with ID 10. It allows the player to swap up to two students between its entrance and diningRoom.- Parameters:
studentFromEntrance- is the list of students to get from the entrancestudentsFromDiningRoom- is the list of students to get from the diningRoom- Throws:
InvalidStudentListsLengthException- if the two inputted lists have different lengthsStudentNotInTheEntranceException- if one of the elements of studentsFromCharacter is not actually present in the entranceFullDiningRoomLaneException- if the diningRoom table corresponding to one of the colors is fullStudentsNotInTheDiningRoomException- if the one of the elements of studentsFromEntrance is not actually present in the entranceMoveNotAvailableException- if the move is not available in the gameNotEnoughCoinsException- if the player doesn't have enough coins to activate the character
-
putOneStudentFromCharacterToDiningRoom
private void putOneStudentFromCharacterToDiningRoom(PlayableCharacter selectedCharacter, Color student) throws StudentNotOnCharacterException, FullDiningRoomLaneException -
playPutOneStudentFromCharacterToDiningRoom
public void playPutOneStudentFromCharacterToDiningRoom(Color color) throws StudentNotOnCharacterException, FullDiningRoomLaneException, MoveNotAvailableException, NotEnoughCoinsException This method executes the effect of the character with ID 11. It allows the player to get one student from the character and put it into his diningRoom- Parameters:
color- represents the student to be moved from the character to the diningRoom- Throws:
StudentNotOnCharacterException- if one of the elements of studentsFromCharacter is not actually present on the characterFullDiningRoomLaneException- if the diningRoom table corresponding to one of the colors is fullMoveNotAvailableException- if the move is not available in the gameNotEnoughCoinsException- if the player doesn't have enough coins to activate the character
-
putThreeStudentsInTheBag
-
playPutThreeStudentsInTheBag
public void playPutThreeStudentsInTheBag(Color color) throws MoveNotAvailableException, NotEnoughCoinsException, StudentsNotInTheDiningRoomException This method executes the effect of the character with ID 12. It makes every player to get three students of the inputted color from the diningRoom and put them into the bag- Parameters:
color- is the color of the students that have to be removed from the diningRoom- Throws:
StudentsNotInTheDiningRoomException- if the one of the elements of studentsFromEntrance is not actually present in the entranceMoveNotAvailableException- if the move is not available in the gameNotEnoughCoinsException- if the player doesn't have enough coins to activate the character
-
getAvailableCharacters
-
wasCharacterPlayedInCurrentTurn
public boolean wasCharacterPlayedInCurrentTurn() -
resetCharacterPlayedThisTurn
public void resetCharacterPlayedThisTurn() -
payCharacter
private void payCharacter() -
lightify
This method returns the light version of the GameState, with all the useful information to be sent over the network -
createSnapshot
public void createSnapshot()Description copied from class:AggregateGenerates the snapshot and saves the Aggregate updated information to the repository- Overrides:
createSnapshotin classAggregate
-
rollback
Description copied from class:AggregateRecreates the aggregate based on the last snapshot, deletes all the events vit aggregate version > snapshot version
-