Class TwoPhaseMoveSelector<T>
java.lang.Object
common.util.TwoPhaseMoveSelector<T>
- Type Parameters:
T
- represents the moves that can be applied to the states
Utility class to determine the next move in two-phase move-type puzzles or
two-player games. It serves to select a source and a target that together
make up a move.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Represents the current selection phase. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTwoPhaseMoveSelector
(TwoPhaseMoveState<T> state) Creates aTwoPhaseMoveSelector
object to determine the next move in the state specified. -
Method Summary
Modifier and TypeMethodDescriptionfinal T
getFrom()
Returns the source selected.getPhase()
Returns the current selection phase.final T
getTo()
Returns the target selected.final boolean
Returns whether the last selection (i.e, for the source or the target, respectively) was invalid.final boolean
Returns whether the move is ready to be made.final void
makeMove()
Makes the move selected.final void
reset()
Resets the selection, i.e., resets both the source and the target selected.final void
Selects the action specified to be either the source or the target of the move, respectively.protected void
selectFrom
(T from) protected void
protected void
Sets the current selection phase.
-
Field Details
-
phase
-
-
Constructor Details
-
TwoPhaseMoveSelector
Creates aTwoPhaseMoveSelector
object to determine the next move in the state specified.- Parameters:
state
- the state in which the next move is to be made
-
-
Method Details
-
getPhase
Returns the current selection phase.- Returns:
- the current selection phase
-
setPhase
Sets the current selection phase. The method is provided to be overridden by subclasses.- Parameters:
phase
- the current selection phase
-
isReadyToMove
public final boolean isReadyToMove()Returns whether the move is ready to be made.- Returns:
- whether the move is ready to be made
-
select
Selects the action specified to be either the source or the target of the move, respectively. However, no selection is made if the selection is invalid.- Parameters:
action
- the action to be selected
-
selectFrom
-
selectTo
-
getFrom
Returns the source selected. If the move is not yet ready to be made, then anIllegalStateException
is thrown.- Returns:
- the source selected
-
getTo
Returns the target selected. If the move is not yet ready to be made, then anIllegalStateException
is thrown.- Returns:
- the target selected
-
isInvalidSelection
public final boolean isInvalidSelection()Returns whether the last selection (i.e, for the source or the target, respectively) was invalid.- Returns:
- whether the last selection (i.e, for the source or the target, respectively) was invalid
-
makeMove
public final void makeMove()Makes the move selected. If the move is not yet ready to be made, then anIllegalStateException
is thrown. -
reset
public final void reset()Resets the selection, i.e., resets both the source and the target selected.
-