Beispiel #1
0
    def __init__(self, screen_size, gravity=(
            0.0, -9.0), ppm=100.0, renderer='pygame'):
        """ Init the world with boundaries and gravity, and init colors.

            Parameters:
              screen_size .. (w, h) -- screen size in pixels [int]
              gravity ...... (x, y) in m/s^2  [float] default: (0.0, -9.0)
              ppm .......... pixels per meter [float] default: 100.0
              renderer ..... which drawing method to use (str) default: 'pygame'

            Return: class Elements()
        """
        self.set_screenSize(screen_size)
        self.set_drawingMethod(renderer)

        # Create Subclasses
        self.add = add_objects.Add(self)
        self.callbacks = callbacks.CallbackHandler(self)
        self.camera = camera.Camera(self)

        # Gravity + Bodies will sleep on outside
        self.gravity = gravity
        self.doSleep = True

        # Create the World
        self.world = box2d.b2World(self.gravity, self.doSleep)
        bodyDef = box2d.b2BodyDef()
        self.world.groundBody = self.world.CreateBody(bodyDef)

        # Init Colors
        self.init_colors()

        # Set Pixels per Meter
        self.ppm = ppm
Beispiel #2
0
    def __init__(self):
        self.count = 1000
        self.force = 10

        self.robots = {}
        self.bullets = []
        self.sprites = {}
        self.to_destroy = []

        halfx = 30
        self.ahalfx = 20
        halfy = 25
        self.ahalfy = 20

        gravity = (0, 0)
        doSleep = True

        self.timeStep = 1.0 / 60.0
        self.velIterations = 10
        self.posIterations = 8


        aabb = box2d.b2AABB()
        aabb.lowerBound = (-halfx, -halfy)
        aabb.upperBound = (halfx, halfy)

        self.w = box2d.b2World(gravity, doSleep)

        self.makearena()
    def __init__(self, **kw):
        super(Framework, self).__init__(**kw)

        # Initialize the text display group
        self.textGroup = grText(self)

        # Load the font and record the screen dimensions
        self.font = pyglet.font.load(self.fontname, self.fontsize)
        self.screenSize = box2d.b2Vec2(self.width, self.height)

        # Box2D Initialization
        self.worldAABB = box2d.b2AABB()
        self.worldAABB.lowerBound = (-200.0, -100.0)
        self.worldAABB.upperBound = ( 200.0, 200.0)
        gravity = (0.0, -10.0)

        doSleep = True
        self.world = box2d.b2World(self.worldAABB, gravity, doSleep)
        self.destructionListener = fwDestructionListener()
        self.boundaryListener = fwBoundaryListener()
        self.contactListener = fwContactListener()
        self.debugDraw = fwDebugDraw()

        self.debugDraw.surface = self.screen

        self.destructionListener.test = self
        self.boundaryListener.test = self
        self.contactListener.test = self
        
        self.world.SetDestructionListener(self.destructionListener)
        self.world.SetBoundaryListener(self.boundaryListener)
        self.world.SetContactListener(self.contactListener)
        self.world.SetDebugDraw(self.debugDraw)

        self._viewCenter = box2d.b2Vec2(0,10.0)
Beispiel #4
0
    def setup(self):
        self.viewer = None

        self.world = Box2D.b2World()
        self.terrain = None

        init_x = TERRAIN_STEP * TERRAIN_STARTPAD / 2
        init_y = TERRAIN_HEIGHT + 2 * LEG_H
        self.start_x = [
            init_x + WALKER_SEPERATION * i * TERRAIN_STEP for i in range(self.n_walkers)
        ]
        self.walkers = [
            BipedalWalker(self.world, init_x=sx,
                          init_y=init_y, seed=self.seed_val)
            for sx in self.start_x
        ]
        self.num_agents = len(self.walkers)
        self.observation_space = [
            agent.observation_space for agent in self.walkers]
        self.action_space = [agent.action_space for agent in self.walkers]

        self.package_scale = self.n_walkers / 1.75
        self.package_length = PACKAGE_LENGTH / SCALE * self.package_scale

        self.total_agents = self.n_walkers

        self.prev_shaping = np.zeros(self.n_walkers)
        self.prev_package_shaping = 0.0

        self.terrain_length = int(TERRAIN_LENGTH * self.n_walkers * 1 / 8.)

        self.reset()
Beispiel #5
0
    def __init__(self):
        self.count = 1000
        self.force = 10

        self.tanks = {}
        self.bullets = []
        self.sprites = {}
        self.to_destroy = []

        halfx = 30
        self.ahalfx = 20
        halfy = 25
        self.ahalfy = 20

        gravity = (0, 0)
        doSleep = True

        self.timeStep = 1.0 / 60.0
        self.velIterations = 10
        self.posIterations = 8


        aabb = box2d.b2AABB()
        aabb.lowerBound = (-halfx, -halfy)
        aabb.upperBound = (halfx, halfy)

        self.w = box2d.b2World(aabb, gravity, doSleep)
        self.w.GetGroundBody().SetUserData({'actor': None})

        self.makearena()
    def __init__(self, force_ground, scroller):
        layer.ScrollableLayer.__init__(self)
        self.scroller = scroller
        self.force_ground = force_ground
        self.b2world = b2.b2World(gravity=(0, -GRAVITY),
                                  contactListener=b2Listener())
        self.b2level = self.b2world.CreateStaticBody()
        self._create_b2_tile_map(force_ground)
        #FROM TILEMAP TESTER
        self.camera_pos = [16*25, 16*25]
        self.keys = {key.LEFT: False,
                     key.RIGHT: False,
                     key.UP: False,
                     key.DOWN: False}
        movable_object.Movable_Object.tilemap = self.force_ground
        movable_object.Movable_Object.world = self.b2world

        self.unit = Actor(Human)
        #print self.unit.cshape
        self.unit.move_to(60, 1716)
        self.add(self.unit, z=100)
        self.unit.do(Brain())
        self.cellmap = force_ground
        #self.counter = 0
        self.path = None

        self.counter = 0
        self.fr = None

        self.schedule(self.update)
Beispiel #7
0
 def setup_world(self):
     self.worldAABB = box2d.b2AABB()
     self.worldAABB.lowerBound = (-2000.0, -2000.0)
     self.worldAABB.upperBound = (2000.0, 2000.0)
     self.gravity = (0.0, -9.81)
     doSleep = False
     self.world = box2d.b2World(self.worldAABB, self.gravity, doSleep) 
