I am doing an 8-puzzle project and I have a method that checks whether two states of the puzzle are the same. I am using a two dimensional array to represent the grid. I was wondering why the following if statement is never evaluating to true. I called the method with a two dimensional array that was absolutely the same as the one called state which represents the current grid state.
public List<Node> getSuccessors()
{
//Code that is not relevant
int [][] nextState = move(direction);
if (areDifferent(nextState))
{
System.out.println("INSIDE");
}
}
//Checks whether two states are different
public boolean isStateDifferent(int[][] nextState)
{
boolean different = false;
for (int i = 0; i < state.length; i++)
{
for (int j = 0; j < state.length; j++)
{
if (state[i][j] != nextState[i][j])
{
different = true;
}
}
}
return different;
}
Aucun commentaire:
Enregistrer un commentaire