コード例 #1
0
    def lidar_west_pulse(self):
        """
        The lidar beam that travels west within the game.
        :return: a point of where the beam either hit a wall or a part of the environment.
        """
        pulse_x, pulse_y = self.snakeEnv.snake.head.pos()
        west_pulse = Point(pulse_x, pulse_y)
        west_wall = Point((-1) * (self.snakeEnv.screen_width / 2), pulse_y)

        hit_obstacle = False
        hit_apple = False

        while True:

            if west_pulse.x <= west_wall.x:
                hit_obstacle = True
                break

            if self.snakeEnv.snake.point_is_in_tail(west_pulse)[0]:
                hit_obstacle = True
                break

            if self.snakeEnv.current_food.point_is_in_food(west_pulse)[0]:
                hit_apple = True
                break

            west_pulse.offset(-1, 0)

        return (west_pulse, hit_obstacle, hit_apple)
        """
コード例 #2
0
    def lidar_north_west_pulse(self):
        """
        The lidar beam that travels north west within the game.
        :return: a point of where the beam either hit a wall or a part of the environment.
        """
        pulse_x, pulse_y = self.snakeEnv.snake.head.pos()
        north_west_pulse = Point(pulse_x, pulse_y)
        north_wall = Point(pulse_x, self.snakeEnv.screen_height / 2)
        west_wall = Point(((-1) * self.snakeEnv.screen_width) / 2, pulse_y)

        hit_obstacle = False
        hit_apple = False

        while True:

            if north_west_pulse.y >= north_wall.y or north_west_pulse.x <= west_wall.x:
                hit_obstacle = True
                break

            if self.snakeEnv.snake.point_is_in_tail(north_west_pulse)[0]:
                hit_obstacle = True
                break

            if self.snakeEnv.current_food.point_is_in_food(
                    north_west_pulse)[0]:
                hit_apple = True
                break

            north_west_pulse.offset(-1, 1)

        return (north_west_pulse, hit_obstacle, hit_apple)
        """
コード例 #3
0
    def lidar_south_pulse(self):
        """
        The lidar beam that travels south within the game.
        :return: a point of where the beam either hit a wall or a part of the environment.
        """
        pulse_x, pulse_y = self.snakeEnv.snake.head.pos()
        south_pulse = Point(pulse_x, pulse_y)
        south_wall = Point(pulse_x, (-1) * (self.snakeEnv.screen_height / 2))

        hit_obstacle = False
        hit_apple = False

        while True:

            if south_pulse.y <= south_wall.y:
                hit_obstacle = True
                break

            if self.snakeEnv.snake.point_is_in_tail(south_pulse)[0]:
                hit_obstacle = True
                break

            if self.snakeEnv.current_food.point_is_in_food(south_pulse)[0]:
                hit_apple = True
                break

            south_pulse.offset(0, -1)

        return (south_pulse, hit_obstacle, hit_apple)
        """