From 84e66ab30fe6459c3ee2653aad7aa8d7681fa4bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kinder?= Date: Thu, 28 Apr 2022 14:42:32 +0200 Subject: [PATCH] =?UTF-8?q?A*=20-=20poprawa=20b=C5=82=C4=99d=C3=B3w?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tiles.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) 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()