This code is an efficient implementation in C++ and C# of the A* algorithm, designed to be used from high performance realtime applications (video games) and with an optional fast memory allocation scheme.
It accompanies this A* tutorial: http://www.heyes-jones.com/astar.html
- @justinhj Original code and tutorial
- @ScaryG C# port
- @Rasoul for submitting the path to Bucharest. Sample from Artificial Intelligence: A Modern Approach
- @sergiosota For fixing a number of issues related to memory management
This software is released under the MIT License, see license.txt
This software has been used in AAA video games and is well tested in the wild. Please let me know if you use this code in you games, studies or hobby projects.
If you feel the need to pay money for this code, it is not required by the license, but you could contribute to Unicef, a charity which helps children worldwide, http://www.unicef.org/ that would be awesome.
If you wish to be added to the list of known products using the code please contact me.
Using this code:
- Gun, Activision
- Company of Heroes and Company of Heroes Online, Relic Entertainment
- Angel Engine, a game prototyping engine http://code.google.com/p/angel-engine/
- War of Sonria, a strategy war game on PSP and Playstation 3 by Playground Squad
- Lighthouses AI contest https://github.com/marcan/lighthouses_aicontest
Enter the cpp folder and run make
This implementation is intended to be simple to read yet fairly efficient. To build it you can compile, with any recent C++ compiler, the following files :
For 8-puzzle solver
- optionally fsa.h
8puzzle with no arguments runs with one of the boards in the cpp file, you can select the one you want changing the conditional compiliation instructions. Or if you prefer pass in a board on the command line using digits for the tile positions, where zero is the space. The board runs from left to right, each row at a time:
For path finder
- optionally fsa.h
pathfind has no arguments. You can edit the simple map in pathfind.cpp and the start and goal co-ordinates to experiement with the pathfinder.
Fixed size allocator notes: As mentioned briefly in the tutorial you can enable and disable the faster memory allocation. This allocates a fixed size block of memory, so you have to specify this size with the astar constructor. You need to enlarge it if you hit an out of memory assert during the search.
Microsoft Visual C++ : Confirmed working with version 8.0.50727 with some deprecation warnings I'm going to leave the deprecation warnings in so that it still works cleanly with GCC. TODO Make a non-deprecated compliant version using compiler checking
Compiled with: Apple LLVM version 6.0 (clang-600.0.51) (based on LLVM 3.5svn)
Please let me know if it doesn't work for you and I will try to help. I cannot help if you are using an old compiler such as Turbo C++, since I update the code to meet Ansi Standard C++ as required.