Class Puzzle


  • public final class Puzzle
    extends Object
    State in a puzzle game.
    Author:
    Herbert Praehofer
    • Field Detail

      • RAND

        static final Random RAND
        A random number generator
      • NUMBERS

        static final int[] NUMBERS
        Array representing solution
      • SOLUTION

        public static final Puzzle SOLUTION
        Solution state
      • field

        private final int[][] field
    • Constructor Detail

      • Puzzle

        private Puzzle()
      • Puzzle

        private Puzzle​(int... numbers)
    • Method Detail

      • shuffled

        public static Puzzle shuffled()
        Creates a random puzzle state.
        Returns:
        a randomly set puzzle state
      • from

        public static Puzzle from​(int... numbers)
        Creates a puzzle state from sequence of numbers.
        Parameters:
        numbers - the sequence of numbers
        Returns:
        the puzzle from the sequence of numbers
      • get

        public int get​(Pos pos)
        Gets the number at the current position.
        Parameters:
        pos - current position
        Returns:
        the number for the current position
      • isSolution

        public boolean isSolution()
        Tests if this puzzle state represents the solution state.
        Returns:
        true if this represents the solution state
      • getNextStates

        public List<Puzzle> getNextStates()
        Returns a list of possible successor states
        Returns:
        the list of successor states
      • assess

        public int assess()
        Computes a difference of this state to the solution state.
        Returns:
        the difference to the solution state
      • getEmptyPos

        public Pos getEmptyPos()
        Gets the position which is empty.
        Returns:
        the empty position
      • getNumbers

        public List<Integer> getNumbers()
        Returns the sequence of numbers in a list.
        Returns:
        the sequence of numbers
      • getMoveHistory

        public List<Move> getMoveHistory()
        Gets the list of moves taken to get to this state.
        Returns:
        a list of moves taken to get to this state
      • getStateHistory

        public List<Puzzle> getStateHistory()
        Gets the list of states to this state.
        Returns:
        a list of states to this state
      • getNextMoves

        public List<Move> getNextMoves()
        Gets the moves possible from this state.
        Returns:
        the list of possible moves
      • doMove

        public Puzzle doMove​(Move move)
        Executes a next move.
        Parameters:
        move - the move
        Returns:
        the next puzzle state
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • equalFieds

        private boolean equalFieds​(int[][] f1,
                                   int[][] f2)
      • get

        private int get​(int i,
                        int j)