PDA

View Full Version : A* algorithm



Ichi
31st March 2013, 11:58
Hi,
I am trying make an A* algorithm. My algorithm works good without walls but when i add walls it doesnt work i don't know why full code :
8870

And this is the main finding function:


void PathFinder::findPath()
{
pathFind = false;
openList.clear();
closedList.clear();
QQuickItem *currentItem = start;
QList<QQuickItem*> path;
closedList.append(start);
findNeighbors(currentItem);
while(!openList.isEmpty())
{
findNeighbors(currentItem);
QQuickItem *minimal = openList.first();
foreach (QQuickItem *item, openList)
{
int minF = getF(currentItem, minimal);
int itemF = getF(currentItem, item);
if(itemF < minF)
{
minimal = item;

}
}
currentItem = minimal;
closedList.append(currentItem);
path.append(currentItem);

if(currentItem == finish)
{
pathFind = true;
path.removeOne(currentItem);
drawPath(path);
break;
}
}

qDebug() << (pathFind ? "path finded" : "no path");

}

Please help me i dont have any idea how make it

amleto
31st March 2013, 12:44
http://en.wikipedia.org/wiki/A*_search_algorithm

Use your debugger. Learning how to is not optional for programmers

Ichi
31st March 2013, 18:31
ok i fix it