I'm trying to solve the 8-puzzle problem using the heuristic search. I'm using a 3*3 matrix to represent a possibility. The code is not complete, but when I try to add the explored element to the explored set(which is an ArrayList), it only updates the current element in explored set instead of adding one more element to the end. When I try to print all the elements in the explored set, there is always only one element (updated each iteration). I'm wondering what is wrong with my code. Thank you!!
public static void printexplored(ArrayList<int[][]> explored){
//System.out.println("the size of the explored set is " + explored.size());
System.out.println("the explored set is...");
while(explored.isEmpty() == false){
int[][] temp = explored.remove(0);
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++){
System.out.print(temp[i][j]);
}
System.out.println();
}
System.out.println();
}
}
public static boolean heuristicSearch(int initialState[][]){
Queue<int[][]> frontier = new LinkedList<int[][]>();
frontier.add(initialState);
ArrayList<int[][]> explored = new ArrayList<int[][]>();
int f_score = 0;
//int count = 0;
while(frontier.isEmpty() == false){
int[][] temporaryState = new int[3][3];
temporaryState = frontier.remove();
int indexX = blankIndexX(temporaryState);
int indexY = blankIndexY(temporaryState);
explored.add(temporaryState);
printexplored(explored);