A* - poprawa błędów
This commit is contained in:
parent
3188f3e7f6
commit
84e66ab30f
24
tiles.py
24
tiles.py
@ -314,7 +314,6 @@ def astar(map, start, end):
|
|||||||
|
|
||||||
open_list.pop(current_index)
|
open_list.pop(current_index)
|
||||||
closed_list.append(current_tile)
|
closed_list.append(current_tile)
|
||||||
|
|
||||||
if current_tile == end_tile:
|
if current_tile == end_tile:
|
||||||
path = []
|
path = []
|
||||||
current = current_tile
|
current = current_tile
|
||||||
@ -330,21 +329,20 @@ def astar(map, start, end):
|
|||||||
continue
|
continue
|
||||||
new_node = Tile(current_tile, tile_position)
|
new_node = Tile(current_tile, tile_position)
|
||||||
children.append(new_node)
|
children.append(new_node)
|
||||||
|
|
||||||
for child in children:
|
for child in children:
|
||||||
|
skip = False
|
||||||
for closed_child in closed_list:
|
for closed_child in closed_list:
|
||||||
if child == closed_child:
|
if child == closed_child:
|
||||||
continue
|
skip = True
|
||||||
|
if skip is False:
|
||||||
child.g = current_tile.g + map[child.position[0]][child.position[1]]
|
child.g = map[child.position[0]][child.position[1]]
|
||||||
child.h = ((child.position[0] - end_tile.position[0]) ** 2) + (
|
child.h = np.absolute(child.position[0] - end_tile.position[0]) + np.absolute(child.position[1] - end_tile.position[1])
|
||||||
(child.position[1] - end_tile.position[1]) ** 2)
|
child.f = child.g + child.h
|
||||||
child.f = child.g + child.h
|
for open_node in open_list:
|
||||||
|
if child == open_node and child.g > open_node.g:
|
||||||
for open_node in open_list:
|
continue
|
||||||
if child == open_node and child.g > open_node.g:
|
open_list.append(child)
|
||||||
continue
|
|
||||||
open_list.append(child)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
map = Map()
|
map = Map()
|
||||||
|
Loading…
Reference in New Issue
Block a user