def remove_dead_end(dead_node, maze):
    """Remove one dead end in a maze."""

    h, w = maze.shape
    pos = dead_node.data
    free_dir = dead_node.get_edges_out()[0].data[0]

    # first, try to pierce the wall straight ahead
    # this might not be possible if we are on the borders of the maze
    # this dictionary gives us the sequence of directions to try
    free_to_pierce = {west: [east, north, south],
                      east: [west, north, south],
                      north: [south, west, east],
                      south: [north, west, east]
                      }

    for pierce_dir in free_to_pierce[free_dir]:
        pierce_x, pierce_y = pos[0] + pierce_dir[0], pos[1] + pierce_dir[1]
        # remember not to pierce walls in the central wall (x==w-1), as those
        # might become dead ends during the mirroring step
        if (pierce_x >= 0 and pierce_x < w - 1
            and pierce_y >= 0
            and pierce_y < h):
            maze[pierce_y, pierce_x] = E
            break
dataset/ETHPy150Open ASPP/pelita/layouts/maze_generator.py/remove_dead_end/original