def generateGraphFromGrid(self): edge = 1 for i in range(len(self.cells)): row = self.cells[i] for j in range(len(row)): node = Node((i, j)) for x in [-1, 0, 1]: for y in [-1, 0, 1]: if x == 0 and y == 0: continue if i + x >= 0 and j + y >= 0 and i + x < self.x_dim and j + y < self.y_dim: node.addNeighbor((i + x, j + y)) self.graph[(i, j)] = node
from search import DFS, BFS from queueG import Queue from graph import Node root = Node(1) b = Node(3) c = Node(4) d = Node(10) e = Node(11) root.addNeighbor(b) # There's a better way b.addNeighbor(root) b.addNeighbor(e) e.addNeighbor(b) root.addNeighbor(c) c.addNeighbor(root) c.addNeighbor(d) d.addNeighbor(c) #print("DFS: ") #DFS(root) print("BFS: ") BFS(root)