pub fn astar_path(
    start_node: (i32, i32),
    nodes: HashMap<(i32, i32), f32>,
    end_node: (i32, i32),
    min_column: i32,
    max_column: i32,
    min_row: i32,
    max_row: i32,
    orientation: HexOrientation
) -> Vec<(i32, i32)>
Expand description

From a starting node calculate the most efficient path to the end node

The nodes input is structured such:

  • The keys are tuples of the nodes position in a grid with the origin being based on the bottom left, (x,y)
  • The layout builds a square/rectangular like grid space
  • The values are the complexity of traversing a particular node

For a grid of perfectly flush hexagons the distance from the centre to the midpoint of an edge is the same in all directions. This module is akin to idea that you wake up in a ‘hexagon world’ and you can only move from the centre of one hexagon to another in a straight line, but while distance is static you’ll find that as you cross the boundary of one hexagon into another you’ll suddenly be sprinting instead of slow-motion walking.

min_column, max_column, min_row and max_row indicate the boundary of the hexagon space and are exclusive. For instance with a square grid space where the origin (bottom left) is (0, 0) and the top most right node is positioned at (3, 3):

                 _________               _________
                /         \             /         \
               /           \           /           \
     _________/    (1,3)    \_________/    (3,3)    \
    /         \             /         \             /
   /           \           /           \           /
  /    (0,3)    \_________/    (2,3)    \_________/
  \             /         \             /         \
   \           /           \           /           \
    \_________/    (1,2)    \_________/    (3,2)    \
    /         \             /         \             /
   /           \    C:4    /           \           /
  /    (0,2)    \_________/    (2,2)    \_________/
  \             /         \             /         \
   \           /           \           /           \
    \_________/    (1,1)    \_________/    (3,1)    \
    /         \             /         \             /
   /           \           /           \           /
  /    (0,1)    \_________/    (2,1)    \_________/
  \             /         \             /         \
   \           /           \           /           \
    \_________/    (1,0)    \_________/    (3,0)    \
    /         \             /         \             /
   /           \           /           \           /
  /    (0,0)    \_________/    (2,0)    \_________/
  \             /         \            /
   \           /           \           /
    \_________/             \_________/

Our min_column and min_row will be equal to -1 and our max_column and max_row will both equal 4.

orientation refers to your hexagonal grid layout.

The return Vec contains a number of tuples which for 0..n show the best path to take