# Thread: A* pathfinding example !

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)

ss

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&#40;thisPiont,EndPoint&#58;TPoint;Matrix&#58;grid&#41;;

var .  ..  . ;
begin

//ending.
if thisPoint=EndPoint then
Solution&#40;Matrax&#41;
else
//moving to all 4 places. &#40;left, right, top, bottom&#41;
for i&#58;=0 to 3 do
//check if that place if free.
if OK&#40;thisPoint,i,Matrix&#41; then
begin
// everything went fine, mark the place where you are &#40;thisPoint&#41; and move on.
//mark
Matrix&#91;thisPoint.x,thisPoint.y&#93;&#58;=False;
//move on
newPoint&#58;=thisPoint;
case i of
1&#58;Dec&#40;newPoint.x&#41;;
2&#58;Inc&#40;newPoint.x&#41;;
3&#58;Dec&#40;newPoint.y&#41;;
4&#58;Inc&#40;newPoint.y&#41;;
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:
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. ## 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. ## A* pathfinding example !

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

6. ## A *

What is the max size of the nodes in X and Y Whit this technique?

7. ## 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.

8. ## A* pathfinding example !

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.

9. ## 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.

10. ## A* pathfinding example !

interesting stuff, is it okay to use in any apps or a under specific license?

Page 1 of 9 123 ... Last

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•