예제 #1
0
파일: car_race_env.py 프로젝트: kubic71/mff
    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
예제 #2
0
파일: main.py 프로젝트: Cosmin013/Facultate
    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()
예제 #3
0
파일: yumi_env.py 프로젝트: contactrika/gym
 def __init__(self, **kwargs):
     default_kwargs = dict(block_gripper=True,
                           reward_type='sparse',
                           distance_threshold=0.05)
     merged = {**default_kwargs, **kwargs}
     super().__init__(task=YumiTask.REACH, **merged)
     EzPickle.__init__(self)
예제 #4
0
 def __init__(self, map_size, reward_args, max_frames, seed):
     EzPickle.__init__(self, map_size, reward_args, max_frames, seed)
     env = magent.GridWorld(get_config(map_size, **reward_args), map_size=map_size)
     self.leftID = 0
     self.rightID = 1
     names = ["red", "blue"]
     super().__init__(env, env.get_handles(), names, map_size, max_frames, seed)
 def __init__(self,
              reward_type='sparse',
              assets_file='slide.xml',
              eval_args=None):
     '''
     slide2.xml: deformable
     slide3.xml: normal but with surrounding box
     '''
     initial_qpos = {
         'robot0:slide0': 0.05,
         'robot0:slide1': 0.48,
         'robot0:slide2': 0.0,
         'object0:joint': [1.32441906, 0.75018422, 0.5, 1., 0., 0., 0.],
     }
     self.max_angle = 25. / 180. * np.pi
     self.eval_args = eval_args
     FetchEnv.__init__(self,
                       'fetch/{}'.format(assets_file),
                       has_object=True,
                       block_gripper=True,
                       n_substeps=20,
                       gripper_extra_height=-0.02,
                       target_in_the_air=False,
                       target_offset=np.array([0.4, 0.0, 0.0]),
                       obj_range=0.1,
                       target_range=0.3,
                       distance_threshold=0.05,
                       initial_qpos=initial_qpos,
                       reward_type=reward_type)
     EzPickle.__init__(self)
예제 #6
0
    def __init__(self, observation_size, action_size,
                 initial_random_force=30,
                 out_of_bounds_penalty=100,
                 max_steps=1000,
                 max_angle=45,
                 bounds=10,
                 initial_altitude=10):

        EzPickle.__init__(self)
        self.seed()
        self.viewer = None
        self.pose = None
        self.action_size = action_size

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

        # Action is two floats [throttle, roll]
        self.action_space = spaces.Box(-1,
                                       +1,
                                       (action_size,),
                                       dtype=np.float32)

        # Pre-convert max-angle degrees to radians
        self.max_angle = np.radians(max_angle)

        # Grab remaining settings
        self.initial_random_force = initial_random_force
        self.out_of_bounds_penalty = out_of_bounds_penalty
        self.max_steps = max_steps
        self.bounds = bounds
        self.initial_altitude = initial_altitude
예제 #7
0
파일: car_racing.py 프로젝트: aysaha/gym
 def __init__(self, seed=None, verbose=0):
     EzPickle.__init__(self)
     #self.contactListener_keepref = FrictionDetector(self)
     #self.world = Box2D.b2World((0,0), contactListener=self.contactListener_keepref)
     self.world = Box2D.b2World((0, 0))
     self.id = self.seed(seed=seed)
     self.viewer = None
     self.invisible_state_window = None
     self.invisible_video_window = None
     self.labels = []
     self.road = None
     self.car = None
     self.dt = 1.0 / FPS
     self.action = np.zeros((3, ))
     self.state = np.zeros((11, ))
     self.reward = 0.0
     self.prev_reward = 0.0
     self.verbose = verbose
     self.track_width = TRACK_WIDTH
     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)
     self.observation_space = spaces.Box(low=-np.inf,
                                         high=np.inf,
                                         shape=(11, ),
                                         dtype=np.float32)
    def __init__(self):
        EzPickle.__init__(self)
        self.seed(5)
        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)

        self.laps = 0
        self.on_road = True
        self.ctrl_pts = None
        self.outward_vectors = None
        self.angles = None
        self.angle_deltas = None
        self.original_road_poly = None
        self.indices = None
        self.my_state = State()
        self.next_road_tile = 0
