@@ -51,6 +51,7 @@ def grid_to_vertices (self, grid, diagonals_allowed = False, wall = '#'):
51
51
52
52
:param string grid: The grid to convert
53
53
:param Boolean diagonals_allowed: Whether diagonal movement is allowed
54
+ :param str wall: What is considered as a wall
54
55
:return: True if the grid was converted
55
56
"""
56
57
self .vertices = []
@@ -77,6 +78,28 @@ def grid_to_vertices (self, grid, diagonals_allowed = False, wall = '#'):
77
78
78
79
return True
79
80
81
+ def grid_search (self , grid , items ):
82
+ """
83
+ Searches the grid for some items
84
+
85
+ :param string grid: The grid to convert
86
+ :param Boolean items: Whether diagonal movement is allowed
87
+ :return: True if the grid was converted
88
+ """
89
+ items_found = {}
90
+ y = 0
91
+
92
+ for line in grid .splitlines ():
93
+ for x in range (len (line )):
94
+ if line [x ] in items :
95
+ if line [x ] in items_found :
96
+ items_found [line [x ]].append ((x , y ))
97
+ else :
98
+ items_found [line [x ]] = [(x , y )]
99
+ y += 1
100
+
101
+ return items_found
102
+
80
103
def vertices_to_grid (self , mark_coords = [], wall = '#' ):
81
104
"""
82
105
Converts a set of coordinates to a text
@@ -221,9 +244,7 @@ def topological_sort_alphabetical (self):
221
244
not_visited .remove (next_node )
222
245
current_distance += 1
223
246
edges = {x :edges [x ] for x in edges if x in not_visited }
224
- print (not_visited , edges )
225
247
next_node = sorted (x for x in not_visited if not x in sum (edges .values (), []))
226
- print (len (next_node ), next_node )
227
248
if len (next_node ):
228
249
next_node = next_node [0 ]
229
250
0 commit comments