Class TwoPhaseMoveSelector<T>

java.lang.Object
common.util.TwoPhaseMoveSelector<T>
Type Parameters:
T - represents the moves that can be applied to the states

public class TwoPhaseMoveSelector<T> extends Object
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.
  • Field Details

  • Constructor Details

    • TwoPhaseMoveSelector

      public TwoPhaseMoveSelector(TwoPhaseMoveState<T> state)
      Creates a TwoPhaseMoveSelector 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

      public final TwoPhaseMoveSelector.Phase getPhase()
      Returns the current selection phase.
      Returns:
      the current selection phase
    • setPhase

      protected void setPhase(TwoPhaseMoveSelector.Phase phase)
      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

      public final void select(T action)
      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

      protected void selectFrom(T from)
    • selectTo

      protected void selectTo(T to)
    • getFrom

      public final T getFrom()
      Returns the source selected. If the move is not yet ready to be made, then an IllegalStateException is thrown.
      Returns:
      the source selected
    • getTo

      public final T getTo()
      Returns the target selected. If the move is not yet ready to be made, then an IllegalStateException 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 an IllegalStateException is thrown.
    • reset

      public final void reset()
      Resets the selection, i.e., resets both the source and the target selected.