Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commited10edc

Browse files
committed
Fixes on pathfinding lib
1 parent0e1b91f commited10edc

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 ifthegrid was converted
90+
:return:A dictionnary oftheitems found
9191
"""
9292
items_found= {}
9393
y=0
@@ -102,13 +102,13 @@ def grid_search(self, grid, items):
102102

103103
returnitems_found
104104

105-
defvertices_to_grid(self,mark_coords=[],wall="#"):
105+
defvertices_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-
:paramlist mark_coords: List ofcoordonates to mark
111+
:paramdict mark_coords: List ofcoordinates 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-
ifisinstance(next(iter(self.vertices)),dict):
121-
vertices=self.vertices.keys()
122-
else:
123-
vertices=self.vertices
124-
125120
foryinrange(min_y,max_y-1,-1):
126121
forxinrange(min_x,max_x+1):
127-
ifx+y*1jinmark_coords:
128-
grid+="X"
129-
elifx+y*1jinvertices:
130-
grid+="."
131-
else:
132-
grid+=wall
122+
try:
123+
grid+=mark_coords[x+y*1j]
124+
exceptKeyError:
125+
ifx+y*1jinmark_coords:
126+
grid+="X"
127+
else:
128+
try:
129+
grid+=self.vertices.get(x+y*1j,wall)
130+
exceptAttributeError:
131+
ifx+y*1jinself.vertices:
132+
grid+="."
133+
else:
134+
grid+=wall
133135
grid+="\n"
134136

135137
returngrid
@@ -160,7 +162,7 @@ def add_walls(self, vertices):
160162
forvertexinvertices:
161163
ifvertexinself.edges:
162164
delself.edges[vertex]
163-
delself.vertices[vertex]
165+
self.vertices.remove(vertex)
164166
changed=True
165167

166168
self.edges= {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp