from collections import deque


def shortest_path(width, height, walls, start, goal):
    """Find a fewest-move path on a four-direction, equal-cost grid."""
    def inside(cell):
        x, y = cell
        return 0 <= x < width and 0 <= y < height

    if width <= 0 or height <= 0:
        raise ValueError("Grid dimensions must be positive")
    if not inside(start) or not inside(goal):
        raise ValueError("Start and goal must be inside the grid")
    if start in walls or goal in walls:
        return []

    frontier = deque([start])
    parent = {start: None}

    while frontier:
        cell = frontier.popleft()
        if cell == goal:
            path = []
            while cell is not None:
                path.append(cell)
                cell = parent[cell]
            return path[::-1]

        x, y = cell
        for dx, dy in [(1, 0), (0, -1), (0, 1), (-1, 0)]:
            neighbour = (x + dx, y + dy)
            if inside(neighbour) and neighbour not in walls and neighbour not in parent:
                parent[neighbour] = cell
                frontier.append(neighbour)

    return []


if __name__ == "__main__":
    walls = {(2, 1), (2, 2), (2, 3)}
    path = shortest_path(5, 5, walls, (0, 2), (4, 2))
    assert len(path) - 1 == 8
    assert path[0] == (0, 2) and path[-1] == (4, 2)
    assert all(cell not in walls for cell in path)
    assert all(abs(a[0] - b[0]) + abs(a[1] - b[1]) == 1
               for a, b in zip(path, path[1:]))

    assert shortest_path(3, 3, {(1, 0), (1, 1), (1, 2)}, (0, 1), (2, 1)) == []
    assert shortest_path(1, 1, set(), (0, 0), (0, 0)) == [(0, 0)]
    assert shortest_path(2, 2, {(1, 1)}, (0, 0), (1, 1)) == []

    print("Moves:", len(path) - 1)
    print("Path:", path)
    print("All checks passed")
