Skip to content

Commit 73a672b

Browse files
committed
if the path is not found
1 parent c2869c6 commit 73a672b

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/bfs.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,15 @@ def bfs(win, startEnd, walls):
4545
q.append((start_x + row[k], start_y + col[k], dist + 1, add + move[k]))
4646
win.write('@', end_x, end_y)
4747

48-
# find path
49-
start_x, start_y = startEnd[0]
50-
for i in range(len(add)):
51-
index = move.index(add[i])
52-
start_x, start_y = start_x + row[index], start_y + col[index]
53-
win.write('+', start_x, start_y, fgcolor='red')
54-
time.sleep(0.02)
55-
win.write('@', end_x, end_y)
56-
5748
if min_dist != sys.maxsize:
49+
# find path
50+
start_x, start_y = startEnd[0]
51+
for i in range(len(add)):
52+
index = move.index(add[i])
53+
start_x, start_y = start_x + row[index], start_y + col[index]
54+
win.write('+', start_x, start_y, fgcolor='red')
55+
time.sleep(0.02)
56+
win.write('@', end_x, end_y)
5857
win.write(f"The shortest path from source to destination has length {min_dist}", 1, 1)
5958
else:
6059
win.write("Destination can't be reached from a given source", 1, 1)

0 commit comments

Comments
 (0)