Beispiel #8
0
    def __init__(self, verbose=1):
        EzPickle.__init__(self)
        self.seed()
        self.contactListener_keepref = FrictionDetector(self)
        self.world = Box2D.b2World(
            (0, 0), contactListener=self.contactListener_keepref)
        self.viewer = None
        self.invisible_state_window = None
        self.invisible_video_window = None
        self.road = None
        self.grass = []
        self.on_grass_idx = set()
        self.car = None
        self.reward = 0.0
        self.prev_reward = 0.0
        self.verbose = verbose
        self.poly = {'grass': [], 'road': [], 'other': []}

        self.action_space = spaces.Box(np.array([-1, 0, 0]),
                                       np.array([+1, +1, +1]),
                                       dtype=np.float32)  # steer, gas, brake

        self.observation_space = spaces.Box(low=0,
                                            high=255,
                                            shape=(STATE_H, STATE_W, 3),
                                            dtype=np.uint8)

        self.timer = 0
    def __init__(self, verbose=1):
        EzPickle.__init__(self)
        self.seed()
        self.contactListener_keepref = FrictionDetector(self)
        self.world = Box2D.b2World(
            (0, 0), contactListener=self.contactListener_keepref)
        self.viewer = None
        self.invisible_state_window = None
        self.invisible_video_window = None
        self.road = None
        self.car = None
        self.reward = 0.0
        self.prev_reward = 0.0
        self.verbose = verbose
        self.fd_tile = fixtureDef(shape=polygonShape(
            vertices=[(0, 0), (1, 0), (1, -1), (0, -1)]))

        self.action_space = spaces.Box(np.array([-1, 0, 0]),
                                       np.array([+1, +1, +1]),
                                       dtype=np.float32)  # steer, gas, brake

        self.observation_space = spaces.Box(low=0,
                                            high=255,
                                            shape=(STATE_H, STATE_W, 3),
                                            dtype=np.uint8)
    def __init__(self, level_number=0, continuous=True, speed_threshold=1):
        self.level_number = level_number
        self._seed()
        self.viewer = None
        self.episode_number = 0

        self.world = Box2D.b2World()
        self.water = None
        self.lander = None
        self.engine = None
        self.ship = None
        self.legs = []
        self.state = []
        self.continuous = continuous
        self.landed = False
        self.landed_fraction = []
        self.good_landings = 0
        self.speed_threshold = speed_threshold
        almost_inf = 9999
        high = np.array(
            [1, 1, 1, 1, 1, 1, 1, almost_inf, almost_inf, almost_inf], dtype=np.float32
        )
        low = -high
        if not VEL_STATE:
            high = high[0:7]
            low = low[0:7]

        self.observation_space = spaces.Box(low, high, dtype=np.float32)

        if self.continuous:
            self.action_space = spaces.Box(-1, +1, (3,), dtype=np.float32)
        else:
            self.action_space = spaces.Discrete(7)

        self.reset()
Beispiel #11
0
    def __init__(self):

        self.viewer = rendering.Viewer(self.VIEWPORT_W, self.VIEWPORT_H)
        self.viewer.set_bounds(0, self.VIEWPORT_W / self.SCALE, 0,
                               self.VIEWPORT_H / self.SCALE)
        self.world = Box2D.b2World()

        self.lander = self.world.CreateDynamicBody(fixtures=[
            fixtureDef(shape=polygonShape(vertices=[(x / self.SCALE,
                                                     y / self.SCALE)
                                                    for x, y in poly]),
                       density=0.0) for poly in [
                           self.HULL_POLY,
                           self._leg_poly(-1),
                           self._leg_poly(+1),
                           self._motor_poly(+1),
                           self._motor_poly(-1),
                           self._blade_poly(+1, -1),
                           self._blade_poly(+1, +1),
                           self._blade_poly(-1, -1),
                           self._blade_poly(-1, +1)
                       ]
        ])

        # By showing props periodically, we can emulate prop rotation
        self.props_visible = 0
Beispiel #12
0
    def __init__(self):
        self.seed()
        self.contactListener_keepref = FrictionDetector(self)
        self.world = Box2D.b2World(
            (0, 0), contactListener=self.contactListener_keepref)
        self.viewer = None
        self.invisible_state_window = None
        self.invisible_video_window = None
        self.road = None
        self.car = None
        self.reward = 0.0
        self.prev_reward = 0.0

        self.action_space = spaces.Box(np.array([-1, 0, 0]),
                                       np.array([+1, +1,
                                                 +1]))  # steer, gas, brake
        self.observation_space = spaces.Box(low=0,
                                            high=255,
                                            shape=(STATE_H, STATE_W, 3),
                                            dtype=np.uint8)
        #VBO stuff
        self.vertex_vbo_id = gl.GLuint()
        self.color_vbo_id = gl.GLuint()
        gl.glGenBuffers(1, self.vertex_vbo_id)
        gl.glGenBuffers(1, self.color_vbo_id)
        self.initialized = 0
    def __init__(self, stochasticity=INITIAL_RANDOM):
        EzPickle.__init__(self)
        self.seed()
        self.viewer = None

        self.world = Box2D.b2World()
        self.moon = None
        self.lander = None
        self.particles = []
        self.stochasticity = stochasticity

        self.prev_reward = None

        # useful range is -1 .. +1, but spikes can be higher
        self.observation_space = spaces.Box(-np.inf, np.inf, shape=(8,), dtype=np.float32)

        if self.continuous:
            # Action is two floats [main engine, left-right engines].
            # Main engine: -1..0 off, 0..+1 throttle from 50% to 100% power. Engine can't work with less than 50% power.
            # Left-right:  -1.0..-0.5 fire left engine, +0.5..+1.0 fire right engine, -0.5..0.5 off
            self.action_space = spaces.Box(-1, +1, (2,), dtype=np.float32)
        else:
            # Nop, fire left engine, main engine, right engine
            self.action_space = spaces.Discrete(4)
        self.ignore_reset = False

        self.reset()
Beispiel #14
0
    def __setstate__(self, state):
        self.initial_center_x, self.initial_center_y, self.terrain_heights = state
        self.seed()
        self.viewer = None

        self.world = Box2D.b2World()
        self.moon = None
        self.lander = None
        self.particles = []

        self.prev_reward = None

        # useful range is -1 .. +1, but spikes can be higher
        self.observation_space = spaces.Box(-np.inf,
                                            np.inf,
                                            shape=(8, ),
                                            dtype=np.float64)

        if self.continuous:
            # Action is two floats [main engine, left-right engines].
            # Main engine: -1..0 off, 0..+1 throttle from 50% to 100% power. Engine can't work with less than 50% power.
            # Left-right:  -1.0..-0.5 fire left engine, +0.5..+1.0 fire right engine, -0.5..0.5 off
            self.action_space = spaces.Box(-1, +1, (2, ), dtype=np.float64)
        else:
            # Nop, fire left engine, main engine, right engine
            self.action_space = spaces.Discrete(4)
Beispiel #15
0
    def __init__(self):
        self._seed()
        self.viewer = None
        self.episode_number = 0

        self.maxstep = 2000
        self.ypos = 0.95

        self.world = Box2D.b2World()
        self.water = None
        self.lander = None
        self.engine = None
        self.ship = None
        self.legs = []

        high = np.array([1, 1, 1, 1, 1, 1, 1, np.inf, np.inf, np.inf],
                        dtype=np.float32)
        low = -high
        if not VEL_STATE:
            high = high[0:7]
            low = low[0:7]

        self.observation_space = spaces.Box(low, high, dtype=np.float32)

        if CONTINUOUS:
            self.action_space = spaces.Box(-1.0, +1.0, (3, ), dtype=np.float32)
        else:
            self.action_space = spaces.Discrete(7)

        self.reset()
Beispiel #16
0
    def __init__(self, verbose=1):
        EzPickle.__init__(self)
        self.WHEEL_COLOR = (0.0,0.0,0.0)
        self.WHEEL_WHITE = (0.3,0.3,0.3)
        self.MUD_COLOR   = (0.4,0.4,0.0)
        self.HULL_COLOR   = (0.9,0.0,0.0)
        self.TILE_WHITE_COLOR = (1., 1., 1.)
        self.TILE_RED_COLOR = (1., 0., 0.)
        self.BACK_COLOR1 = (0., 1., 0.)
        self.BACK_COLOR2 = (0., 0.8, 0.2)

        self.seed()
        self.contactListener_keepref = FrictionDetector(self)
        self.world = Box2D.b2World((0,0), contactListener=self.contactListener_keepref)
        self.viewer = None
        self.invisible_state_window = None
        self.invisible_video_window = None
        self.road = None
        self.car = None
        self.reward = 0.0
        self.prev_reward = 0.0
        self.verbose = verbose
        self.fd_tile = fixtureDef(
                shape = polygonShape(vertices=
                    [(0, 0),(1, 0),(1, -1),(0, -1)]))

        self.action_space = spaces.Box( np.array([-1,0,0]), np.array([+1,+1,+1]), dtype=np.float32)  # steer, gas, brake
        self.observation_space = spaces.Box(low=0, high=255, shape=(STATE_H, STATE_W, 3), dtype=np.uint8)

        self.road_color = [0.4, 0.4, 0.4]
Beispiel #17
0
    def __init__(self, verbose=1):
        EzPickle.__init__(self)
        self.seed_value = 0
        self.seed()
        self.contactListener_keepref = FrictionDetector(self)
        self.world = Box2D.b2World(
            (0, 0), contactListener=self.contactListener_keepref)
        self.viewer = None
        self.invisible_state_window = None
        self.invisible_video_window = None
        self.road = None
        self.car = None
        self.reward = 0.0
        self.prev_reward = 0.0
        self.verbose = verbose
        self.wheels_on_road = 0
        self.new_step = False
        self.sem = 0
        self.wheel_reward = 1
        self.wheels = {}

        self.action_space = spaces.Box(np.array([-1, 0, 0]),
                                       np.array([+1, +1, +1]),
                                       dtype=np.float32)  # steer, gas, brake
        self.observation_space = spaces.Box(low=0,
                                            high=255,
                                            shape=(STATE_H, STATE_W, 3),
                                            dtype=np.uint8)
Beispiel #18
0
    def __init__(self):
        self._player_maximum_thrust = 2

        self._physics_world = Box2D.b2World(gravity=(0,0), doSleep=False, contactListener=ContactDamageInflicter(self))

        self._asteroid_shape = Box2D.b2CircleShape()
        self._asteroid_shape.radius = ASTEROID_RADIUS

        self._asteroid_fixture = Box2D.b2FixtureDef()
        self._asteroid_fixture.shape = self._asteroid_shape
        self._asteroid_fixture.density = 10
        self._asteroid_fixture.restitution = 1
        self._asteroid_fixture.friction = 1
        self._asteroid_fixture.filter.categoryBits = CollisionFilterCategory.ASTEROID
        self._asteroid_fixture.filter.maskBits = CollisionFilterCategory.ASTEROID | CollisionFilterCategory.PLAYER 

        self._ship_shape = Box2D.b2CircleShape()
        self._ship_shape.radius = PLAYER_RADIUS

        ship_fixture = Box2D.b2FixtureDef()
        ship_fixture.shape = self._ship_shape
        ship_fixture.density = 5
        ship_fixture.restitution = 1
        ship_fixture.friction = 1
        ship_fixture.filter.categoryBits = CollisionFilterCategory.PLAYER
        ship_fixture.filter.maskBits = CollisionFilterCategory.ASTEROID | CollisionFilterCategory.BORDER

        self._player_base_friction = 0.02
        self._player_thrust_extra_friction = 0.02

        self._player_maximum_turn_thrust = 1
        self._thrust_extra_turn_thrust = -0.3
        self._base_rotational_friction = 0.1
        self._thrust_extra_rotational_friction = 0.05

        ship_body_def = Box2D.b2BodyDef()
        ship_body_def.position = (
            5 + random() * (RIGHT_BORDER_X - 10),
            5 + random() * (TOP_BORDER_Y - 10)
        )
        ship_body_def.angle = random() * pi * 2
        ship_body_def.linearVelocity = (0,0)
        ship_body_def.linearDamping = self._player_base_friction
        ship_body_def.angularVelocity = 0
        ship_body_def.angularDamping = self._base_rotational_friction
        ship_body_def.fixtures = [ship_fixture]
        ship_body_def.type = Box2D.b2_dynamicBody
        ship_body_def.allowSleep = False

        self._player_ship = self._physics_world.CreateBody(ship_body_def)

        self._asteroids = self._create_starting_asteroids()
        self._asteroids_to_kill = []
        self._asteroid_extra_spawn_accumulator = 0
        self._asteroids_avoided_count = 0

        self._borders = borders.add_borders(self._physics_world, LEFT_BORDER_X, RIGHT_BORDER_X, BOTTOM_BORDER_Y, TOP_BORDER_Y)
        self._asteroid_play_space = asteroid_play_space.add_asteroid_play_space(self._physics_world, LEFT_BORDER_X, RIGHT_BORDER_X, BOTTOM_BORDER_Y, TOP_BORDER_Y)

        self.player_current_health = MAX_PLAYER_HEALTH
Beispiel #19
0
    def __init__(self):


        self._seed()
        self.viewer = None

        self.world = Box2D.b2World()
        self.moon = None
        self.lander = None
        self.particles = []

        self.prev_reward = None

        high = np.array([np.inf]*8)  # useful range is -1 .. +1, but spikes can be higher
        self.observation_space = spaces.Box(-high, high)

        if self.continuous:
            # Action is two floats [main engine, left-right engines].
            # Main engine: -1..0 off, 0..+1 throttle from 50% to 100% power. Engine can't work with less than 50% power.
            # Left-right:  -1.0..-0.5 fire left engine, +0.5..+1.0 fire right engine, -0.5..0.5 off
            self.action_space = spaces.Box(-1, +1, (2,))
        else:
            # Nop, fire left engine, main engine, right engine
            self.action_space = spaces.Discrete(4)

        self._reset()
Beispiel #20
0
    def __init__(self, total_episode_steps=1000 ,verbose=1):
        EzPickle.__init__(self)
        self.seed()
        self.contactListener_keepref = FrictionDetector(self)
        self.world = Box2D.b2World((0,0), contactListener=self.contactListener_keepref)
        self.viewer = None
        self.invisible_state_window = None
        self.invisible_video_window = None
        self.road = None
        self.car = None
        self.reward = 0.0
        self.prev_reward = 0.0
        self.verbose = verbose
        self.fd_tile = fixtureDef(
                shape = polygonShape(vertices=
                    [(0, 0),(1, 0),(1, -1),(0, -1)]))

        # discrete car racer
        self.action_space = spaces.Box( np.array([-1,0,0]), np.array([+1,+1,+1]), dtype=np.float32)  # steer, gas, brake
        # self.action_space = spaces.Discrete(5)
        # self.actions = [np.array([-1,0,0], dtype=np.float32), 
        #                 np.array([1,0,0], dtype=np.float32), 
        #                 np.array([0,1,0], dtype=np.float32), 
        #                 np.array([0,0,0.8], dtype=np.float32), 
        #                 np.array([0,0,0], dtype=np.float32)]  # left right, gas, brake, nothing
        self.total_episode_steps = total_episode_steps
        self.current_steps = 0
        self.observation_space = spaces.Box(low=0, high=255, shape=(STATE_W, STATE_H, 3), dtype=np.uint8)
Beispiel #21
0
    def __init__(self, hist_len=0, block_high=0.5):
        self.seed()
        self.viewer = None

        self.world = Box2D.b2World()
        self.moon = None
        self.lander = None
        self.particles = []

        self.hist_len = hist_len
        self.block_high = block_high

        self.prev_reward = None

        # We assume this env is always partially observable
        # if hist_len != 0:
        high = np.array([np.inf] * (1 + self.hist_len) * (9 + 2))
        t_high = np.array([np.inf] * ((1 + self.hist_len) * (9 + 2) + 9))
        self.history = np.zeros([(self.hist_len + 1) * (9 + 2)])

        self.observation_space = spaces.Box(-high, high)

        # TODO: change the following line into (-t_high, t_high) for guided case
        self.total_space = spaces.Box(-high, high)

        # We assume this environment is continuous
        # Action is two floats [main engine, left-right engines].
        # Main engine: -1..0 off, 0..+1 throttle from 50% to 100% power. Engine can't work with less than 50% power.
        # Left-right:  -1.0..-0.5 fire left engine, +0.5..+1.0 fire right engine, -0.5..0.5 off
        self.action_space = spaces.Box(-1, +1, (2, ))

        self.prev_obs = None
Beispiel #22
0
    def __init__(self, verbose=1, **kwargs):
        EzPickle.__init__(self)
        self.seed()

        self.road_color = ROAD_COLOR[:]
        self.grass_color = [0.4, 0.8, 0.4, 1]
        if 'modification' in kwargs:
            self._modification_type = kwargs['modification']
        else:
            self._modification_type = ''

        self.contactListener_keepref = FrictionDetector(self)
        self.world = Box2D.b2World(
            (0, 0), contactListener=self.contactListener_keepref)
        self.viewer = None
        self.invisible_state_window = None
        self.invisible_video_window = None
        self.road = None
        self.car = None
        self.reward = 0.0
        self.prev_reward = 0.0
        self.verbose = verbose
        self.fd_tile = fixtureDef(shape=polygonShape(
            vertices=[(0, 0), (1, 0), (1, -1), (0, -1)]))

        self.action_space = spaces.Box(np.array([-1, 0, 0]),
                                       np.array([+1, +1, +1]),
                                       dtype=np.float32)  # steer, gas, brake
        self.observation_space = spaces.Box(low=0,
                                            high=255,
                                            shape=(STATE_H, STATE_W, 3),
                                            dtype=np.uint8)

        self.step_cnt = 0
Beispiel #23
0
 def __init__(self, max_skew: float, seed=None):
     self.rand_state = np.random.RandomState(seed=seed) if seed else None
     self.VIEWPORT_H = skew_by(val=self.VIEWPORT_H, max_skew=max_skew, rand_state=self.rand_state)
     self.VIEWPORT_W = skew_by(val=self.VIEWPORT_W, max_skew=max_skew, rand_state=self.rand_state)
     self.max_skew = max_skew
     super(NoisyLander, self).__init__()
     
     EzPickle.__init__(self)
     self.seed()
     self.viewer = None
 
     self.world = Box2D.b2World()
     self.moon = None
     self.lander = None
     self.particles = []
 
     self.prev_reward = None
 
     # useful range is -1 .. +1, but spikes can be higher
     self.observation_space = spaces.Box(-np.inf, np.inf, shape=(8,), dtype=np.float32)
 
     if self.continuous:
         # Action is two floats [main engine, left-right engines].
         # Main engine: -1..0 off, 0..+1 throttle from 50% to 100% power. Engine can't work with less than 50% power.
         # Left-right:  -1.0..-0.5 fire left engine, +0.5..+1.0 fire right engine, -0.5..0.5 off
         self.action_space = spaces.Box(-1, +1, (2,), dtype=np.float32)
     else:
         # Nop, fire left engine, main engine, right engine
         self.action_space = spaces.Discrete(4)
 
     self.reset()
    def __init__(self):
        EzPickle.__init__(self)
        self.seed()
        self.viewer = None

        self.world = Box2D.b2World()
        self.terrain = None
        self.hull = None

        self.prev_shaping = None

        self.fd_polygon = fixtureDef(
            shape=polygonShape(vertices=[(0, 0), (1, 0), (1, -1), (0, -1)]),
            friction=FRICTION)

        self.fd_edge = fixtureDef(
            shape=edgeShape(vertices=[(0, 0), (1, 1)]),
            friction=FRICTION,
            categoryBits=0x0001,
        )

        self.reset()

        high = np.array([np.inf] * 24)
        self.action_space = spaces.Box(np.array([-1, -1, -1, -1]),
                                       np.array([1, 1, 1, 1]),
                                       dtype=np.float32)
        self.observation_space = spaces.Box(-high, high, dtype=np.float32)
Beispiel #25
0
    def __init__(self):

        # load ROS params
        global WINDOW_W
        global WINDOW_H
        global VIDEO_W
        global VIDEO_H

        WINDOW_W = rospy.get_param('/car_racing/window_w', 1200)
        WINDOW_H = rospy.get_param('/car_racing/window_h', 1000)
        VIDEO_W = rospy.get_param('/car_racing/video_w', 600)
        VIDEO_H = rospy.get_param('/car_racing/video_h', 400)

        self._seed()
        self.contactListener_keepref = FrictionDetector(self)
        self.world = Box2D.b2World((0,0), contactListener=self.contactListener_keepref)
        self.viewer = None
        self.invisible_state_window = None
        self.invisible_video_window = None
        self.road = None
        self.car = None
        self.reward = 0.0
        self.prev_reward = 0.0

        self.action_space = spaces.Box( np.array([-1,0,0]), np.array([+1,+1,+1]))  # steer, gas, brake
        self.observation_space = spaces.Box(low=0, high=255, shape=(STATE_H, STATE_W, 3))
    def __init__(self):

        # load ROS params
        global WINDOW_W
        global WINDOW_H
        global VIDEO_W
        global VIDEO_H

        WINDOW_W = rospy.get_param('/car_racing/window_w', 1200)
        WINDOW_H = rospy.get_param('/car_racing/window_h', 1000)
        VIDEO_W = rospy.get_param('/car_racing/video_w', 600)
        VIDEO_H = rospy.get_param('/car_racing/video_h', 400)

        self._seed()
        self.contactListener_keepref = FrictionDetector(self)
        self.world = Box2D.b2World(
            (0, 0), contactListener=self.contactListener_keepref)
        self.viewer = None
        self.invisible_state_window = None
        self.invisible_video_window = None
        self.road = None
        self.car = None
        self.reward = 0.0
        self.prev_reward = 0.0

        self.action_space = spaces.Box(np.array([-1, 0, 0]),
                                       np.array([+1, +1,
                                                 +1]))  # steer, gas, brake
        self.observation_space = spaces.Box(low=0,
                                            high=255,
                                            shape=(STATE_H, STATE_W, 3))
