queue<puzzle> Queue;//khai báo hàng đợi
set<puzzle> Set;//khai báo set
puzzle root;
root.count=0;//số lần di cuyển ban đâu là 0
//define the root here
//trạng thái ban đầu như thế nào ?
//
Queue.push(root);//đẩy trạng thái ban đầu vào hàng đợi
bool found=false;
while(Queue.empty()==false)
{
puzzle t=Queue.front();
Queue.pop();//lấy thằng đầu tiên trong hàng đợi ra và loại nó khoti hàng đợi
if(Set.insert(t).second==false) continue;//nếu trạng thái này đã xét thì bỏ qua
if(t.goal()==true)//nếu đây là trạng thái đích
{
found=true;
printf("%d\n",t.count);
break;
}
if(t.canMoveUp()==true) Queue.push(t.movedUp());
if(t.canMoveDown()==true) Queue.push(t.movedDown());
if(t.canMoveLeft()==true) Queue.push(t.movedLeft());
if(t.canMoveRight()==true) Queue.push(t.movedRight());
}
if(found==false) printf("9999\n");//nếu xết hết mọi tổ hợp có thể có mà vẫn không tìm được trạng thái đích