質問編集履歴
1
コードの書き方
test
CHANGED
File without changes
|
test
CHANGED
@@ -176,6 +176,52 @@
|
|
176
176
|
|
177
177
|
''' 探索中の座標からゴールまでの最短距離のスコア '''
|
178
178
|
|
179
|
-
return ((pos[0] - goal[0]) ** 2 + (pos[1] - goal[1]) ** 2) ** 0
|
179
|
+
return ((pos[0] - goal[0]) ** 2 + (pos[1] - goal[1]) ** 2) ** 0.5
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
def distance(path):
|
184
|
+
|
185
|
+
''' スタートから探索中の座標までの距離のスコア '''
|
186
|
+
|
187
|
+
return len(path)
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
def render_path(path):
|
192
|
+
|
193
|
+
''' 結果の出力 '''
|
194
|
+
|
195
|
+
buf = [[ch for ch in l] for l in dungeon]
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
for pos in path[1:-1]:
|
200
|
+
|
201
|
+
buf[pos[0]][pos[1]] = "*"
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
buf[path[0][0]][path[0][1]] = "s"
|
206
|
+
|
207
|
+
buf[path[-1][0]][path[-1][1]] = "g"
|
208
|
+
|
209
|
+
return ["".join(l) for l in buf]
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
path = astar(init, goal)
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
if len(path) > 0:
|
218
|
+
|
219
|
+
print("\n".join(render_path(path)))
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
else:
|
224
|
+
|
225
|
+
print('通ることができません')
|
180
226
|
|
181
227
|
```
|