- All Implemented Interfaces:
RuleSetStrategy
- Direct Known Subclasses:
AffectMyTurnStrategy
,AffectOpponentTurnStrategy
,BuildingStrategy
,MovementStrategy
,WinConditionStrategy
public class RuleSetBase extends java.lang.Object implements RuleSetStrategy
It defines the default rules for moving, building and setting up the turn:
- Setup: using this ruleset, the player can place TWO workers at the beginning of the game
(see
Worker
for details about the Workers placement) - Turn Order: the player MUST choose a worker, move the worker in another cell (see #isMoveActionValid()) and build (see #isBuildActionValid()) with THE SAME worker
-
Field Summary
Fields Modifier and Type Field Description protected int
buildsAvailable
protected Game
game
protected boolean
hasMovedUp
protected Worker
movedWorker
protected int
movesAvailable
protected int
movesUpAvailable
protected Cell
startingCell
-
Constructor Summary
Constructors Constructor Description RuleSetBase()
Default constructorRuleSetBase(RuleSetStrategy ruleSetBase, Game game)
Copy constructor -
Method Summary
Modifier and Type Method Description protected void
addBuildableCells(Worker worker, java.util.List<Cell> cells)
Adds to a list the cells on which the given player can build onprotected void
addWalkableCells(Worker worker, java.util.List<Cell> cells)
Adds to a list the cells on which the given player can walk onprotected boolean
canBuild(BuildAction action)
Determines if the worker chosen for the build action can actually buildboolean
canEndTurn()
Determines whether a player can end its turnboolean
canEndTurnAutomatically()
Determines whether a player can end its turnboolean
checkLoseCondition()
Checks if the turn can beginboolean
checkLoseCondition(BuildAction buildAction)
Determines if the lose conditions are satisfied upon a build actionboolean
checkLoseCondition(MoveAction moveAction)
Determines if the lose conditions are satisfied upon a movement actionboolean
checkWinCondition(MoveAction action)
Determines if the win conditions are satisfied upon a movement actionRuleSetStrategy
cloneStrategy(Game game)
Creates a clone of this objectvoid
doEffect()
Applies end turn effectsjava.util.List<Block>
getBlocks(Cell selectedCell)
Provides the possible blocks buildable on a given celljava.util.List<Cell>
getBuildableCells(Worker worker)
Provides a list of cells on which the worker can build onint
getBuildsAvailable()
buildsAvailable getterWorker
getMovedWorker()
movedWorker getterint
getMovesAvailable()
movesAvailable getterint
getMovesUpAvailable()
movesUpAvailable getterjava.util.List<PossibleActions>
getPossibleActions(Worker worker)
Provides a list of possible actions for a player to perform, based on the chosen workerjava.util.List<Cell>
getWalkableCells(Worker worker)
Provides a list of cells on which the worker can walk onboolean
hasMovedUp()
hasMovedUp getterprotected void
initialize()
Sets the parameters for a new turnboolean
isBuildActionValid(BuildAction action)
Determines if a buildAction is legal and applies itprotected boolean
isCorrectBlock(BuildAction action)
Determines if the block to be built can actually be builtprotected boolean
isCorrectDistance(Worker worker, Cell cell)
Determines if a worker can reach a cellprotected boolean
isInsideBuildableCells(BuildAction action)
Determines if the buildAction's target cell is a legal oneprotected boolean
isInsideWalkableCells(MoveAction action)
Determines if the moveAction's target cell is a legal oneboolean
isMoveActionValid(MoveAction action)
Determines if a moveAction is legal and applies itvoid
setGame(Game game)
game settervoid
setMovesUpAvailable(int num)
movesUpAvailable setter
-
Field Details
-
game
-
movesAvailable
protected int movesAvailable -
movesUpAvailable
protected int movesUpAvailable -
buildsAvailable
protected int buildsAvailable -
hasMovedUp
protected boolean hasMovedUp -
startingCell
-
movedWorker
-
-
Constructor Details
-
RuleSetBase
public RuleSetBase()Default constructor- See Also:
initialize()
-
RuleSetBase
Copy constructorUsed to restore the game status in case of unfortunate events on the server side
- Parameters:
ruleSetBase
- the ruleSet to restoregame
- the game code
-
-
Method Details
-
initialize
protected void initialize()Sets the parameters for a new turnUsing this ruleSet, a player is granted one movement and one building action, which have to be used in this order and by the same worker
-
getMovesAvailable
public int getMovesAvailable()movesAvailable getter- Specified by:
getMovesAvailable
in interfaceRuleSetStrategy
- Returns:
- the number of moves available
-
getMovesUpAvailable
public int getMovesUpAvailable()movesUpAvailable getter- Specified by:
getMovesUpAvailable
in interfaceRuleSetStrategy
- Returns:
- the number of moves available on a taller building
-
setMovesUpAvailable
public void setMovesUpAvailable(int num)movesUpAvailable setterUsed when an effect has a malus on other players' available moves
- Specified by:
setMovesUpAvailable
in interfaceRuleSetStrategy
- Parameters:
num
- the number of moves up to be made available
-
hasMovedUp
public boolean hasMovedUp()hasMovedUp getter- Specified by:
hasMovedUp
in interfaceRuleSetStrategy
- Returns:
- true if the player moved up during the last turn, false otherwise
-
getBuildsAvailable
public int getBuildsAvailable()buildsAvailable getter- Specified by:
getBuildsAvailable
in interfaceRuleSetStrategy
- Returns:
- the number of buildings the player can build
-
getMovedWorker
movedWorker getter- Specified by:
getMovedWorker
in interfaceRuleSetStrategy
- Returns:
- the worker which has been moved during the last turn (can be null)
-
setGame
game setter- Specified by:
setGame
in interfaceRuleSetStrategy
- Parameters:
game
- the game in which the effect is used
-
getBlocks
Provides the possible blocks buildable on a given cellUsing this ruleSet, a worker will always be able to build only one kind of block, immediately higher than the one it is trying to build on
- Specified by:
getBlocks
in interfaceRuleSetStrategy
- Parameters:
selectedCell
- the cell to get the buildable blocks for- Returns:
- a list of blocks that can be built on the given cell
-
doEffect
public void doEffect()Applies end turn effectsUsing this ruleSet, the end turn effects simply resets the attributes changed during the turn
- Specified by:
doEffect
in interfaceRuleSetStrategy
-
isInsideWalkableCells
Determines if the moveAction's target cell is a legal one- Parameters:
action
- the action to analyze- Returns:
- true if the cell is walkable, false otherwise
-
getPossibleActions
Provides a list of possible actions for a player to perform, based on the chosen workerg this ruleSet, the possible actions for a worker are:
- Change Worker/Move, if the worker has not been moved yet
- Build, if the worker has been moved
- None, in any other case
- Specified by:
getPossibleActions
in interfaceRuleSetStrategy
- Parameters:
worker
- the worker to perform an action with- Returns:
- a list of possible performable actions
-
isMoveActionValid
Determines if a moveAction is legal and applies itg this ruleSet, a movement action is considered valid if the following conditions are all true:
- no worker has been moved yet during the turn
- the target cell is a walkable cell (see getWalkableCells(Worker)) for the worker to be moved
- Specified by:
isMoveActionValid
in interfaceRuleSetStrategy
- Parameters:
action
- the movement action to validate- Returns:
- true if the action has been applied, false otherwise
-
isBuildActionValid
Determines if a buildAction is legal and applies itg this ruleSet, a build action is considered valid if the following conditions are all true:
- a worker has already been moved
- the worker to perform the action is the same which has been moved
- the cell to build on is a buildable cell (see getBuildableCells(Worker)) for the worker
- Specified by:
isBuildActionValid
in interfaceRuleSetStrategy
- Parameters:
action
- the build action to validate- Returns:
- true if the action has been applied, false otherwise
-
isInsideBuildableCells
Determines if the buildAction's target cell is a legal one- Parameters:
action
- the action to analyze- Returns:
- true if the cell is buildable, false otherwise
- See Also:
isBuildActionValid(BuildAction)
-
canBuild
Determines if the worker chosen for the build action can actually build- Parameters:
action
- the action to analyze- Returns:
- true if the worker can build, false otherwise
- See Also:
isBuildActionValid(BuildAction)
-
isCorrectBlock
Determines if the block to be built can actually be built- Parameters:
action
- the action to analyze- Returns:
- true if the block can be placed, false otherwise
- See Also:
isBuildActionValid(BuildAction)
-
checkWinCondition
Determines if the win conditions are satisfied upon a movement actionUsing this ruleSet, a player can win only upon moving (following the rules already defined in isMoveActionValid(MoveAction)) on a level 3 building
- Specified by:
checkWinCondition
in interfaceRuleSetStrategy
- Parameters:
action
- the action to analyze- Returns:
- true if the action led to victory, false otherwise
-
checkLoseCondition
Determines if the lose conditions are satisfied upon a movement actionUsing this ruleSet, a player can lose upon a movement action if the worker which has been moved cannot build any block around it
- Specified by:
checkLoseCondition
in interfaceRuleSetStrategy
- Parameters:
moveAction
- the action to analyze- Returns:
- true if the action led to a loss, false otherwise
-
checkLoseCondition
public boolean checkLoseCondition()Checks if the turn can beginUsing 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 interfaceRuleSetStrategy
- Returns:
- true if there is at least one action to perform, false otherwise
-
checkLoseCondition
Determines if the lose conditions are satisfied upon a build actionUsing this ruleSet, the player can never lose after it performs a build action; it might "trap itself", but in this case it will lose on the beginning of its next turn.
- Specified by:
checkLoseCondition
in interfaceRuleSetStrategy
- Parameters:
buildAction
- the action to analyze- Returns:
- true if the action led to a loss, false otherwise
-
getWalkableCells
Provides a list of cells on which the worker can walk onUsing 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 interfaceRuleSetStrategy
- Parameters:
worker
- the worker to be moved- Returns:
- a list of walkable cells
-
addWalkableCells
Adds to a list the cells on which the given player can walk on- Parameters:
worker
- the worker to be movedcells
- the list of walkable cells
-
isCorrectDistance
Determines if a worker can reach a cellA cell is considered reachable if the height difference between the worker's cell and the target cell is at most 1, and the movesUpAvailable counter has not been decreased
- Parameters:
worker
- the worker to be movedcell
- the target cell- Returns:
- true if the cell is reachable, false otherwise
-
getBuildableCells
Provides a list of cells on which the worker can build onUsing this ruleSet, a worker can build on any cell adjacent to its starting cell
- Specified by:
getBuildableCells
in interfaceRuleSetStrategy
- Parameters:
worker
- the worker to build with- Returns:
- a list of buildable cells
-
addBuildableCells
Adds to a list the cells on which the given player can build on- Parameters:
worker
- the worker to be movedcells
- the list of buildable cells- See Also:
getBuildableCells(Worker)
-
canEndTurn
public boolean canEndTurn()Determines whether a player can end its turnUsing this ruleSet, a player cannot end manually its turn
- Specified by:
canEndTurn
in interfaceRuleSetStrategy
- Returns:
- true if the player can end its turn, false otherwise
-
canEndTurnAutomatically
public boolean canEndTurnAutomatically()Determines whether a player can end its turnUsing this ruleSet, a player turn is ended automatically right after it performs its build action
This method should never be invoked directly from the player- Specified by:
canEndTurnAutomatically
in interfaceRuleSetStrategy
- Returns:
- true if the player can end its turn, false otherwise
-
cloneStrategy
Creates a clone of this object- Specified by:
cloneStrategy
in interfaceRuleSetStrategy
- Parameters:
game
- the current game- Returns:
- a clone of this object
-