-
Notifications
You must be signed in to change notification settings - Fork 0
/
BFS.py
38 lines (35 loc) · 1.15 KB
/
BFS.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/python3
'''
Written by Karim (ksaadDE) - 03/2021
Studying & Research purposes, no practical or commerical use intended!
'''
import pygame as pg
import os, sys, time
from Colors import Colors
class BFS:
def __init__(self, graph):
self.graph = graph
self.visited = []
def run(self, screen=False):
self.visited = []
nodeID = 0
connectedNodeID = 0
for node in self.graph.getNodes():
nodeID += 1
if screen != False:
for conNode in node.getConnectedNodes():
connectedNodeID += 1
time.sleep(0.25)
startPos = node.getPos()
endPos = conNode.getPos()
conNode.color = Colors.BLUE
conNode.draw(screen)
self.visited.append(conNode)
pg.draw.line(screen, Colors.WHITE, startPos, endPos, 4)
pg.display.update()
time.sleep(2)
for node in self.visited:
node.color = Colors.RED
node.draw(screen)
pg.display.update()
self.visited = []