Skip to content

Commit d2d84da

Browse files
committed
add dfs
1 parent 0c321b8 commit d2d84da

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

gifs/dfs.gif

84.9 KB
Loading

src/dfs.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ def dfs(win, startEnd, walls):
3535
min_dist = sys.maxsize
3636

3737
while q:
38+
for i in range(len(add)):
39+
for event in pygame.event.get():
40+
# Quit if the user closes the window.
41+
if event.type == pygame.QUIT:
42+
return
3843
(start_x, start_y, dist, add) = q[-1]
3944
if start_x == end_x and start_y == end_y:
4045
min_dist = dist
@@ -45,7 +50,7 @@ def dfs(win, startEnd, walls):
4550
visited[start_x + row[k]][start_y + col[k]] = True
4651

4752
win.write('*', start_x + row[k], start_y + col[k], fgcolor='green')
48-
pygame.time.wait(3)
53+
pygame.time.wait(5)
4954
q.append((start_x + row[k], start_y + col[k], dist + 1, add + move[k]))
5055
found = True
5156
break
@@ -64,7 +69,7 @@ def dfs(win, startEnd, walls):
6469
index = move.index(add[i])
6570
start_x, start_y = start_x + row[index], start_y + col[index]
6671
win.write('+', start_x, start_y, fgcolor='red')
67-
pygame.time.wait(5)
72+
pygame.time.wait(10)
6873
win.write('@', end_x, end_y)
6974
win.write(f"The path from source to destination has length {min_dist}", 1, 1)
7075
else:

0 commit comments

Comments
 (0)