Skip to content

Instantly share code, notes, and snippets.

@MartinHarding
Created November 29, 2017 03:42
Show Gist options
  • Save MartinHarding/7cbc722a282fb49f3f85935182158f3c to your computer and use it in GitHub Desktop.
Save MartinHarding/7cbc722a282fb49f3f85935182158f3c to your computer and use it in GitHub Desktop.
from pathfinding.core.diagonal_movement import DiagonalMovement
from pathfinding.core.grid import Grid
from pathfinding.finder.a_star import AStarFinder
matrix = [
[0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
[1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1],
[0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0],
[0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0],
[0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0],
[0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0],
[0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0],
[0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0],
[0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0],
[0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0],
[0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0]
]
grid = Grid(matrix=matrix)
start = grid.node(0, 0)
end = grid.node(4, 10)
finder = AStarFinder(diagonal_movement=DiagonalMovement.never)
path, runs = finder.find_path(start, end, grid)
print('operations:', runs, 'path length:', len(path))
print(grid.grid_str(path=path, start=start, end=end))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment