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 :
A-StarTest01.zip
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");
}
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");
}
To copy to clipboard, switch view to plain text mode
Please help me i dont have any idea how make it
Bookmarks