Module AM37

Class BuildBeforeAfterMovement

java.lang.Object
it.polimi.ingsw.model.rules.RuleSetBase
it.polimi.ingsw.model.godCardsEffects.affectMyTurnEffects.AffectMyTurnStrategy
it.polimi.ingsw.model.godCardsEffects.affectMyTurnEffects.BuildBeforeAfterMovement
All Implemented Interfaces:
RuleSetStrategy

public class BuildBeforeAfterMovement
extends AffectMyTurnStrategy
Build (optional), Move, Build *
This effect alters the player's turn order; either, the player can:
  • Play the turn as usual, following the RuleSetBase
  • Build a block, move on a level not higher than the current one, then build again
  • Constructor Details

  • Method Details

    • initialize

      public void initialize()
      Sets the parameters for a new turn

      Using this ruleSet, a player is granted one movement and two building action, to be performed by the same worker following the rules mentioned in the class documentation.
      The attribute stuckWorkers is needed because, using this effect, it is possible to lose after performing a build action; this counter keeps track of the number of the controlled workers that can perform no action during the turn

      Overrides:
      initialize in class RuleSetBase
    • doEffect

      public void doEffect()
      Applies end turn effects

      Using this ruleSet, the end turn effects simply resets the attributes changed during the turn

      Specified by:
      doEffect in interface RuleSetStrategy
      Overrides:
      doEffect in class RuleSetBase
    • getPossibleActions

      public java.util.List<PossibleActions> getPossibleActions​(Worker worker)
      Provides a list of possible actions for a player to perform, based on the chosen worker

      g this ruleSet, the possible actions for a worker are:

      • Change Worker/Move/Build, if the worker has not been moved yet
      • Move, if the worker built as its first action
      • Build, if the worker has been moved
      • None, in any other case
      Note that in the rare case that all the possible actions lead the player to a loss, it must perform a move anyway, since the game board has to be altered before removing its workers from the board
      Specified by:
      getPossibleActions in interface RuleSetStrategy
      Overrides:
      getPossibleActions in class RuleSetBase
      Parameters:
      worker - the worker to perform an action with
      Returns:
      a list of possible performable actions
    • isMoveActionValid

      public boolean isMoveActionValid​(MoveAction action)
      Determines if a moveAction is legal and applies it

      g this ruleSet, a movement action is considered valid if the following conditions are all true:

      • no worker has been moved yet during the turn OR the worker has built but has not been moved
      • the target cell is a walkable cell (see getWalkableCells(Worker)) for the worker to be moved
      Specified by:
      isMoveActionValid in interface RuleSetStrategy
      Overrides:
      isMoveActionValid in class RuleSetBase
      Parameters:
      action - the movement action to validate
      Returns:
      true if the action has been applied, false otherwise
    • isBuildActionValid

      public boolean isBuildActionValid​(BuildAction action)
      Determines if a buildAction is legal and applies it

      g this ruleSet, a build action is considered valid if the following conditions are all true:

      • no worker has been moved yet OR the worker to perform the action has already been moved
      • the cell to build on is a buildable cell (see getBuildableCells(Worker)) for the worker
      Specified by:
      isBuildActionValid in interface RuleSetStrategy
      Overrides:
      isBuildActionValid in class RuleSetBase
      Parameters:
      action - the build action to validate
      Returns:
      true if the action has been applied, false otherwise
    • checkLoseCondition

      public boolean checkLoseCondition()
      Checks if the turn can begin

      Using this ruleSet, a player's turn can start if at least one of the player's workers can perform a movement action

      Specified by:
      checkLoseCondition in interface RuleSetStrategy
      Overrides:
      checkLoseCondition in class RuleSetBase
      Returns:
      true if there is at least one action to perform, false otherwise
    • checkLoseCondition

      public boolean checkLoseCondition​(BuildAction buildAction)
      Determines if the lose conditions are satisfied upon a build action

      Using this ruleSet, the player can lose after performing a build action: since the worker cannot be moved upwards if the player decides to build first, it can lose if, after placing the building block, all the cells around him become inaccessible

      Specified by:
      checkLoseCondition in interface RuleSetStrategy
      Overrides:
      checkLoseCondition in class RuleSetBase
      Parameters:
      buildAction - the action to analyze
      Returns:
      true if the action led to a loss, false otherwise
    • getWalkableCells

      public java.util.List<Cell> getWalkableCells​(Worker worker)
      Provides a list of cells on which the worker can walk on

      Using this ruleSet, a worker can walk on the cells adjacent to its starting cell which height difference is at most one compared to the starting cell (domes do not count), is not occupied by another worker and has no dome built on it

      Specified by:
      getWalkableCells in interface RuleSetStrategy
      Overrides:
      getWalkableCells in class RuleSetBase
      Parameters:
      worker - the worker to be moved
      Returns:
      a list of walkable cells
    • getBuildableCells

      public java.util.List<Cell> getBuildableCells​(Worker worker)
      Provides a list of cells on which the worker can build on

      Using this ruleSet, a worker can build on any cell adjacent to its cell, in both the cases mentioned above

      Specified by:
      getBuildableCells in interface RuleSetStrategy
      Overrides:
      getBuildableCells in class RuleSetBase
      Parameters:
      worker - the worker to build with
      Returns:
      a list of buildable cells
    • cloneStrategy

      public RuleSetStrategy cloneStrategy​(Game game)
      Creates a clone of this object
      Specified by:
      cloneStrategy in interface RuleSetStrategy
      Overrides:
      cloneStrategy in class RuleSetBase
      Parameters:
      game - the current game
      Returns:
      a clone of this object