Working Dijkstra
This commit is contained in:
@ -101,7 +101,7 @@ class Player(FightingEntity):
|
||||
visited = []
|
||||
distances = {(self.y, self.x): 0}
|
||||
predecessors = {}
|
||||
while not queue.empty:
|
||||
while not queue.empty():
|
||||
dist, (y, x) = queue.get()
|
||||
if dist >= max_distance or (y,x) in visited:
|
||||
continue
|
||||
@ -110,14 +110,14 @@ class Player(FightingEntity):
|
||||
new_y, new_x = y + diff_y, x + diff_x
|
||||
if not 0 <= new_y < self.map.height or \
|
||||
not 0 <= new_x < self.map.width or \
|
||||
not self.map.tiles[y][x].can_walk():
|
||||
not self.map.tiles[new_y][new_x].can_walk():
|
||||
continue
|
||||
new_distance = dist + 1
|
||||
if not (new_y, new_x) in distances or \
|
||||
distances[(new_y, new_x)] > new_distance:
|
||||
predecessors[(new_y, new_x)] = (y, x)
|
||||
distances[(new_y, new_x)] = new_distance
|
||||
queue.put(new_distance, (new_y, new_x))
|
||||
queue.put((new_distance, (new_y, new_x)))
|
||||
self.paths = predecessors
|
||||
|
||||
def save_state(self) -> dict:
|
||||
|
Reference in New Issue
Block a user