Beispiel #27
0
    def reset(self, tree=None, module_list=None):
        self.wod = WallOfDeath(WOD_SPEED)
        self.wod.position = 0.0
        self.tree_morphology = copy.deepcopy(tree)

        self._destroy()
        # Creating the world since not all objects were properly deleted. TODO need to debug this
        self.world = Box2D.b2World()
        self.world.cmap = plt.get_cmap('viridis')
        self.game_over = False
        self.scroll = 0.0
        self.scroll_y = 0.0
        # smooth scroll
        self.prevscroll = 0.0
        self.prevscroll_y = 0.0
        self.scroll_y
        W = VIEWPORT_W / SCALE
        H = VIEWPORT_H / SCALE
        self._generate_terrain(self.hardcore)
        self._generate_clouds()

        init_x = TERRAIN_STEP * TERRAIN_STARTPAD / 2
        init_y = TERRAIN_HEIGHT + 2 * LEG_H
        # will check if the robot position needs to be shifted upward
        lowestY = init_y
        # Fetch the nodes from the tree phenotype
        if (self.tree_morphology is not None):
            nodes = self.tree_morphology.getNodes()
            # create a robot from these nodes
            self.create_robot(nodes, module_list)
            self.drawlist = self.terrain + self.robot.components + self.robot.joints
        else:
            self.drawlist = self.terrain
        return
Beispiel #28
0
    def __init__(self, obstacle_prob, verbose=1, sensors_activated=True):
        EzPickle.__init__(self)
        self.obstacles_positions = [
        ]  # sera rempli de 4-tuples contenant la position de chaque mur
        self.seed()
        self.contactListener_keepref = FrictionDetector(self)
        self.world = Box2D.b2World(
            (0, 0), contactListener=self.contactListener_keepref)
        self.viewer = None
        self.invisible_state_window = None
        self.invisible_video_window = None
        self.road = None
        self.car = None
        self.reward = 0.0
        self.prev_reward = 0.0
        self.times_succeeded = 0
        self.verbose = verbose
        self.sensors_activated = sensors_activated
        self.fd_tile = fixtureDef(shape=polygonShape(
            vertices=[(0, 0), (1, 0), (1, -1), (0, -1)]))

        self.action_space = spaces.Box(np.array([-1, 0, 0]),
                                       np.array([+1, +1, +1]),
                                       dtype=np.float32)  # steer, gas, brake

        self.observation_space = spaces.Box(low=0,
                                            high=255,
                                            shape=(STATE_H, STATE_W, 3),
                                            dtype=np.uint8)
        self.random_obs = 0
        global OBSTACLE_PROB
        OBSTACLE_PROB = obstacle_prob
Beispiel #29
0
    def load(self):
        # Load world map
#        fp = file(worldCfgFilename, 'r')
#        self.worldCfg = bunch.bunchify(json.load(fp))
#        fp.close()
#        # Configure the simulation parameters
#        self.timestep = self.worldCfg.solver.timestep
#        self.velocityIterations = self.worldCfg.solver.velocityIterations
#        self.positionIterations = self.worldCfg.solver.positionIterations
        # Load world geometry
        fp = file(self.worldCfg.geometryFilename, 'rb')
        geometry = np.load(fp).transpose()
        fp.close()
        # Set world parameters
        self.width, self.height = geometry.shape
        # Create the dynamics world
        self.world = b2.b2World((0,0))
        # Load static objects
        for name, objCfg in self.worldCfg.objects.static.items():
            self.staticObjects[name] = staticobject.StaticObject()
            self.staticObjects[name].configure(objCfg)
            self.loadStaticObject(geometry, self.staticObjects[name])
        # Load dynamics objects
#        for name, objCfg in self.worldCfg.objects.dynamic.items():
#            self.dynamicObjects[name] = dynamicobject.DynamicObject(name, objCfg)
#            self.loadDynamicObject(geometry, self.dynamicObjects[name])
        for name, agentCfg in self.worldCfg.objects.agents.items():
            self.agents[name] = agent.Agent(name)
            self.agents[name].construct(self.world, agentCfg)

        # Set up collision handling
        self.contactListener = WorldContactListener()
        self.world.contactListener = self.contactListener
        return True
Beispiel #30
0
    def __init__(self, random_seed=None):
        self.robot_components = []
        self.drawlist = []
        EzPickle.__init__(self)
        self.seed(random_seed)
        self.viewer = None
        self.tree_morphology = None
        self.scroll = 0  # 12-VIEWPORT_W/SCALE/5
        self.scroll_y = 0
        self.robot = None
        self.world = Box2D.b2World()
        self.terrain = None
        self.hull = None
        self.wod = None
        self.prev_shaping = None

        self.fd_polygon = fixtureDef(
            shape=polygonShape(vertices=[(0, 0), (1, 0), (1, -1), (0, -1)]),
            friction=FRICTION)

        self.fd_edge = fixtureDef(
            shape=edgeShape(vertices=[(0, 0), (1, 1)]),
            friction=FRICTION,
            categoryBits=0x0001,
        )

        high = np.array([np.inf] * 24)
        self.action_space = spaces.Box(np.array([-1, -1, -1, -1]),
                                       np.array([1, 1, 1, 1]),
                                       dtype=np.float32)
        self.observation_space = spaces.Box(-high, high, dtype=np.float32)
Beispiel #31
0
    def __init__(self):
        self.seed()
        self.viewer = None

        self.world = Box2D.b2World()
        self.terrain = None
        self.hull = None

        self.prev_shaping = None

        self.fd_polygon = fixtureDef(
                        shape = polygonShape(vertices=
                        [(0, 0),
                         (1, 0),
                         (1, -1),
                         (0, -1)]),
                        friction = FRICTION)

        self.fd_edge = fixtureDef(
                    shape = edgeShape(vertices=
                    [(0, 0),
                     (1, 1)]),
                    friction = FRICTION,
                    categoryBits=0x0001,
                )

        self.reset()

        high = np.array([np.inf]*24)
        self.action_space = spaces.Box(np.array([-1,-1,-1,-1]), np.array([+1,+1,+1,+1]))
        self.observation_space = spaces.Box(-high, high)
