A* - poprawa błędów
This commit is contained in:
parent
3188f3e7f6
commit
84e66ab30f
14
tiles.py
14
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,23 +329,22 @@ 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)
|
||||
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()
|
||||
waiter = Waiter([32, 32])
|
||||
tables = []
|
||||
|
Loading…
Reference in New Issue
Block a user