Skip to content

Commit 3b4a38a

Browse files
committed
Pathfinding: fixed some bugs
1 parent cbdba8d commit 3b4a38a

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

2019/pathfinding.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,9 @@ class NegativeWeightCycle(Exception):
1212

1313

1414
class Graph:
15-
vertices = []
16-
edges = {}
17-
distance_from_start = {}
18-
came_from = {}
19-
2015
def __init__(self, vertices=[], edges={}):
21-
self.vertices = vertices
22-
self.edges = edges
16+
self.vertices = vertices.copy()
17+
self.edges = edges.copy()
2318

2419
def neighbors(self, vertex):
2520
"""
@@ -57,6 +52,7 @@ def grid_to_vertices(self, grid, diagonals_allowed=False, wall="#"):
5752
:return: True if the grid was converted
5853
"""
5954
self.vertices = []
55+
self.edges = {}
6056
y = 0
6157

6258
for line in grid.splitlines():
@@ -151,15 +147,15 @@ def add_traps(self, vertices):
151147

152148
return changed
153149

154-
def add_walls(self, vertices):
150+
def add_walls(self, walls):
155151
"""
156152
Adds walls - useful for modification of map
157153
158154
:param Any vertex: The vertices to consider
159155
:return: True if successful, False if no vertex found
160156
"""
161157
changed = False
162-
for vertex in vertices:
158+
for vertex in walls:
163159
if vertex in self.edges:
164160
del self.edges[vertex]
165161
if isinstance(self.vertices, list):
@@ -169,7 +165,7 @@ def add_walls(self, vertices):
169165
changed = True
170166

171167
self.edges = {
172-
source: [target for target in self.edges[source] if target not in vertices]
168+
source: [target for target in self.edges[source] if target not in walls]
173169
for source in self.edges
174170
}
175171

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy