Take the 2-minute tour ×

Can we get people to post code of simple, optimized implementations of the A* pathfinding algorithm, in every single language?

This is mostly for fun and to play with what stackoverflow itself is capable of... although I actually am interested in getting an ActionScript 3 version of this.

But the idea is that this "Question" will continue to be updated eternally into the future, even as different programming languages are created!

I don't know of any other place online where you can see pseudocode "translated" into many (much less every) different language. Seems like it's a worthwhile resource, and while not necessarily what this site was designed for, there's no harm in trying it out and seeing if it turns out to be a worthwhile thing that stackoverflow could be used for!

share|improve this question
Would probably be better if you gave more ground rules such as a "test" maze/obstacle field. Ideally each implementation would find the same route or a very common short-list of possible solutions! –  Ray Hayes Sep 17 '08 at 16:35
I suggest a community wiki. –  strager Jan 27 '09 at 2:04
@Ray Hayes, Maybe not the same route (as there can be multiple routes to the same goal), but the same length route. –  strager Jan 27 '09 at 2:05
SPOJ and its spin-off products/sites feature a way to compile code from many different languages online. Maybe you can make a problem there and people can post testable and compilable code. –  ziggystar Nov 7 '10 at 18:22
The terms "optimized code" and "simple code" are mutually exclusive. –  ziggystar Nov 7 '10 at 18:22
show 1 more comment

9 Answers

Here is a JavaScript implementation, along with source code and an online demo I did as a hobby/research project.

It is very simple, but you can change some of the params (grid size, # of walls, debugging info on/off). It will show you the calculated f(x), g(x), and h(x) values for each node that is inspected.

The demo page implementation uses jQuery.

share|improve this answer
Note this is jquery reliant. –  Dave Dec 29 '12 at 5:51
The demo is reliant on jQuery, the plugin itself isn't. I updated the answer to point to the non-dependant part more prominently –  Brian Grinstead Jan 2 '13 at 17:03
add comment

Here's a C++ implementation. It's fairly well tested by now, and used in commercial video games and various AI projects.


And there's a tutorial, which I actually wrote first:


share|improve this answer
add comment

Here's a C# implementation done by one of the people who build the language.

share|improve this answer
add comment

Source codes and demos in different programming languages:

List of demo's for each language:

C++: 1
Java: 3
Processing: 1
Actionscript 3 (Flash): 4
Flex (Flash): 1
Javascript: 6
C#: 1
Ruby: 1
Prolog: 1
Unity: 1
Lua: 1

Pathfinding Demo in different languages

Enjoy :)

share|improve this answer
add comment

A VB6 implementation.


This is particularly useful because you can step through the process and get a good understanding of how the algorithm works. This can be quite valuable when converting the algorithm to another language.

share|improve this answer
This answer suffers from link rot as got 404! –  t0mm13b Jan 2 '13 at 23:26
add comment

An AS 3 example... http://www.dauntless.be/astar/

share|improve this answer
add comment

A Clojure implementation, heavily based on an example given in PAIP.

share|improve this answer
add comment

Not an implementation, but I found http://theory.stanford.edu/~amitp/GameProgramming/AStarComparison.html to be a particularly clear explanation of the algorithm. Has pseudocode that makes it very easy to implement, along with an extended review of various data structures that can be used for implementing the open & closed sets, a discussion of different heuristics that are applicable in different situations, modifications to heuristics to get specific behaviours (e.g. getting approximations of straight lines in systems that only support limited angles of movement), common pitfalls (e.g. using a heuristic with a different scale to the actual movement costs), and some optimizations (e.g. working with regions of uniform cost rather than a grid).

share|improve this answer
add comment

An optimized Java implementation is available in GraphHopper.

share|improve this answer
Linky suffers from rot! 404! :D –  t0mm13b Jan 2 '13 at 23:29
fixed to point to new graphhopper repository –  Karussell Jan 4 '13 at 13:56
add comment

Your Answer


