diff --git a/tiles.py b/tiles.py index f806b4a..0564140 100644 --- a/tiles.py +++ b/tiles.py @@ -314,7 +314,6 @@ def astar(map, start, end): open_list.pop(current_index) closed_list.append(current_tile) - if current_tile == end_tile: path = [] current = current_tile @@ -330,21 +329,20 @@ def astar(map, start, end): continue new_node = Tile(current_tile, tile_position) children.append(new_node) + for child in children: + skip = False for closed_child in closed_list: if child == closed_child: - continue - - child.g = current_tile.g + map[child.position[0]][child.position[1]] - child.h = ((child.position[0] - end_tile.position[0]) ** 2) + ( - (child.position[1] - end_tile.position[1]) ** 2) - child.f = child.g + child.h - - for open_node in open_list: - if child == open_node and child.g > open_node.g: - continue - open_list.append(child) - + skip = True + if skip is False: + child.g = map[child.position[0]][child.position[1]] + child.h = np.absolute(child.position[0] - end_tile.position[0]) + np.absolute(child.position[1] - end_tile.position[1]) + child.f = child.g + child.h + for open_node in open_list: + if child == open_node and child.g > open_node.g: + continue + open_list.append(child) map = Map()