mountaincar.py 文件源码

python
阅读 48 收藏 0 点赞 0 评论 0

项目:DDPG 作者: MOCR 项目源码 文件源码
def DoAction(self, a, s):
        #MountainCarDoAction: executes the action (a) into the mountain car
        # acti: is the force to be applied to the car
        # x: is the vector containning the position and speed of the car
        # xp: is the vector containing the new position and velocity of the car
        #print('action',a)
        #print('state',s)
#        if a[0]>0.1:
#            force = 1
#        elif a[0]<-0.1:
#            force = -1
#        else:
#            force = 0
        force = min(max(a[0], -1.0), 1.0)

        self.steps = self.steps + 1

        position = s[0]
        speed = s[1]
        #print position, speed

        # bounds for position
        bpleft = -1.4

        # bounds for speed
        bsleft = -0.07
        bsright = 0.07

        speedt1 = speed + (self.power * force) + (-0.0025 * cos(3.0 * position))
        #print speedt1

        if speedt1 < bsleft:
            speedt1 = bsleft
        elif speedt1 > bsright:
            speedt1 = bsright

        post1 = position + speedt1

        if post1 <= bpleft:
            post1 = bpleft
            speedt1 = 0.0
        #print post1, speedt1
        return [post1, speedt1]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号