def available_moves(x, y, maze):
    """Given an (x, y) position, generate available moves"""
    N = maze.shape[0]
    available = []

    # Go down
    for n in range(x + 1, N):
        if maze[n, y] == 0:
            available.append((n, y))
        else:
            break

    # Go up
    for n in reversed(range(0, x)):
        if maze[n, y] == 0:
            available.append((n, y))
        else:
            break

    # Go left
    for n in range(y + 1, N):
        if maze[x, n] == 0:
            available.append((x, n))
        else:
            break

    # Go right
    for n in reversed(range(0, y)):
        if maze[x, n] == 0:
            available.append((x, n))
        else:
            break

    return available