PDA

View Full Version : A* pathfind algorithm and Grid



Ichi
27th March 2013, 13:29
Hi i want to make some findpath app i am using QML and i don't know how to implement this because i don't know how makes node from QML grid. But i have some problems with implement algorithm. Can somebody give me some advices or links.
Thanks

Ichi
28th March 2013, 09:16
Any help? i simply don't know how to make from QML grid something like tree or graph and how to sent it to c++ class.

lanz
28th March 2013, 10:38
How do you generate grid?

MarekR22
28th March 2013, 11:26
the best approach is to use GridView (http://qt-project.org/doc/qt-4.8/qml-gridview.html). Data model and A* algorithm I would implement in C++.

Ichi
28th March 2013, 11:38
yes i will implement A* algorithm in C++ but have you some source or example ??? It will help me a lot :D
Thanks for help

lanz
28th March 2013, 12:15
What do you need example for?
Try to subdivide your task to a series of simpler task, then you can easily google it/look it up in reference.

1. How to implement A* in C++ (http://code.activestate.com/recipes/577457-a-star-shortest-path-algorithm/).
2. How to expose C++ classes to QML (http://qt-project.org/doc/qt-5.0/qtqml/qtqml-cppintegration-exposecppattributes.html).
3. How to dynamically generate QML elements (http://kunalmaemo.blogspot.ru/2011/04/creating-qml-element-dynamically-on.html).

Ichi
28th March 2013, 12:27
I want some example how to use A* algorithm with QML GridLayout

lanz
28th March 2013, 12:56
OK, I don't think there's particular example or specific component in qt for that.
Try to do it yourself, start with simple QML - C++ calls, then implement graph structure in QML (for example add to your node objects references to neighbors).
Then you can expose these elements to C++, or you can serialize them and send to C++.
After calculating shortest path you can return it as a list of identifiers for example.

Be creative, every complex task is just a number of simple tasks, don't be afraid to write some code! :D

Ichi
30th March 2013, 11:53
Hi yesterday i start code and i do this but i dont know what with walls i dont know how to go back i somebody will look my code and help me i will happy
Code: 8867

Ichi
30th March 2013, 20:55
ok i make it otherwise :



pathFind = false;
openList.clear();
QQuickItem *currentItem = start;
QList<QQuickItem*> path;
openList.append(start);
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;

}
}
openList.removeOne(start);
closedList.append(currentItem);
currentItem = minimal;
path.append(currentItem);
if(currentItem == finish)
{
pathFind = true;
drawPath(path);
}
}
qDebug() << (pathFind ? "path finded" : "no path");

}

but this algorthm dont know how go back