예제 #9
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()
예제 #10
0
    def __init__(self, env_config):
        EzPickle.__init__(self)
        self.seed()
        self.viewer = None

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

        self.prev_shaping = None

        self.env_config = env_config
        self.low_friction = env_config["nuisance"]["low"]
        self.high_friction = env_config["nuisance"]["high"]
        self.friction = env_config["nuisance"].get("value", None)

        self.reset()

        high = np.array([np.inf] * 24)
        self.observation_space = spaces.Box(np.append([self.low_friction],
                                                      -high),
                                            np.append([self.high_friction],
                                                      high),
                                            dtype=np.float32)

        self.action_space = spaces.Box(np.array([-1, -1, -1, -1]),
                                       np.array([1, 1, 1, 1]),
                                       dtype=np.float32)
예제 #11
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
예제 #12
0
파일: lunar_lander.py 프로젝트: pmcs/gym
    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()
예제 #13
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)
    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
예제 #15
0
파일: point_mass.py 프로젝트: yijiezh/BEAR
    def __init__(self,
                 goal_reward=10,
                 actuation_cost_coeff=30.0,
                 distance_cost_coeff=1.0,
                 init_sigma=0.1):
        EzPickle.__init__(**locals())

        self.dynamics = PointDynamics(dim=2, sigma=0)
        self.init_mu = np.zeros(2, dtype=np.float32)
        self.init_sigma = init_sigma
        self.goal_positions = np.array((
            (-5, 0),
            (5, 0),
            (0, 5),
            (0, -5),
        ),
                                       dtype=np.float32)
        self.goal_threshold = 1.0
        self.goal_reward = goal_reward
        self.action_cost_coeff = actuation_cost_coeff
        self.distance_cost_coeff = distance_cost_coeff
        self.xlim = (-7, 7)
        self.ylim = (-7, 7)
        self.vel_bound = 1.
        self.reset()
        self.observation = None

        self._ax = None
        self._env_lines = []
        self.fixed_plots = None
        self.dynamic_plots = []
    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)
예제 #17
0
    def __init__(self, net, graph: tf.Graph, mixfrac=1.0, maxiter=25):
        EzPickle.__init__(self, net, mixfrac, maxiter)
        self.net = net
        self.mixfrac = mixfrac

        self.x_nx = net.input

        ypred_ny = net
        with graph.as_default():
            ytarg_ny = tf.placeholder(dtype=ypred_ny.dtype,
                                      shape=(None, None))  # T.matrix("ytarg")
        var_list = net.trainable_weights
        l2 = 1e-3 * tf.add_n([tf.reduce_sum(tf.square(v)) for v in var_list])
        N = tf.cast(tf.shape(self.x_nx)[0], dtype=tf.float32)
        mse = tf.reduce_sum(tf.square(ytarg_ny - ypred_ny)) / N
        symb_args = [self.x_nx, ytarg_ny]
        loss = mse + l2
        self.opt = optimizers.LbfgsOptimizer(loss,
                                             var_list,
                                             symb_args,
                                             maxiter=maxiter,
                                             extra_losses={
                                                 "mse": mse,
                                                 "l2": l2
                                             })
예제 #18
0
    def __init__(self, verbose=1, lap_complete_percent=0.95):
        EzPickle.__init__(self)
        pygame.init()
        self.contactListener_keepref = FrictionDetector(
            self, lap_complete_percent)
        self.world = Box2D.b2World(
            (0, 0), contactListener=self.contactListener_keepref)
        self.screen = None
        self.clock = None
        self.isopen = True
        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.new_lap = False
        self.fd_tile = fixtureDef(shape=polygonShape(
            vertices=[(0, 0), (1, 0), (1, -1), (0, -1)]))

        # This will throw a warning in tests/envs/test_envs in utils/env_checker.py as the space is not symmetric
        #   or normalised however this is not possible here so ignore
        self.action_space = spaces.Box(
            np.array([-1, 0, 0]).astype(np.float32),
            np.array([+1, +1, +1]).astype(np.float32),
        )  # steer, gas, brake

        self.observation_space = spaces.Box(low=0,
                                            high=255,
                                            shape=(STATE_H, STATE_W, 3),
                                            dtype=np.uint8)
