#!/usr/bin/env python3
"""Auto-generated by AGI Loop cycle #1286
Task: \boxed{}</think>

Write a Python function that calculates the shortest path between two points in a 2D grid, considering obstacles, and returns the path as a list of coordinates.
Generated: 2026-02-13T02:57:54.668617
"""

import heapq

def shortest_path(grid, start, end):
    rows, cols = len(grid), len(grid[0])
    directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]  # right, down, left, up
    
    # Heuristic function (Manhattan distance)
    def heuristic(pos):
        return abs(pos[0] - end[0]) + abs(pos[1] - end[1])
    
    # Priority queue for A* algorithm
    queue = [(heuristic(start), start)]
    visited = set()
    came_from = {}
    
    while queue:
        _, current = heapq.heappop(queue)
        
        if current == end:
            # Reconstruct path
            path = [current]
            while current in came_from:
                current = came_from[current]
                path.append(current)
            return path[::-1]
        
        if current in visited:
            continue
        
        visited.add(current)
        
        for dx, dy in directions:
            new_row, new_col = current[0] + dx, current[1] + dy
            new_pos = (new_row, new_col)
            
            if (0 <= new_row < rows and 0 <= new_col < cols and 
                grid[new_row][new_col] == 0 and new_pos not in visited):
                priority = heuristic(new_pos)
                heapq.heappush(queue, (priority, new_pos))
                came_from[new_pos] = current
    
    return None  # No path found

if __name__ == '__main__':
    # Example grid (0 = free space, 1 = obstacle)
    grid = [
        [0, 0, 0, 0, 0],
        [0, 1, 1, 1, 0],
        [0, 0, 0, 1, 0],
        [0, 1, 0, 1, 0],
        [0, 0, 0, 0, 0]
    ]
    
    start = (0, 0)
    end = (4, 4)
    
    path = shortest_path(grid, start, end)
    
    if path:
        print("Path found:", path)
    else:
        print("No path found")