Pathfinding library using the astar algorithm, supports manhhaten and euclidean distance heuristics.
Add this line to your application's Gemfile:
gem 'astar'And then execute:
bundleOr install it yourself as:
gem install astarMake sure you have an object that responds to methods x,y and walkable_neighbours
class Tile
attr_reader :x, :y
#returns the surrounding tiles that are walkable
def walkable_neighbours
end
endPass in your to and from tiles including the heuristic
Astar::FindPath.from(tile1).to(tile, Astar::ManhattenDistance)
Astar::FindPath.from(tile1).to(tile, Astar::EuclideanDistance)The specs also have an example of how to use the lib.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request