Пример #1
0
    def __init__(self, filename):
        alpha = 0.3
        gamma = 0.5
        alpha_decay = 0.999
        min_alpha = 0.005
        epsilon = 0.99
        epsilon_decay = 0.99
        min_epsilon = 0.001
        self.filename = filename
        try:
            pend = cPickle.load(open(filename))
        except IOError:
            e = reply.encoder.DistanceEncoder(
                self.get_state_space(), self.get_action_space()
                )
            pend = reply.RL(
                    reply.learner.QLearner(alpha, gamma, alpha_decay, min_alpha),
                    reply.storage.DebugTableStorage(e),
                    e,
                    reply.selector.EGreedySelector(epsilon, epsilon_decay, min_epsilon)
                )
        self.rl = pend
        self.win = window.Window(width=800, height=600)
        self.figure = None
        cp.cpInitChipmunk()

        #PID stuff
        self.integral = 0
        self.last_error = 0
        self.ki = 0.5
        self.kd = -0.5
        self.kp = 1.0
Пример #2
0
    cp.cpSpaceAddShape(space, shape)

    anims = chipmunk_body_anims(body)
    sprite.x, sprite.y, sprite.rot = anims

    return shape, sprite


if __name__ == "__main__":
    pygame.init()
    pygame.display.set_mode((800, 600), pygame.OPENGL | pygame.DOUBLEBUF)
    rabbyt.set_viewport((800, 600))
    rabbyt.set_default_attribs()

    ### Physics stuff
    cp.cpInitChipmunk()
    space = cp.cpSpaceNew()
    space.contents.gravity = vec2d(0.0, -900.0)

    cp.cpSpaceResizeStaticHash(space, 50.0, 2000)
    cp.cpSpaceResizeActiveHash(space, 50.0, 100)

    wallBody = cp.cpBodyNew(1e100, 1e100)
    wallShape = cp.cpSegmentShapeNew(wallBody, vec2d(-300, -300),
                                     vec2d(300, -300), 0.0)
    wallShape.contents.u = 1.0
    wallShape.contents.collision_type = COLLTYPE_DEFAULT
    cp.cpSpaceAddStaticShape(space, wallShape)

    shapes = []
    sprites = []
Пример #3
0
    shape.contents.collision_type = COLLTYPE_DEFAULT
    cp.cpSpaceAddShape(space, shape)

    anims = chipmunk_body_anims(body)
    sprite.x, sprite.y, sprite.rot = anims

    return shape, sprite

if __name__ == "__main__":
    pygame.init()
    pygame.display.set_mode((800,600), pygame.OPENGL | pygame.DOUBLEBUF)
    rabbyt.set_viewport((800, 600))
    rabbyt.set_default_attribs()

    ### Physics stuff
    cp.cpInitChipmunk()
    space = cp.cpSpaceNew()
    space.contents.gravity = vec2d(0.0, -900.0)
    
    cp.cpSpaceResizeStaticHash(space, 50.0, 2000)
    cp.cpSpaceResizeActiveHash(space, 50.0, 100)

    wallBody = cp.cpBodyNew(1e100, 1e100)
    wallShape = cp.cpSegmentShapeNew(wallBody, vec2d(-300, -300),
            vec2d(300, -300), 0.0)
    wallShape.contents.u = 1.0
    wallShape.contents.collision_type = COLLTYPE_DEFAULT
    cp.cpSpaceAddStaticShape(space, wallShape)


    shapes = []
Пример #4
0
def init_pymunk():
    """Call this method to initialize pymunk"""
    cp.cpInitChipmunk()