Package mini2

Enum State

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

    public enum State
    extends java.lang.Enum<State>
    Possible cell states for a certain puzzle game.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static char NULL_CHAR
      Character to represent a null state in string conversions.
      static char[] TEXT
      Text representation for printing states.
    • 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 char getChar​(State s)
      Returns the basic character for a State.
      static State getValue​(char c)
      Returns the State corresponding to the given character, if possible.
      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 java.lang.String toString​(State[] arr)
      Converts a state array to a string representation, using the character representations defined in this class, with an extra space inserted between characters.
      static java.lang.String toString​(State[] arr, boolean addSpaces)
      Converts a state array to a string representation, using the character representations defined in this class, where an extra space is optionally inserted between characters.
      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
    • Field Detail

      • TEXT

        public static final char[] TEXT
        Text representation for printing states.
      • NULL_CHAR

        public static final char NULL_CHAR
        Character to represent a null state in string conversions.
        See Also:
        Constant Field Values
    • 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
      • 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
      • getChar

        public static char getChar​(State s)
        Returns the basic character for a State. Returns NULL_CHAR if the given state is null.
        Parameters:
        s - a State
        Returns:
        character for the given state
      • getValue

        public static State getValue​(char c)
        Returns the State corresponding to the given character, if possible. Any capital letter in the range 'A' - 'Z' is treated as a portal.
        Parameters:
        c - given character
        Returns:
        State corresponding to the given character, of null if the character does not correspond to a State
      • toString

        public static java.lang.String toString​(State[] arr)
        Converts a state array to a string representation, using the character representations defined in this class, with an extra space inserted between characters. A null state will be represented by the character NULL_CHAR.
        Parameters:
        arr - array of State
        Returns:
        string representation of the State array
      • toString

        public static java.lang.String toString​(State[] arr,
                                                boolean addSpaces)
        Converts a state array to a string representation, using the character representations defined in this class, where an extra space is optionally inserted between characters. A null state will be represented by the character NULL_CHAR.
        Parameters:
        arr - array of State
        addSpaces - if true, method inserts a space between characters
        Returns:
        string representation of the State array