Skip to content

Commit 53e3385

Browse files
committed
Updated pathfinding to calculate groups
1 parent eff324a commit 53e3385

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

2018/pathfinding.py

+19
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,25 @@ def add_walls(self, vertices):
172172

173173
return changed
174174

175+
def dfs_groups(self):
176+
"""
177+
Groups vertices based on depth-first search
178+
179+
:return: A list of groups
180+
"""
181+
groups = []
182+
unvisited = self.vertices.copy()
183+
184+
while unvisited:
185+
start = unvisited.pop()
186+
self.depth_first_search(start)
187+
188+
newly_visited = list(self.distance_from_start.keys())
189+
unvisited = [x for x in unvisited if x not in newly_visited]
190+
groups.append(newly_visited)
191+
192+
return groups
193+
175194
def depth_first_search(self, start, end=None):
176195
"""
177196
Performs a depth-first search based on a start node

0 commit comments

Comments
 (0)