Saturday, April 17, 2010

Pathfinding... what is it?

Path finding is extremely important for some game. Note the 'some' games. Well this is because games like 'Tetris' does not need path finding, nor does Twin Bee. Wha? You don't know what Twin Bee is? Go google... While some does not need it, others like C&C (Command and Conquer) can't work without it. What does this 'pathfinding' means. Let's put it this way. When playing all rts (real time strategy), clicking on a tank and clicking on a destination, you actually asked the computer to move the tank to that destination. It needs to calculate the road it's gonna use, which bridge is accesible, what rock is blocking, which humans the tank can mow over... you get the point don't you? And thus... that is pathfinding.

Basically an algorithm to calculate possible path from point A to B taking into account obstacles and some point even type of terrans terian... terry...

This is just a small article to tell you what it is, I am done. Go on... go away...
... it's over.

Ok.. since you decided to read on, I am gonna introduce you to some path finding algorithm. I am by no way gonna go detail into these algo but I am gonna direct you to some really nice readings about them.

A* (pronounced "A Star") is one of the famous ones... and it's most famous article here at http://www.policyalmanac.org/games/aStarTutorial.htm This article comes highly recommended as I tried and tried to understand for about 80 years but to no avail really gain some insight on it on the very first reading which got me interested to learn more. Oh ya... this is only good if you are dividing the play area into grids and want to find the nearest path from A to B. This one moves from one grid item to another and count and move to another and count and again and again. Yes it's quite computing intensive. You can see a sample here in flash... at http://pixelwelders.com/experiments/pathfinding/ if it's still there...

Dijkstra's algorithm is another one. This is a bit different as it spreads out from it's origin until it reaches it's target unlike A* which travels node to node (point to point). I found and old example dated year 2000 at http://www.electrotank.com/junk/mike/ai/precomputedPathTutorial.html. Basically Dijkstra is slower than A* for the obvoius reason of spreading out...

There are others out there but since we are going into Flixel with tilemap style gameplay I think the A* should suffice. Well no codes for today... just some reading... come on it's weekend... take some time out and play something duh...

No comments: