Package api

Enum State

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<State>

    public enum State
    extends java.lang.Enum<State>
    Possible cell states for the Pearls game.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean canMerge​(State s1, State s2)
      Returns true if both given states are movable and have opposite parity.
      static boolean isBoundary​(State s, boolean containsMovable)
      Determines whether the given state should be considered a boundary when constructing a state sequence for a move.
      static boolean isMovable​(State s)
      Returns true if the given state represents a movable block.
      static boolean isSpikes​(State s)
      Returns true if the given state is some form of spikes.
      static boolean spikesAreDeadly​(State s, Direction dir)
      Returns true if the given state is spikes pointing in the direction opposite the given Direction, or if the given state is SPIKES_ALL.
      static State valueOf​(java.lang.String name)
      Returns the enum constant of this type with the specified name.
      static State[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      • Methods inherited from class java.lang.Enum

        compareTo, equals, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Enum Constant Detail

      • EMPTY

        public static final State EMPTY
      • WALL

        public static final State WALL
      • PEARL

        public static final State PEARL
      • OPEN_GATE

        public static final State OPEN_GATE
      • CLOSED_GATE

        public static final State CLOSED_GATE
      • MOVABLE_POS

        public static final State MOVABLE_POS
      • MOVABLE_NEG

        public static final State MOVABLE_NEG
      • SPIKES_LEFT

        public static final State SPIKES_LEFT
      • SPIKES_RIGHT

        public static final State SPIKES_RIGHT
      • SPIKES_DOWN

        public static final State SPIKES_DOWN
      • SPIKES_UP

        public static final State SPIKES_UP
      • SPIKES_ALL

        public static final State SPIKES_ALL
      • PORTAL

        public static final State PORTAL
    • Method Detail

      • values

        public static State[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (State c : State.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static State valueOf​(java.lang.String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        Parameters:
        name - the name of the enum constant to be returned.
        Returns:
        the enum constant with the specified name
        Throws:
        java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
        java.lang.NullPointerException - if the argument is null
      • isMovable

        public static boolean isMovable​(State s)
        Returns true if the given state represents a movable block.
        Parameters:
        s - a State value
        Returns:
        true if the given state is one of the two movable block types
      • canMerge

        public static boolean canMerge​(State s1,
                                       State s2)
        Returns true if both given states are movable and have opposite parity.
        Parameters:
        s1 - a State value
        s2 - a State value
        Returns:
        true if both given states are movable and have opposite parity
      • isSpikes

        public static boolean isSpikes​(State s)
        Returns true if the given state is some form of spikes.
        Parameters:
        s - a State
        Returns:
        true if the given state is one of the five types of spikes
      • spikesAreDeadly

        public static boolean spikesAreDeadly​(State s,
                                              Direction dir)
        Returns true if the given state is spikes pointing in the direction opposite the given Direction, or if the given state is SPIKES_ALL.
        Parameters:
        s - a State value
        dir - a Direction
        Returns:
        true if player moving in given direction would be impaled on the given state
      • isBoundary

        public static boolean isBoundary​(State s,
                                         boolean containsMovable)
        Determines whether the given state should be considered a boundary when constructing a state sequence for a move. The "boundary" is the last cell in the sequence, beyond which nothing will move. For motion of the player, the possible boundaries are CLOSED_GATE, WALL, or any form of spikes. However, movable blocks cannot pass through gates or portals, so if there were any movable blocks encountered previously in constructing the sequence, then OPEN_GATE and PORTAL would also be considered boundary states.
        Parameters:
        s - any State value
        containsMovable - true if OPEN_GATE and PORTAL should also be treated as boundary states, false otherwise
        Returns:
        true if the given state is a boundary when constructing a state sequence