I am writing a program that is solving a 8 tile puzzle but I am not getting any out put, I am running the debugger and I am generating the right successors, one of which is the goal state that I want but when I compare them it does not say they are so my program just keeps looping and looping. Does anyone know why this might be happening?
public static void BFSSearch(Node start, Node goal) {
Queue<Node> q = new LinkedList<>();
q.add(start);
while (!q.isEmpty()) {
Node theNode = q.poll();
if (theNode.equals(goal)) {
Stack<Node> path = new Stack<>();
path.push(theNode);
theNode = theNode.getParent();
while (theNode.getParent() != null) {
path.push(theNode);
theNode = theNode.getParent();
}
path.push(theNode);
int stackSize = path.size();
for (int i = 0; i < stackSize; i++) {
theNode = path.pop();
theNode.printState();
}
} else {
ArrayList<Node> successors = theNode.genSuccessors();
for (int i = 0; i < successors.size(); i++) {
Node newNode = new Node(successors.get(i).curr);
if (newNode.equals(goal)){
System.out.println("found");
}
if (!checkRepeats(newNode)) {
((LinkedList<Node>) q).add(newNode);
}
}
}
}
}