Created
November 29, 2017 03:42
-
-
Save MartinHarding/7cbc722a282fb49f3f85935182158f3c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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