Ejemplo n.º 1
0
    def move(self):
        if self.__follow_wall and self.__angular == 0:
            self.__follow_wall = False

        allowed_directions = self.__labyrinth.get_allowed_directions(self)
        if not self.__follow_wall:
            if self.__direction in allowed_directions:
                self.__labyrinth.move(self, self.__direction)
            else:
                self.__follow_wall = True
                self.turn_right()
        else:
            left = Direction.next_left(self.__direction)
            if left in allowed_directions:
                self.__labyrinth.move(self, left)
                self.turn_left()
            else:
                loop = 0
                while loop != 3:
                    if self.__direction in allowed_directions:
                        self.__labyrinth.move(self, self.__direction)
                        break
                    else:
                        self.turn_right()
                    loop += 1
                if loop == 3:
                    raise Exception("Infinite loop !")
Ejemplo n.º 2
0
 def turn_left(self):
     self.__direction = Direction.next_left(self.__direction)
     self.__angular -= 1