Esempio n. 1
0
    def get_reward(self, old_bird: Bird, bird: Bird) -> Tuple[bool, int]:
        reset_bird = False
        if bird.get_top() <= self.height and bird.get_bottom() > 0:
            if self.board_controller.is_top(bird):
                reward = Reward.REWARD_STUCK
                reset_bird = True
            elif self.board_controller.is_bottom(
                    bird) or self.board_controller.is_pipe(bird):
                self.loose = True
                reward = Reward.REWARD_LOOSE
                if len(self.board_controller.goals) != 0:
                    self.board_controller.goals.pop(0)
            elif self.board_controller.is_checkpoint(bird):
                self.win_streak += 1
                self.checked = True
                reward = Reward.REWARD_CHECKPOINT
                self.board_controller.goals.pop(0)
            else:
                reward = Reward.REWARD_DEFAULT
        else:
            reset_bird = True
            reward = Reward.REWARD_IMPOSSIBLE

        penalty = 0
        if not reset_bird:
            old_distance = self.board_controller.distance_next_pipe(old_bird)
            distance = self.board_controller.distance_next_pipe(bird)
            if distance == -1:
                penalty = 0
            elif old_distance - distance < 0:
                penalty = distance * int(Reward.REWARD_PENALTY)
            else:
                penalty = int(Reward.REWARD_CHECKPOINT)
        return reset_bird, int(reward) + penalty
Esempio n. 2
0
 def is_bottom(self, bird: Bird) -> bool:
     return bird.get_bottom() < self.texture_manager.texture["bottom"]["height"]
Esempio n. 3
0
 def in_pipe(self, pipe: Pipe, bird: Bird) -> bool:
     if pipe.position_x <= bird.get_max_x() and pipe.position_x + self.texture["pipe"]["width"] >= bird.get_min_x() \
             and (pipe.bottom >= bird.get_bottom() or bird.get_top() >= pipe.top):
         return True
     return False
Esempio n. 4
0
 def in_checkpoint(self, pipe: Pipe, bird: Bird) -> bool:
     if pipe.position_x + self.texture["pipe"]["width"] <= bird.get_min_x() \
             and pipe.bottom < bird.get_bottom() and bird.get_top() < pipe.top:
         return True
     return False