Maze Solving with DFS

def visit(u):
    for vert in u.adj:
        if vert.get_color() == "white":
            vert.prev = u
            path = visit(vert)
            if path != None:
                return path
        elif vert.get_color() == "blue":
            vert.prev = u
            return vert

def find_path(start_node):
    start_node.prev = None        
    goal = visit(start_node)
    visited = []
    cur = goal
    while cur != None:
        visited.insert(0, cur)
        cur = cur.prev
    return visited #Placeholder return to avoid errors
  • This lab was heavily inspired by Nathan Taylor's University of Minnesota CSCI 4041 assignment.