Skip to content

Commit ed10edc

Browse files
committed
Fixes on pathfinding lib
1 parent 0e1b91f commit ed10edc

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

2018/pathfinding.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def grid_search(self, grid, items):
8787
8888
:param string grid: The grid in which to search
8989
:param Boolean items: The items to search
90-
:return: True if the grid was converted
90+
:return: A dictionnary of the items found
9191
"""
9292
items_found = {}
9393
y = 0
@@ -102,13 +102,13 @@ def grid_search(self, grid, items):
102102

103103
return items_found
104104

105-
def vertices_to_grid(self, mark_coords=[], wall="#"):
105+
def vertices_to_grid(self, mark_coords={}, wall="#"):
106106
"""
107107
Converts a set of coordinates to a text
108108
109109
The text will be separated by newline characters
110110
111-
:param list mark_coords: List of coordonates to mark
111+
:param dict mark_coords: List of coordinates to mark, with letter to use
112112
:param string wall: Which character to use as walls
113113
:return: True if the grid was converted
114114
"""
@@ -117,19 +117,21 @@ def vertices_to_grid(self, mark_coords=[], wall="#"):
117117
min_y, max_y = int(max_imag(self.vertices)), int(min_imag(self.vertices))
118118
min_x, max_x = int(min_real(self.vertices)), int(max_real(self.vertices))
119119

120-
if isinstance(next(iter(self.vertices)), dict):
121-
vertices = self.vertices.keys()
122-
else:
123-
vertices = self.vertices
124-
125120
for y in range(min_y, max_y - 1, -1):
126121
for x in range(min_x, max_x + 1):
127-
if x + y * 1j in mark_coords:
128-
grid += "X"
129-
elif x + y * 1j in vertices:
130-
grid += "."
131-
else:
132-
grid += wall
122+
try:
123+
grid += mark_coords[x + y * 1j]
124+
except KeyError:
125+
if x + y * 1j in mark_coords:
126+
grid += "X"
127+
else:
128+
try:
129+
grid += self.vertices.get(x + y * 1j, wall)
130+
except AttributeError:
131+
if x + y * 1j in self.vertices:
132+
grid += "."
133+
else:
134+
grid += wall
133135
grid += "\n"
134136

135137
return grid
@@ -160,7 +162,7 @@ def add_walls(self, vertices):
160162
for vertex in vertices:
161163
if vertex in self.edges:
162164
del self.edges[vertex]
163-
del self.vertices[vertex]
165+
self.vertices.remove(vertex)
164166
changed = True
165167

166168
self.edges = {

0 commit comments

Comments
 (0)