예제 #19
0
    def __init__(self, max_episode_steps=50, reward_type='sparse'):
        initial_qpos = {
            'robot0:slide0': 0.405,
            'robot0:slide1': 0.48,
            'robot0:slide2': 0.0,
            'object0:joint': [1.25, 0.53, 0.4, 1., 0., 0., 0.],
            'pole0:joint': [1.55, 0.53, 0.4, 1., 0, 0., 0.],
        }

        self.object_x_offset = 0.3
        self.object_y_offset = 0.2

        self.pole_x_offset = 0.15
        self.pole_y_offset = 0.0

        fetch_env.FetchEnv.__init__(self,
                                    MODEL_XML_PATH,
                                    has_object=True,
                                    block_gripper=False,
                                    n_substeps=20,
                                    gripper_extra_height=0.2,
                                    target_in_the_air=True,
                                    target_offset=0.0,
                                    obj_range=0.15,
                                    target_range=0.15,
                                    distance_threshold=0.05,
                                    initial_qpos=initial_qpos,
                                    reward_type=reward_type)
        EzPickle.__init__(self)

        self.max_episode_steps = max_episode_steps
예제 #20
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)
예제 #21
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.mixed:
            self.action_space = spaces.Tuple((
                # Main engine - 0-off, 1-on
                spaces.Discrete(2),
                # Left-right:  -1.0..-0.5 fire left engine, +0.5..+1.0 fire right engine, -0.5..0.5 off
                spaces.Box(-1, +1, (1, ), dtype=np.float32),
            ))

        self.reset()
예제 #22
0
    def __init__(self, knock_reward: float = 0.5, gin_reward: float = 1.0):
        EzPickle.__init__(self, knock_reward, gin_reward)
        RLCardBase.__init__(self, "gin-rummy", 2, (5, 52))
        self._knock_reward = knock_reward
        self._gin_reward = gin_reward

        self.env.game.judge.scorer.get_payoff = self._get_payoff
예제 #23
0
    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,
        )

        high = np.array([np.inf] * 28)
        #self.action_space = spaces.Box(np.array([-1, -1, -1, -1]), np.array([1, 1, 1, 1]), dtype=np.float32)
        self.observation_space = gym.spaces.Box(-high, high, dtype=np.float32)

        self.action_space = MultiDiscrete([3, 21, 21, 21, 21])

        #self.observation_shape = (24,)
        #self.observation_space = gym.spaces.Box(low=-high, high=high, shape=self.observation_shape, dtype=np.float32)

        self.valid_actions = []
        self.state_machine = None
        self.reset()
        self.terminal = False
        self.counter = 0
예제 #24
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 = 0.025
        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)
예제 #25
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
예제 #26
0
    def __init__(self, human_control=False, debug=False):
        EzPickle.__init__(self)
        self.seed()

        self.human_control = human_control
        self.debug = debug

        self.viewer = TrialsViewer(self.viewport_width, self.viewport_height)

        self.world = Box2D.b2World()
        self.world.continuousPhysics = False  # seems to affect joint limits
        self.terrain = None

        self.bike = Bike(self.world, self.init_x, self.init_y)

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

        if self.human_control:
            self.move = [False for i in range(4)]
            self.viewer.window.on_key_press = self.key_press
            self.viewer.window.on_key_release = self.key_release

        self._resets = 0
        self.reset()

        high = np.array([np.inf] * (self.lidar_count + 5))
        self.action_space = spaces.Box(np.array([-1, -1, -1]),
                                       np.array([1, 1, 1]),
                                       dtype=np.float32)
        self.observation_space = spaces.Box(-high, high, dtype=np.float32)
예제 #27
0
파일: car_racing.py 프로젝트: pkicki/gym
    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.init_state = (0.0, 0.0, 0.0)
        self.aim_x = 5.0
        self.aim_y = 10.0
        self.aim_th = 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)
예제 #28
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)
예제 #29
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()
예제 #30
0
    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]))
        self.observation_space = spaces.Box(-high, high)
예제 #31
0
    def __init__(self, map_size, reward_args, max_frames):
        EzPickle.__init__(self, map_size, reward_args, max_frames)
        env = magent.GridWorld(load_config(map_size, **reward_args))
        handles = env.get_handles()

        names = ["omnivore"]
        super().__init__(env, handles[1:], names, map_size, max_frames)
예제 #32
0
    def __init__(self):
        EzPickle.__init__(self)
        self.seed()
        self.viewer = None

        self.world = Box2D.b2World()
        self.moon = None
        self.landers = None
        self.particles = []
예제 #33
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)