I have the code below but the output doesn't give me co-ordinates, just [<GridNode(0:0 0x106fdadb0)> as an example, not (0,0). How do I just print co-ordinates?
from pathfinding.core.grid import Grid
from pathfinding.finder.a_star import AStarFinder
from pathfinding.core.diagonal_movement import DiagonalMovement
matrix = [
[1, 1, 1, 1, 1, 1],
[1, 0, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1]
]
grid = Grid(matrix= matrix)
start = grid.node(0,0) # start in top left hand corner
end = grid.node(5,2) # end in bottom right hand corner
finder = AStarFinder(diagonal_movement=DiagonalMovement.always)
path, runs = finder.find_path(start, end, grid) # returns two things
print(path)
print(runs) # ran through 17 times to find the shortest path
You should iterate through the path list and convert each GridNode object to its corresponding coordinates. See the code below:
Output: