def alive_bonus()

in roboschool/gym_humanoid_flagrun.py [0:0]


    def alive_bonus(self, z, pitch):
        if self.frame%30==0 and self.frame>100 and self.on_ground_frame_counter==0:
            target_xyz  = np.array(self.body_xyz)
            robot_speed = np.array(self.robot_body.speed())
            angle       = self.np_random.uniform(low=-3.14, high=3.14)
            from_dist   = 4.0
            attack_speed   = self.np_random.uniform(low=20.0, high=30.0)  # speed 20..30 (* mass in cube.urdf = impulse)
            time_to_travel = from_dist / attack_speed
            target_xyz += robot_speed*time_to_travel  # predict future position at the moment the cube hits the robot
            cpose = cpp_household.Pose()
            cpose.set_xyz(
                target_xyz[0] + from_dist*np.cos(angle),
                target_xyz[1] + from_dist*np.sin(angle),
                target_xyz[2] + 1.0)
            attack_speed_vector  = target_xyz - np.array(cpose.xyz())
            attack_speed_vector *= attack_speed / np.linalg.norm(attack_speed_vector)
            attack_speed_vector += self.np_random.uniform(low=-1.0, high=+1.0, size=(3,))
            self.aggressive_cube.set_pose_and_speed(cpose, *attack_speed_vector)
        if z < 0.8:
            if self.task==self.TASK_WALK:
                self.on_ground_frame_counter = 10000  # This ends episode immediately
            self.on_ground_frame_counter += 1
            self.electricity_cost = RoboschoolHumanoid.electricity_cost / 5.0   # Don't care about electricity, just stand up!
        elif self.on_ground_frame_counter > 0:
            self.on_ground_frame_counter -= 1
            self.electricity_cost = RoboschoolHumanoid.electricity_cost / 2.0    # Same as in Flagrun
        else:
            self.walking_normally += 1
            self.electricity_cost = RoboschoolHumanoid.electricity_cost / 2.0
        # End episode if the robot can't get up in 170 frames, to save computation and decorrelate observations.
        return self.potential_leak() if self.on_ground_frame_counter<170 else -1