Need Code for A star path finding

Started by
15 comments, last by mawaliya 13 years ago
Hi,

I was trying to work out the A* alghoritm not too long ago myself.

Please check this thread:


http://www.gamedev.net/community/forums/topic.asp?topic_id=420517


At my last post I attached something I invented that day. It's far from perfect as it lacks saving final path, 'no path vavailable' check, no boundaries check etc. but it is working fine.

Hope that helps a bit
Advertisement
Quote:Original post by Altaf
Thanks a lot guys....


They did actually give you quite a bit of help, you know. Programming is not about copy-pasting tutorials and piecing a game together. It's about understanding algorithms and being able to code them yourself. You've gotten to the point in your game (if you're looking for A* code) where you can't copy-paste tutorials anymore. Everything from this point forward is going to be writing code that works with your engine. So... read the algorithm descriptions and write it. It'll take you a few days, but it's really not that hard.

And as mentioned DirectX is zero-percent related to A*. DirectX is rendering. A* is game-logic. Game logic should never be dependant on rendering. i.e. you can write A* code for a game that uses DirectX and then switch the engine to openGL and not have to touch a single line of code in your A* code.

The format of the A* grid, for instance, is going to be dependent on how your level geometry works.

Anyway, did you have questions specifically about how the A* algorithm works? Are there parts you don't understand that are preventing you from coding it?

-me
I wrote a working code. My problem is the returned path is correct but not the shortest path. I guess my parent list has a problem.
Or your heuristic is not correct, if your heuristic is too high or too low you won't get the best results. If you always set your heuristic to 0, do you get the shortest path?

Try not to compute your heuristic, so that the A* formula F = G + H is F = G, that way your algorithm will become Djisktra's, it will search alot more nodes, but it should give you the shortest path. If it doesn't, check your parents, etc.. if you do get the shortest path.. make sure your heuristic is good.
http://www.cs.ualberta.ca/~games/pathfind/libpathfind/0.1.0/doc/index.html

This is exactly what you need. I use it and it's great!
Thanks a lot .....
Developing Games in Java by Laurence Vanhelswue will definitely help you getting to learn many AI techniques.
Also I will create a C++ version of A Star path finding on my site http://www.01fes.com/

This topic is closed to new replies.

Advertisement