Beispiel #32
0
    def __init__(self):
        # initiate a 2dbox world
        self.world = b2.b2World(gravity=(0, -10), doSleep=True)
        # self.world.contactListener = self
        # # Introduce traffic map

        # self.map_scale = OBS_SCALE   # map px per meters. set it to OBS_SCALE so no resizing necessary when getting observation

        # contours = self.loadMap()
        # num_contour = len(contours)
        # print("num", num_contour)
        # obstacles = []

        # for contour in contours:
        #     vertices = []
        #     for item in contour:
        #         new_vec = b2.b2Vec2(float(item[0][0]), float(item[0][1]))
        #         vertices.append(new_vec)
        #     print("vertices")
        #     print(vertices)
        #     contour_shape = b2.b2PolygonShape(vertices=vertices)
        #     obstacle = self.world.CreateStaticBody(position=(0,0), shapes=contour_shape)
        #     obstacles.append(obstacle)

        ground = self.world.CreateBody(position=(0, 0))
        ground.CreateEdgeChain([(-GROUND_EDGE, -GROUND_EDGE),
                                (-GROUND_EDGE, GROUND_EDGE),
                                (GROUND_EDGE, GROUND_EDGE),
                                (GROUND_EDGE, -GROUND_EDGE),
                                (-GROUND_EDGE, -GROUND_EDGE)])
        '''s
Beispiel #33
0
    def __init__(self):
        self.seed()
        self.viewer = None

        self.world = Box2D.b2World(gravity=Box2D.b2Vec2(0,0))
        self.terrain = None
        self.hull = None

        self.prev_shaping = None

        self.fd_polygon = fixtureDef(
                        shape = polygonShape(vertices=
                        [(0, 0),
                         (1, 0),
                         (1, -1),
                         (0, -1)]),
                        friction = FRICTION)

        self.fd_edge = fixtureDef(
                    shape = edgeShape(vertices=
                    [(0, 0),
                     (1, 1)]),
                    friction = FRICTION,
                    categoryBits=0x0001,
                )

        high = np.array([np.inf]*24)
        self.observation_space = spaces.Box(-high, high)

        self.reset()

        self.action_space = spaces.Box(
            np.array([-1]*len(self.joints)), np.array([+1]*len(self.joints)))
Beispiel #34
0
    def __init__(self, frame_skip, verbose=False):
        EzPickle.__init__(self)

        if frame_skip < 1:
            raise ValueError("The value of frame_skip must be at least 1")

        self.seed()
        self.contactListener_keepref = FrictionDetector(self)
        self.world = Box2D.b2World((0,0), contactListener=self.contactListener_keepref)
        self.viewer = None
        self.invisible_state_window = None
        self.invisible_video_window = None
        self.road = None
        self.car = None
        self.reward = 0.0
        self.prev_reward = 0.0
        self.verbose = verbose
        self.fd_tile = fixtureDef(
                shape=polygonShape(vertices=[(0, 0), (1, 0), (1, -1), (0, -1)]))

        self.action_space = spaces.Box(np.array([-1, 0, 0], dtype=np.float32),
                                       np.array([+1, +1, +1], dtype=np.float32),
                                       dtype=np.float32)  # steer, gas, brake

        self.observation_space = spaces.Box(low=0, high=255, shape=(STATE_H, STATE_W, 3), dtype=np.float32)
        self.state = np.zeros([STATE_H, STATE_W, 3], dtype=np.float32)
        self.frame_skip = frame_skip
    def __init__(self):
        EzPickle.__init__(self)
        self.seed(101)
        self.viewer = None

        self.world = Box2D.b2World()
        self.terrain = None
        self.hull = None

        self.prev_shaping = None

        self.counter = self.np_random.randint(1, 3)
        self.velocity_ = self.np_random.uniform(-1, 1)
        self.counter2 = self.np_random.randint(3, 5)
        self.counter3 = self.np_random.randint(TERRAIN_GRASS / 2,
                                               TERRAIN_GRASS)
        self.init_force = self.np_random.uniform(-INITIAL_RANDOM,
                                                 INITIAL_RANDOM)
        self.fd_polygon = fixtureDef(
            shape=polygonShape(vertices=[(0, 0), (1, 0), (1, -1), (0, -1)]),
            friction=FRICTION)

        self.fd_edge = fixtureDef(
            shape=edgeShape(vertices=[(0, 0), (1, 1)]),
            friction=FRICTION,
            categoryBits=0x0001,
        )

        self.reset()

        high = np.array([np.inf] * 24)
        self.action_space = spaces.Box(np.array([-1, -1, -1, -1]),
                                       np.array([1, 1, 1, 1]),
                                       dtype=np.float32)
        self.observation_space = spaces.Box(-high, high, dtype=np.float32)
Beispiel #36
0
    def __init__(self):
        EzPickle.__init__(self)
        self.seed()
        self.viewer = None

        self.world = Box2D.b2World()
        self.moon = None
        self.lander = None
        self.particles = []
        self.terrain_y_values = np.array(
            [1, 2, 3, 2, 5, 1, 2, 4, 5, 3, 1, 1, 3,
             6])  # self.np_random.uniform(0, 400/60, size=(12,) )
        self.goal_x = 8  # len(self.terrain_y_values)//2

        self.prev_reward = None

        # useful range is -1 .. +1, but spikes can be higher
        self.observation_space = spaces.Box(-np.inf,
                                            np.inf,
                                            shape=(8, ),
                                            dtype=np.float32)

        if self.continuous:
            # Action is two floats [main engine, left-right engines].
            # Main engine: -1..0 off, 0..+1 throttle from 50% to 100% power. Engine can't work with less than 50% power.
            # Left-right:  -1.0..-0.5 fire left engine, +0.5..+1.0 fire right engine, -0.5..0.5 off
            self.action_space = spaces.Box(-1, +1, (2, ), dtype=np.float32)
        else:
            # Nop, fire left engine, main engine, right engine
            self.action_space = spaces.Discrete(4)

        self.reset()
Beispiel #37
0
    def __init__(self, env_config):
        self.spec = None
        self.set_env_config(env_config)
        self.env_seed = None
        self._seed()
        self.viewer = None

        self.world = Box2D.b2World()
        self.terrain = None
        self.hull = None

        self.prev_shaping = None
        self.fd_polygon = fixtureDef(
            shape=polygonShape(vertices=[(0, 0),
                                         (1, 0),
                                         (1, -1),
                                         (0, -1)]),
            friction=FRICTION)

        self.fd_edge = fixtureDef(
            shape=edgeShape(vertices=[(0, 0),
                                      (1, 1)]),
            friction=FRICTION,
            categoryBits=0x0001,
        )

        self._reset()

        high = np.array([np.inf] * 24)
        self.action_space = spaces.Box(
            np.array([-1, -1, -1, -1]), np.array([+1, +1, +1, +1]))
        self.observation_space = spaces.Box(-high, high)
Beispiel #38
0
    def __init__(self, hardcore: bool = False):
        EzPickle.__init__(self)
        self.screen = None
        self.clock = None
        self.isopen = True

        self.world = Box2D.b2World()
        self.terrain = None
        self.hull = None

        self.prev_shaping = None

        self.hardcore = hardcore

        self.fd_polygon = fixtureDef(
            shape=polygonShape(vertices=[(0, 0), (1, 0), (1, -1), (0, -1)]),
            friction=FRICTION,
        )

        self.fd_edge = fixtureDef(
            shape=edgeShape(vertices=[(0, 0), (1, 1)]),
            friction=FRICTION,
            categoryBits=0x0001,
        )

        high = np.array([np.inf] * 24).astype(np.float32)
        self.action_space = spaces.Box(
            np.array([-1, -1, -1, -1]).astype(np.float32),
            np.array([1, 1, 1, 1]).astype(np.float32),
        )
        self.observation_space = spaces.Box(-high, high)
Beispiel #39
0
    def __init__(self):
        EzPickle.__init__(self)
        self.seed()
        self.viewer = None

        self.world = Box2D.b2World()
        self.moon = None
        self.lander = None
        self.particles = []

        self.prev_reward = None

        # useful range is -1 .. +1, but spikes can be higher
        self.observation_space = spaces.Box(-np.inf, np.inf, shape=(8,), dtype=np.float32)

        if self.continuous:
            # Action is two floats [main engine, left-right engines].
            # Main engine: -1..0 off, 0..+1 throttle from 50% to 100% power. Engine can't work with less than 50% power.
            # Left-right:  -1.0..-0.5 fire left engine, +0.5..+1.0 fire right engine, -0.5..0.5 off
            self.action_space = spaces.Box(-1, +1, (2,), dtype=np.float32)
        else:
            # Nop, fire left engine, main engine, right engine
            self.action_space = spaces.Discrete(4)

        self.reset()
    def __init__(self):
        EzPickle.__init__(self)
        self.seed()
        self.__contactListener_keepref = ContactListener(self)
        self.__world = Box2D.b2World(
            (0, 0), contactListener=self.__contactListener_keepref)
        self.viewer = None
        self.__robots = []
        self.__robot_name = [ID_R1, ID_B1, ID_R2, ID_B2]
        self.__obstacle = None
        self.__area_buff = None
        self.__projectile = None
        #self.__area_supply = None
        self.__callback_autoaim = callback_capture()

        self.reward = 0.0
        self.prev_reward = 0.0
        self.actions = None
        self.action = [Action(), Action()]
        self.state = None
        self.step_reward = 0
        self.conflict = False

        self.o_ang = 0
        self.o_dis = 8.0
        self.control = False
Beispiel #41
0
 def loadLevel(self, filename):
     self.tileset = Tileset()
     self.tileset.load("media/Tiles.png")
     
     self.b2World = Box2D.b2World( gravity=(0,40), doSleep=True)
     
     #self.player = player.Player( self.b2World, self.em, (100,100) )
     self.player = player.Player( self.b2World, self.em, (game.WIDTH /2, game.HEIGHT - 100))
     self.createChunks(2)
Beispiel #42
0
def initWorld():
	w = Box2D.b2World(gravity=(0,0),
					contactListener=listeners.ContactListener(),
					doSleep=True)

	Box2D.b2.circleShape.draw = debugRenderer.my_draw_circle
	Box2D.b2.polygonShape.draw = debugRenderer.my_draw_polygon

	return w
Beispiel #43
0
 def create_physics_world(self, size):
     # create world
     worldAABB = box2d.b2AABB()
     worldAABB.lowerBound = (-10, -10)
     worldAABB.upperBound = (size[0] + 10, size[1] + 10)
     gravity = box2d.b2Vec2(0.0, 0.0)
     doSleep = True
     world = box2d.b2World(worldAABB, gravity, doSleep)
     return world
Beispiel #44
0
 def to_box2d(self):
     world = Box2D.b2World(allow_sleeping=False)
     if self.gravity:
         world.gravity = self.gravity
     for body in self.bodies:
         body.to_box2d(world, self)
     for joint in self.joints:
         joint.to_box2d(world, self)
     return world
    def __init__(self):
        EzPickle.__init__(self)
        self.seed()
        self.viewer = None

        self.world = Box2D.b2World()
        self.moon = None
        self.landers = None
        self.particles = []
Beispiel #46
0
    def test_b2EdgeShape(self):
        world = b2.b2World()

        v1=(-10.0, 0.0)
        v2=(-7.0, -1.0)
        v3=(-4.0, 0.0)

        ground=world.CreateStaticBody(shapes=
                [b2.b2EdgeShape(vertices=[None, v1, v2, v3])])
    def __init__(self):
        # Box2D Initialization
        self.worldAABB=box2d.b2AABB()
        self.worldAABB.lowerBound = (-200.0, -100.0)
        self.worldAABB.upperBound = ( 200.0, 200.0)
        gravity = (0.0, -10.0)

        doSleep = True
        self.world = box2d.b2World(self.worldAABB, gravity, doSleep)
        self.destructionListener = fwDestructionListener()
        self.boundaryListener = fwBoundaryListener()
        self.contactListener = fwContactListener()
        self.debugDraw = fwDebugDraw()

        self.destructionListener.test = self
        self.boundaryListener.test = self
        self.contactListener.test = self
        
        self.world.SetDestructionListener(self.destructionListener)
        self.world.SetBoundaryListener(self.boundaryListener)
        self.world.SetContactListener(self.contactListener)
        self.world.SetDebugDraw(self.debugDraw)

        # Pygame Initialization
        if fwSettings.onlyInit: # testing mode doesn't initialize pygame
            return

        pygame.init()

        self.screen = pygame.display.set_mode( (640,480) )
        self.debugDraw.surface = self.screen

        self.screenSize = box2d.b2Vec2(*self.screen.get_size())

	caption= "TEST (%3d X %3d) " % (self.screenSize.x, self.screenSize.y) 
        pygame.display.set_caption(caption)

        
        try:
            self.font = pygame.font.Font(None, 15)
        except IOError:
            try:
                self.font = pygame.font.Font("freesansbold.ttf", 15)
            except IOError:
                print "Unable to load default font or 'freesansbold.ttf'"
                print "Disabling text drawing."
                self.DrawString = lambda x,y,z: 0

        # GUI Initialization
        self.gui_app = gui.App()
        self.gui_table=fwGUI(self.settings)
        container = gui.Container(align=1,valign=-1)
        container.add(self.gui_table,0,0)
        self.gui_app.init(container)

        self.viewCenter = (0,10.0*20.0)
Beispiel #48
0
    def constructWorld(self):
        doSleep = False

        worldAABB=b2d.b2AABB()
        worldAABB.lowerBound = (-20, -20)
        worldAABB.upperBound = (self.size[0]+20, self.size[1]+20)
        self.world = b2d.b2World(worldAABB, self.original_gravity, doSleep)

        self.contactListener = ContactListener(self)
        self.world.SetContactListener(self.contactListener)
Beispiel #49
0
 def __init__(self):
     self._seed()
     self.world = Box2D.b2World((0,0), contactListener=FrictionDetector(self))
     self.viewer = None
     self.invisible_state_window = None
     self.invisible_video_window = None
     self.road = None
     self.car = None
     self.reward = 0.0
     self.prev_reward = 0.0
Beispiel #50
0
    def __init__(self):
        self._seed()
        self.viewer = None

        self.world = Box2D.b2World()
        self.terrain = None
        self.hull = None

        self.prev_shaping = None
        self._reset()
def create_world(
        jsw,  # json world
        ):
    return b2.b2World(
        autoClearForces=jsw["autoClearForces"],
        continuousPhysics=jsw["continuousPhysics"],
        gravity=rubeVecToB2Vec2(jsw["gravity"]),
        subStepping=jsw["subStepping"],
        warmStarting=jsw["warmStarting"],
        )
Beispiel #52
0
    def __init__(self, x0, target, render):
        self.render = render
        if self.render:
            super(CarWorld, self).__init__()
        else:
            self.world = b2.b2World(gravity=(0, 0), doSleep=True)

        self.world.gravity = (0.0, 0.0)
        self.initial_position = (x0[0], x0[1])
        self.initial_angle = 0

        ground = self.world.CreateBody(position=(0, 20))
        ground.CreateEdgeChain(
            [(-10, -30),
             (-10, 5),
             (-30, 30),]
            )
	    
        ground.CreateEdgeChain(
            [(10, -30),
             (10, 5),
             (-10, 30),]
            )
	    
        xf1 = b2.b2Transform()
        xf1.angle = 0.3524 * b2.b2_pi
        xf1.position = b2.b2Mul(xf1.R, (1.0, 0.0))

        xf2 = b2.b2Transform()
        xf2.angle = -0.3524 * b2.b2_pi
        xf2.position = b2.b2Mul(xf2.R, (-1.0, 0.0))

        self.car = TDCar(self.world, position=self.initial_position, angle=self.initial_angle)

        self.target = self.world.CreateStaticBody(
            position=target[:2],
            angle=self.initial_angle,
            shapes=[b2.b2PolygonShape(vertices=[xf1*(-1, 0), xf1*(1, 0),
                                                xf1*(0, .5)]),
                    b2.b2PolygonShape(vertices=[xf2*(-1, 0), xf2*(1, 0),
                                                xf2*(0, .5)])],
        )
        self.target.active = False


        self.start = self.world.CreateStaticBody(
            position=self.initial_position,
            angle=self.initial_angle,
            shapes=[b2.b2PolygonShape(vertices=[xf1*(-1, 0), xf1*(1, 0),
                                                xf1*(0, .5)]),
                    b2.b2PolygonShape(vertices=[xf2*(-1, 0), xf2*(1, 0),
                                                xf2*(0, .5)])],
        )
        self.start.active = False
Beispiel #53
0
 def __init__(self):
     self.action_space = spaces.Box( np.array([-1,0,0]), np.array([+1,+1,+1]) )  # steer, gas, brake
     self.observation_space = spaces.Box(low=0, high=255, shape=(STATE_H, STATE_W, 3))
     self.world = Box2D.b2World((0,0), contactListener=FrictionDetector(self))
     self.viewer = None
     self.invisible_state_window = None
     self.invisible_video_window = None
     self.road = None
     self.car = None
     self.reward = 0.0
     self.prev_reward = 0.0
Beispiel #54
0
    def __init__(self):
        self._seed()
        self.viewer = None

        self.world = Box2D.b2World()
        self.moon = None
        self.lander = None
        self.particles = []

        self.prev_reward = None
        self._reset()
Beispiel #55
0
    def __init__(self):
        self.viewer = None

        high = np.array([np.inf]*24)
        self.action_space = spaces.Box( np.array([-1,-1,-1,-1]), np.array([+1,+1,+1,+1]) )
        self.observation_space = spaces.Box(-high, high)

        self.world = Box2D.b2World()
        self.terrain = None
        self.hull = None

        self.prev_shaping = None
        self._reset()
Beispiel #56
0
    def init(width=Game.WINDOW_WIDTH, height=Game.WINDOW_HEIGHT, window_per_world=20.0):

        WorldConfig.WINDOW_PER_WORLD = window_per_world

        worldAABB = box2d.b2AABB()
        worldAABB.lowerBound.Set(0, 0)
        WorldConfig.WORLD_WIDTH= width / window_per_world
        WorldConfig.WORLD_HEIGHT=height/ window_per_world
        
        worldAABB.upperBound.Set(WorldConfig.WORLD_WIDTH, WorldConfig.WORLD_HEIGHT)
        WorldConfig.world = box2d.b2World(worldAABB, WorldConfig.gravity, WorldConfig.doSleep)
        WorldConfig.contactListener = fwContactListener()
        WorldConfig.world.SetContactListener(WorldConfig.contactListener)
Beispiel #57
0
    def __init__(self):
        self.viewer = None

        high = np.array([np.inf, np.inf, np.inf, np.inf, np.inf]) # useful range is -1 .. +1
        self.action_space = spaces.Discrete(4)                    # nop, fire left engine, main engine, right engine
        self.observation_space = spaces.Box(-high, high)

        self.world = Box2D.b2World(contactListener=ContactDetector(self))
        self.moon = None
        self.lander = None
        self.particles = []

        self.prev_reward = None
        self._reset()
 def __init__(self):
     worldAABB=box2d.b2AABB()
     worldAABB.lowerBound = (-8, -8)
     worldAABB.upperBound = (30, 30)
     
     self.world = box2d.b2World(worldAABB, self.gravity, self.doSleep)        
     
     floor_bodyDef = box2d.b2BodyDef()
     floor_bodyDef.position = (14, 8)
     floor_bodyDef.userData = self
     floor_body = self.world.CreateBody(floor_bodyDef)
     floor_shapeDef = box2d.b2PolygonDef()
     floor_shapeDef.SetAsBox(16, 1)
     floor_body.CreateShape(floor_shapeDef)
Beispiel #59
0
 def init_physics(self):
     # Box2D Initialization
     self.worldAABB = box2d.b2AABB()
     self.worldAABB.lowerBound = (-self.window.width*4, -self.window.height*4)
     self.worldAABB.upperBound = (self.window.width*8, self.window.height*8)
     gravity = (0.0, -21.0)
     
     doSleep = True
     self.contact_listener = ContactListener()
     self.world = box2d.b2World(self.worldAABB, gravity, doSleep)
     self.world.SetContactListener(self.contact_listener)
     self.build_map_container()
     self.build_ground()
     self.build_objects()        
     self.weather = Weather(self)
Beispiel #60
0
    def __init__(self):
        EzPickle.__init__(self)
        self.seed()
        self.contactListener_keepref = FrictionDetector(self)
        self.world = Box2D.b2World((0,0), contactListener=self.contactListener_keepref)
        self.viewer = None
        self.invisible_state_window = None
        self.invisible_video_window = None
        self.road = None
        self.car = None
        self.reward = 0.0
        self.prev_reward = 0.0

        self.action_space = spaces.Box( np.array([-1,0,0]), np.array([+1,+1,+1]), dtype=np.float32)  # steer, gas, brake
        self.observation_space = spaces.Box(low=0, high=255, shape=(STATE_H, STATE_W, 3), dtype=np.uint8)