GithubHelp home page GithubHelp logo

blondeburrito / hexagonal_pathfinding_astar Goto Github PK

View Code? Open in Web Editor NEW
19.0 1.0 1.0 116 KB

An implementation of the A-Star pathfinding algorithm tailored for traversing a bespoke collection of weighted hexagons. It's intended to calculate the most optimal path to a target hexagon where you are traversing from the centre of one hexagon to the next along a line orthogonal to a hexagon edge

License: Other

Rust 100.00%
rust pathfinding pathfinding-algorithm a-star a-star-algorithm

hexagonal_pathfinding_astar's People

Contributors

blondeburrito avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

geotyper

hexagonal_pathfinding_astar's Issues

Edge case: no path can be found

In the event that two distinct hexagon grids are merged into the same data set (think of two islands separated by an ocean where the ocean isn't made of traversable hexagons) and the start point is in one set and the end point is in the other set then no path will be found as there are no neighbours bridging the two sets. It will either panic or get stuck in an infinite loop.

This can be resolved by amending the end of the A-Star calculation to check the size of the queue of nodes to be processed. If queue.len() == 0 then it means all nodes have been exhausted and there is no path.

Rather than returning a Vec to the user an Option should instead be returned. Where None indicates that no path could be found and Some will contain a Vec of the best path.

Include other hexagon orientations

Currently two Offset hexagon orientations have been included:

  • flat top, odd columns shifted up
             _______
            /       \
    _______/  (1,1)  \_______
   /       \         /       \
  /  (0,1)  \_______/  (2,1)  \
  \         /       \         /
   \_______/  (1,0)  \_______/
   /       \         /       \
  /  (0,0)  \_______/  (2,0)  \
  \         /       \         /
   \_______/         \_______/
  • flat top , odd columns shifted down
    _______           _______
   /       \         /       \
  /  (0,1)  \_______/  (2,1)  \
  \         /       \         /
   \_______/  (1,1)  \_______/
   /       \         /       \
  /  (0,0)  \_______/  (2,0)  \
  \         /       \         /
   \_______/  (1,0)  \_______/
           \         /
            \_______/

There are another two styles to creating a hexagon grid:

  • Pointy top, odd columns shifted down
  • Pointy top, odd column shifted up

Which should be codified into fn expand_neighrbor_nodes() so paths in pointy-topped grids can be found

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.