Results 1 to 3 of 3

Thread: A* algorithm

  1. #1
    Join Date
    Feb 2013
    Posts
    29
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default A* algorithm

    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:
    Qt Code:
    1. void PathFinder::findPath()
    2. {
    3. pathFind = false;
    4. openList.clear();
    5. closedList.clear();
    6. QQuickItem *currentItem = start;
    7. QList<QQuickItem*> path;
    8. closedList.append(start);
    9. findNeighbors(currentItem);
    10. while(!openList.isEmpty())
    11. {
    12. findNeighbors(currentItem);
    13. QQuickItem *minimal = openList.first();
    14. foreach (QQuickItem *item, openList)
    15. {
    16. int minF = getF(currentItem, minimal);
    17. int itemF = getF(currentItem, item);
    18. if(itemF < minF)
    19. {
    20. minimal = item;
    21.  
    22. }
    23. }
    24. currentItem = minimal;
    25. closedList.append(currentItem);
    26. path.append(currentItem);
    27.  
    28. if(currentItem == finish)
    29. {
    30. pathFind = true;
    31. path.removeOne(currentItem);
    32. drawPath(path);
    33. break;
    34. }
    35. }
    36.  
    37. qDebug() << (pathFind ? "path finded" : "no path");
    38.  
    39. }
    To copy to clipboard, switch view to plain text mode 
    Please help me i dont have any idea how make it

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: A* algorithm

    http://en.wikipedia.org/wiki/A*_search_algorithm

    Use your debugger. Learning how to is not optional for programmers
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Feb 2013
    Posts
    29
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: A* algorithm

    ok i fix it

Similar Threads

  1. A* pathfind algorithm and Grid
    By Ichi in forum Qt Programming
    Replies: 9
    Last Post: 30th March 2013, 19:55
  2. Help to set up sorting algorithm
    By Quasar in forum General Programming
    Replies: 2
    Last Post: 12th June 2012, 00:16
  3. No Response when Algorithm runs...
    By revellix in forum Qt Programming
    Replies: 2
    Last Post: 13th August 2011, 17:24
  4. qt algorithm speed up problem
    By leonardhead in forum Newbie
    Replies: 3
    Last Post: 27th August 2010, 01:03
  5. Dijkstra's Algorithm
    By therealjag in forum Qt Programming
    Replies: 2
    Last Post: 6th March 2006, 10:16

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.