@@ -51,6 +51,7 @@ def grid_to_vertices (self, grid, diagonals_allowed = False, wall = '#'):
5151
5252 :param string grid: The grid to convert
5353 :param Boolean diagonals_allowed: Whether diagonal movement is allowed
54+ :param str wall: What is considered as a wall
5455 :return: True if the grid was converted
5556 """
5657 self .vertices = []
@@ -77,6 +78,28 @@ def grid_to_vertices (self, grid, diagonals_allowed = False, wall = '#'):
7778
7879 return True
7980
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+
80103 def vertices_to_grid (self , mark_coords = [], wall = '#' ):
81104 """
82105 Converts a set of coordinates to a text
@@ -221,9 +244,7 @@ def topological_sort_alphabetical (self):
221244 not_visited .remove (next_node )
222245 current_distance += 1
223246 edges = {x :edges [x ] for x in edges if x in not_visited }
224- print (not_visited , edges )
225247 next_node = sorted (x for x in not_visited if not x in sum (edges .values (), []))
226- print (len (next_node ), next_node )
227248 if len (next_node ):
228249 next_node = next_node [0 ]
229250
0 commit comments