Class NPuzzleState


  • public class NPuzzleState
    extends java.lang.Object
    A node for the normal n-Puzzleproblem. Every node contains the current board configuration as an 2D-Array of integer. The empty space is indicated by an Integer with value 0.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected int[][] board  
      protected int emptyX  
      protected int emptyY  
    • Constructor Summary

      Constructors 
      Constructor Description
      NPuzzleState​(int dim)
      Constructor for a NPuzzleNode which creates a NPuzzleNode with complete randomly distributed numbers.
      NPuzzleState​(int[][] board, int emptyX, int emptyY)
      Constructor for a NPuzzleNode in which the board is already given.
      NPuzzleState​(int dim, int seed)
      Constructor for a NPuzzleNode which creates a NPuzzleNode.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object obj)  
      int[][] getBoard()  
      double getDistance()
      Returns the steps which are minimal need to reach a goal state
      int getEmptyX()  
      int getEmptyY()  
      int getNumberOfWrongTiles()
      Returns the number of wrongly placed tiles
      int hashCode()  
      java.lang.String toString()
      Returns a graphical version of the board configuration.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • board

        protected int[][] board
      • emptyX

        protected int emptyX
      • emptyY

        protected int emptyY
    • Constructor Detail

      • NPuzzleState

        public NPuzzleState​(int dim)
        Constructor for a NPuzzleNode which creates a NPuzzleNode with complete randomly distributed numbers.
        Parameters:
        dim - The dimension of the board.
      • NPuzzleState

        public NPuzzleState​(int dim,
                            int seed)
        Constructor for a NPuzzleNode which creates a NPuzzleNode. The board configuration starts with the targetconfiguration and shuffels the tiles afterwards.
        Parameters:
        dim - The dimension of the board.
        perm - The number of moves which should be made before starting the search. This number is hardcoded to at least 1.
      • NPuzzleState

        public NPuzzleState​(int[][] board,
                            int emptyX,
                            int emptyY)
        Constructor for a NPuzzleNode in which the board is already given.
        Parameters:
        board - The board configuration for this node
        emptyX - The empty space on the x-axis.
        emptyY - The empty space on the y-axis.
        noMoves - The number of already done moves.
    • Method Detail

      • getBoard

        public int[][] getBoard()
      • getEmptyX

        public int getEmptyX()
      • getEmptyY

        public int getEmptyY()
      • toString

        public java.lang.String toString()
        Returns a graphical version of the board configuration. Works best if there is no number with two or more digits.
        Overrides:
        toString in class java.lang.Object
      • getNumberOfWrongTiles

        public int getNumberOfWrongTiles()
        Returns the number of wrongly placed tiles
        Returns:
        The number of wrongly placed tiles.
      • getDistance

        public double getDistance()
        Returns the steps which are minimal need to reach a goal state
        Returns:
        The number of steps.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object