// Breadth First Search Usage in the common Eight Puzzle Problem.
import java.util.*;

class EightPuzzle {

Queue<String> q = new LinkedList<String>(); // Use of Queue Implemented using LinkedList for Storing All the Nodes in BFS.
Map<String,Integer> map = new HashMap<String, Integer>(); // HashMap is used to ignore repeated nodes

public static void main(String args[]){

String str="087465132"; // Input the Board State as a String with 0 as the Blank Space

EightPuzzle e = new EightPuzzle(); // New Instance of the EightPuzzle
e.add(str,0); // Add the Initial State

while(e.q.peek()!=null){

e.up(e.q.peek()); // Move the blank space up and add new state to queue
e.down(e.q.peek()); // Move the blank space down
e.left(e.q.peek()); // Move left
e.right(e.q.remove()); // Move right and remove the current node from Queue
}
System.out.println("Solution doesn't exist");
}