def breadth_first_search():

    def search(nodes):

        def check(next_col, next_row, sub_nodes):
            if valid_cell(next_col, next_row):
                if (grid[(next_col, next_row)] == TERMINAL):
                    backtrack_node = node
                    while (backtrack_node is not None):
                        if (backtrack_node.get_parent() is not None):
                            grid[(backtrack_node.get_col(), backtrack_node.get_row())] = PATH
                            draw_cell(PATH_CELL_COLOR, backtrack_node.get_col(), backtrack_node.get_row())
                            pygame.display.update()
                        backtrack_node = backtrack_node.get_parent()
                    return True
                elif ((grid[(next_col, next_row)] != WALL) and (grid[(next_col, next_row)] != VISITED) and (grid[(next_col, next_row)] != INITIAL)):
                    grid[(next_col, next_row)] = VISITED
                    draw_cell(VISITED_CELL_COLOR, next_col, next_row)
                    pygame.display.update()
                    child_node = bfs_node(next_col, next_row, node)
                    sub_nodes.append(child_node)
            return False
        pygame.display.update()
        time.sleep(SMALL_SLEEP)
        sub_nodes = []
        for node in nodes:
            if check((node.get_col() - 1), node.get_row(), sub_nodes):
                return
            if check((node.get_col() + 1), node.get_row(), sub_nodes):
                return
            if check(node.get_col(), (node.get_row() + 1), sub_nodes):
                return
            if check(node.get_col(), (node.get_row() - 1), sub_nodes):
                return
        if (len(sub_nodes) > 0):
            return search(sub_nodes)
        else:
            return False
    global processing
    processing = True
    reset_maze()
    draw_grid()
    nodes = []
    nodes.append(bfs_node(initial_cell_col, initial_cell_row, None))
    search(nodes)
    processing = False
def breadth_first_search():

    def search(nodes):

        def check(next_col, next_row, sub_nodes):
            if valid_cell(next_col, next_row):
                if (grid[(next_col, next_row)] == TERMINAL):
                    backtrack_node = node
                    while (backtrack_node is not None):
                        if (backtrack_node.get_parent() is not None):
                            grid[(backtrack_node.get_col(), backtrack_node.get_row())] = PATH
                            draw_cell(PATH_CELL_COLOR, backtrack_node.get_col(), backtrack_node.get_row())
                            pygame.display.update()
                        backtrack_node = backtrack_node.get_parent()
                    return True
                elif ((grid[(next_col, next_row)] != WALL) and (grid[(next_col, next_row)] != VISITED) and (grid[(next_col, next_row)] != INITIAL)):
                    grid[(next_col, next_row)] = VISITED
                    draw_cell(VISITED_CELL_COLOR, next_col, next_row)
                    pygame.display.update()
                    child_node = bfs_node(next_col, next_row, node)
                    sub_nodes.append(child_node)
            return False
        pygame.display.update()
        time.sleep(SMALL_SLEEP)
        sub_nodes = []
        for node in nodes:
            if check((node.get_col() - 1), node.get_row(), sub_nodes):
                return
            if check((node.get_col() + 1), node.get_row(), sub_nodes):
                return
            if check(node.get_col(), (node.get_row() + 1), sub_nodes):
                return
            if check(node.get_col(), (node.get_row() - 1), sub_nodes):
                return
        if (len(sub_nodes) > 0):
            return search(sub_nodes)
        else:
            return False
    global processing
    processing = True
    reset_maze()
    draw_grid()
    nodes = []
    nodes.append(bfs_node(initial_cell_col, initial_cell_row, None))
    search(nodes)
    processing = False