Package ai.libs.jaicore.problems.npuzzle
Class NPuzzleState
- java.lang.Object
-
- ai.libs.jaicore.problems.npuzzle.NPuzzleState
-
public class NPuzzleState extends java.lang.ObjectA 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.
-
-
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 booleanequals(java.lang.Object obj)int[][]getBoard()doublegetDistance()Returns the steps which are minimal need to reach a goal stateintgetEmptyX()intgetEmptyY()intgetNumberOfWrongTiles()Returns the number of wrongly placed tilesinthashCode()java.lang.StringtoString()Returns a graphical version of the board configuration.
-
-
-
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 nodeemptyX- 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:
toStringin classjava.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:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
-