Ejemplo n.º 1
0
    def __init__(self, maze: Maze, hand: Hand):
        position = path.Node(maze.start)
        direction = Direction.EAST
        turn_prio = [hand, lambda d: d, Hand.opposite(hand), turn_back]

        while position.val != maze.end:
            candidates = [turn(direction) for turn in turn_prio]
            neighbours = maze.get_accessible_neighbours(position.val)
            direction = next(c for c in candidates
                             if c(position.val) in neighbours)
            position = position.create_child(direction(position.val))

        self.solution = Solution.from_vertices(list(position.as_path()))