Page 1 of 9 123 ... LastLast
Results 1 to 10 of 90

Thread: A* pathfinding example !

  1. #1

    A* pathfinding example !

    I've managed to write a very simple A* pathfinding program using delphiX that works well thaks to a tut on GameDev.net : A* Pathfinig for beginners by Patrick Lester !
    I'm quite proud of myself and to help and have some feedback i'm posting a link to it here (delphiX needed)

    The A* algo (whith sources & exe)

    Waiting for some feedback, Abened

    PS : To move start point, move your mouse while pressing shift.
    To move destination, move your mouse holding Control
    To place walls, clik & move ! (to remove, right clik)

  2. #2

    A* pathfinding example !

    ss

  3. #3

    A* pathfinding example !

    source comment...

    first of all: nottings wrong with your program.

    your way of programming is with the mind.
    you must program 'recursive'>>the way that the computer must use his head(cpu).

    analyse:

    there are 4 ways the 'person' can go.
    starts in a point and ends in a point.
    the grid has a max x&y value.


    for example a procedure:

    Code:
    PathFinding(thisPiont,EndPoint:TPoint;Matrix:grid);
    
    var .  ..  . ;
    begin
    
    //ending.
      if thisPoint=EndPoint then
        Solution(Matrax)
      else
    //moving to all 4 places. (left, right, top, bottom)
      for i:=0 to 3 do
    //check if that place if free.
      if OK(thisPoint,i,Matrix) then
      begin
    // everything went fine, mark the place where you are (thisPoint) and move on.
    //mark
        Matrix[thisPoint.x,thisPoint.y]:=False;
    //move on
        newPoint:=thisPoint;
        case i of
          1:Dec(newPoint.x);
          2:Inc(newPoint.x);
          3:Dec(newPoint.y);
          4:Inc(newPoint.y);
        end;
        PathFinding&#40;newPoint,endPoint,Matrix&#41;;//<<< this is recursive.
    //unmark
        Matrix&#91;thisPoint.x,thisPoint.y&#93;&#58;=True;
      end;
    end;
    now there are 2 other procedures to write.
    Solution(Matrix:grid);

    and
    OK(thisPoint,i,Matrix);

    the solution procedure is simple this is calling when the computer found A way to the end, <<ps. there is often more then one!!!!

    the OK procedure is the ai for the computer.
    return false when:
    1:the newPoint is already taken.
    2:there was already found a shorter way.
    etc. ect.
    otherwise return true.

    the second point i recommend is not nessesery. but slows the computer down. becauce the Matrix that was found is not the Matrix where we are looking for.

    the more false returning in the OK procedure the smatrer the computer.

    this way of programming is called 'BACKTRACKING'.

  4. #4

    Re: A* pathfinding example !

    thank you Abened ! A* is really tricky so i enjoyed the help of your work. It is exactly what i was looking for.

    I have just ported it to freepascal. It works fine with only minor changes (static Arrays). Using Console output it can be compiled by any existing pascal compiler.

    THANKS!

  5. #5

    A* pathfinding example !

    It is just what I was searching.
    Thanks, soon post a coment. :lol:

  6. #6

    A *

    What is the max size of the nodes in X and Y Whit this technique?
    The hell is empty, all the devils are here.

  7. #7
    Legendary Member cairnswm's Avatar
    Join Date
    Nov 2002
    Location
    Randburg, South Africa
    Posts
    1,537

    A* pathfinding example !

    There is an article on A* pathfinding in the Tools and Tutorials forum that I wrote a few years ago - it includes example code on how the algorithm works.
    William Cairns
    My Games: http://www.cairnsgames.co.za (Currently very inactive)
    MyOnline Games: http://TheGameDeveloper.co.za (Currently very inactive)

  8. #8

    A* pathfinding example !

    Quote Originally Posted by cairnswm
    There is an article on A* pathfinding in the Tools and Tutorials forum that I wrote a few years ago - it includes example code on how the algorithm works.
    is that anywhere to download?
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

  9. #9
    Legendary Member cairnswm's Avatar
    Join Date
    Nov 2002
    Location
    Randburg, South Africa
    Posts
    1,537

    A* pathfinding example !

    I've updated the tutorial with the links.

    The example code can be downloaded from http://www.cairnsgames.co.za/files/astar1.zip - This is the final code - I do not have theintermediate example available any more.
    William Cairns
    My Games: http://www.cairnsgames.co.za (Currently very inactive)
    MyOnline Games: http://TheGameDeveloper.co.za (Currently very inactive)

  10. #10

    A* pathfinding example !

    interesting stuff, is it okay to use in any apps or a under specific license?
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

Page 1 of 9 123 ... LastLast

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
  •  
Comodo SSL