예제 #1
0
list<TPoint> PathFindAStar::computePath(TPoint  startPoint, TPoint endPoint)
{
    TPoint current;
    myCloseList.clear();
    myOpenList.push_back(startPoint);
    computeHeuristics(endPoint);
    Visited myNavigated;
    myNavigated.clear();
    myMap->getGraph()[startPoint.x][startPoint.y].poids=0;
    myMap->getGraph()[startPoint.x][startPoint.y].heuristic=
	myMap->getGraph()[startPoint.x][startPoint.y].poids+computeHeuristic(startPoint,endPoint);
    while(myOpenList.size()!=0)
    {

	current=minHeuristic(myOpenList);
	if((current.x==endPoint.x) && (current.y==endPoint.y))
	{
	    return reconstruire(myNavigated,endPoint);
	}
	removeFromList(myOpenList,current);
	myCloseList.push_front(current);
	list<TPoint> neibs= myMap->getGraph()[current.x][current.y].points;
	list<TPoint>::iterator p;
        orderNeibs(neibs,endPoint);
	for(p=neibs.begin();p!=neibs.end();p++)
	{
		
	    if(belongs(myCloseList,*p))
	    {
	    }
	    else
	    {
		int tentative=myMap->getGraph()[current.x][current.y].poids+1;
				
		if((!belongs(myOpenList,*p))||(tentative<=myMap->getGraph()[(*p).x][(*p).y].poids))
		{


		    myNavigated[make_pair((*p).x,(*p).y)]=make_pair(current.x,current.y);
		    myMap->getGraph()[(*p).x][(*p).y].poids=tentative;
		    myMap->getGraph()[(*p).x][(*p).y].heuristic=tentative+computeHeuristic((*p),endPoint);
		    if(!belongs(myOpenList,*p))
		    {
			myOpenList.push_front(*p);	
		    }

		}
			
	    }
		
	}
    }
    list<TPoint> b;
    return b;

	
}