How would i implement an A star algorithm for a game that i'm making on the android in java? i'm looking for a pre-made A star API in java with classes and methods to call. i don't want to have to code from scratch.

  • \$\begingroup\$ Not sure why this got a down-vote, it's a pretty straightfoward question to answer. Anyway, while I'm sure there are plenty of existing A* implementations done in Java, I implemented it pretty easily just by following along with this explanation policyalmanac.org/games/aStarTutorial.htm \$\endgroup\$ – jhocking Feb 5 '12 at 20:13
  • \$\begingroup\$ Incidentally, I did it in ActionScript 3, which may be easy to port to Java newarteest.com/flash/astar.html \$\endgroup\$ – jhocking Feb 5 '12 at 20:15
  • \$\begingroup\$ thanks i'll read over the articles, crack my knuckles, and get it done ! \$\endgroup\$ – kdavis8 Feb 6 '12 at 4:29

Like others have commented, it might be easier (not to mention fun) to write your own implementation of A* (use the link jhocking provided, I learned it from there, and highly recommend it - http://www.policyalmanac.org/games/aStarTutorial.htm).

However if you definitely want a pre-existing library, here are some alternatives: - http://www.stackframe.com/software/PathFinder (scroll to the bottom for the download) - http://www.ludumdare.com/compo/2011/12/16/java-pathfinding-library/ (probably not an ideal solution, but it would help you in writing your own)

But the one I like best is Critter AI, which is a port of Recast for .NET and Java. The one for Java is more intended for study, but is still awesome. http://www.critterai.org/

Good luck! :)

| improve this answer | |
  • \$\begingroup\$ thanks, the reason i want a pre existing api is because, as my game gets heavy,and i am implementing my own algorithm,im sure it will become error prone ; where as code that has already been implemented various times by others is well, go to go. \$\endgroup\$ – kdavis8 Feb 6 '12 at 4:33
  • \$\begingroup\$ yeah i agree with you on that! - When i was learning about pathfinding I wrote my own simple class. But now that im working on a pretty big project, its nice to use a well-known and tested library like recast. Documentation + help from others is so good \$\endgroup\$ – Aralox Feb 6 '12 at 11:15
  • \$\begingroup\$ The biggest problem I find when simply posting links which is the situation with this post in particular is that it becomes useless once those links are no longer available. The provided link from policyalmanac.org is dead. \$\endgroup\$ – rbaleksandar Oct 24 '15 at 11:08

Ignore, if you are done.

I have implemented "8-puzzle" using pure A* implementation. You can follow the same searching pattern for your game.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.