<commit_before>from pybrain.rl.environments import EpisodicTask
from environment import Lander


class LanderTask(EpisodicTask):
    """
    Task that represents lander attempting to land.
    """

    def __init__(self, environment=None):
        if environment is None:
            self.env = Lander()
        else:
            self.env = environment
        EpisodicTask.__init__(self, self.env)

        self.sensor_limits = [(0.0, 100.0), (0.0, 35.0), (1.0, 3.0),
                              (-0.2, 0.2), (-0.2, 0.2),
                              (-0.1, 0.1), (0.0, 100.0)]
        self.actor_limits = [(0.0, 12.0), (-0.1, 0.1)]

    def isFinished(self):
        return self.env.status == 'landed' or self.env.status == 'crashed'

    def getReward(self):
        reward = 0
        if self.env.status == 'crashed':
            if self.env.y_velocity > self.env.max_safe_landing_speed:
                reward -= 10
            if abs(self.env.x_position) > self.env.max_safe_x:
                reward -= 10
        if self.env.status == 'landed':
            reward += 100
        return reward
<commit_msg>Adding dynamic reward system<commit_after>from math import ceil
from pybrain.rl.environments import EpisodicTask
from environment import Lander


class LanderTask(EpisodicTask):
    """
    Task that represents lander attempting to land.
    """

    def __init__(self, environment=None):
        if environment is None:
            self.env = Lander()
        else:
            self.env = environment
        EpisodicTask.__init__(self, self.env)

        self.sensor_limits = [(0.0, 100.0), (0.0, 35.0), (1.0, 3.0),
                              (-0.2, 0.2), (-0.2, 0.2),
                              (-0.1, 0.1), (0.0, 100.0)]
        self.actor_limits = [(0.0, 12.0), (-0.1, 0.1)]

    def isFinished(self):
        return self.env.status == 'landed' or self.env.status == 'crashed'

    def getReward(self):
        reward = 0
        if self.env.status == 'crashed':
            if self.env.y_velocity > self.env.max_safe_landing_speed:
                reward -= ceil(abs(self.env.y_velocity) /
                               self.env.max_safe_landing_speed)
            if abs(self.env.x_position) > self.env.max_safe_x:
                reward -= ceil(abs(self.env.x_position) /
                               self.env.max_safe_x)
            print('Returning full crashed reward: {}'.format(reward))
        if self.env.status == 'landed':
            reward += 1000
        return reward

{'fraction_non_alphanumeric': 0.13046937151949084, 'fraction_numerical': 0.038583929992044554, 'mean_word_length': 1.727765726681128, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1282046', 'n_tokens_mistral': 863, 'n_tokens_neox': 798, 'n_words': 180}