def explore(start, goal, grid,visited, h=False):
    start.g = 0
    start.cost =start.h
    goal.g = math.inf
    heap = []
    steps = 0
    heapq.heappush(heap, (start.cost, start))

    while len(heap) > 0:
        u = heapq.heappop(heap)[1]
        goalPoint=[goal.row, goal.col]
        if visited[u.row][u.col]:
            continue
        visited[u.row][u.col] = True
        steps += 1
        if ([u.row, u.col] ==goalPoint) :
            goal.parent = u.parent
            found = True
            break

        for i in u.adjacent(grid):       
            if (visited[i[0]][i[1]] == True): 
                continue
            adj = Node(i[0], i[1], grid[i[0]][i[1]], parent=u)
            adj.g = u.g + 1
            if h == True:
                adj.h = adj.distance(goal)
            adj.cost = adj.g + adj.h
            heapq.heappush(heap, (adj.cost, adj))

    if found and h:
        print(fIt takes {steps} steps to find a path using A*)
    elif found and not h:
        print(fIt takes {steps} steps to find a path using Dijkstra)
    else:
        print(No path found)
    return goal, steps
It seems like you have provided a code snippet for pathfinding using Dijkstra's algorithm and A* algorithm with a heuristic function. The function explore takes in start and goal nodes, grid, and a 2D boolean visited array as input. It initializes the g-score of start to 0 and the g-score of goal to infinity. A heap is used to store nodes and prioritize them based on their cost. The function then iterates through the heap and finds the shortest path to the goal node.

If h is True, A* algorithm is used which considers both the cost of the node and a heuristic function that estimates the cost to the goal node. If h is False, Dijkstra's algorithm is used which only considers the cost of the node.

The function returns the goal node and the number of steps taken to find the shortest path.

However, it is worth noting that this code snippet is not complete and does not include the definitions of Node and distance function, which are needed to run the code.