Ejemplo n.º 1
0
    def _add_symbols(self, obs):
        obs = super()._add_symbols(obs)
        obs["sqare_coords"] = self.metadata["square_coords"]
        obs["ball_coords"] = self.metadata["ball_coords"]
        obs["carrying"] = self.carrying
        obs["ball_placed_correctly"] = self.has_ever_been_good
        return obs

    def _is_ball_placed_correctly(self):
        object_goal = self.grid.get(*self.metadata["square_coords"])
        return True if object_goal and object_goal.type == "ball" else False

    def _handle_constraint_violation(self, done):
        constraint_violation = 0
        if done:
            object_goal = self.grid.get(*self.metadata["square_coords"])
            if not object_goal or object_goal.type != "ball":
                constraint_violation += 1
                self.metadata[
                    CONSTRAINT_VIOLATION_COUNT] += constraint_violation
        return constraint_violation

    def reset(self):
        obs = super().reset()
        # self.metadata["ball_coords"] = (1,3)
        return obs


register(
    id='MiniGrid-Ethical5x5Object-v0',
    entry_point='ethical_rl.environments.five_by_five_object:Ethical5x5Object')
Ejemplo n.º 2
0
class MultiRoomEnvN6(MultiRoomEnv):
    def __init__(self):
        super().__init__(minNumRooms=6, maxNumRooms=6)


# class MultiRoomEnvN4r(MultiRoomEnv):
#     def __init__(self):
#         super().__init__(
#             minNumRooms=1,
#             maxNumRooms=5,
#             maxRoomSize=7,
#             grid_size=15
#         )

register(id='MiniGrid-MultiRoom-N2-S4-v0',
         entry_point='gym_minigrid.envs:MultiRoomEnvN2S4',
         reward_threshold=1000.0)

register(id='MiniGrid-MultiRoom-N6-v0',
         entry_point='gym_minigrid.envs:MultiRoomEnvN6',
         reward_threshold=1000.0)

# Own environments:
register(id='MiniGrid-MultiRoom-N5r-v0',
         entry_point='gym_minigrid.envs:MultiRoomEnv',
         reward_threshold=1000.0,
         kwargs={
             'minNumRooms': 1,
             'maxNumRooms': 5,
             'maxRoomSize': 7,
             'grid_size': 15
Ejemplo n.º 3
0
            self.grid.set(*self._agent_default_pos, None)
            self.agent_dir = self._rand_int(
                0, 4)  # assuming random start direction
        else:
            flag = False
            for a in range(50):
                if flag:
                    break
                for b in range(50):
                    if (a, b) not in self.wallss:
                        self.place_agent((a, b))
                        flag = True
                        break

        if self._goal_default_pos is not None:
            goal = Goal()
            self.put_obj(goal, *self._goal_default_pos)
            goal.init_pos, goal.cur_pos = self._goal_default_pos
        else:
            self.place_obj(Goal())

        self.mission = 'Reach the goal'

    def step(self, action):
        obs, reward, done, info = MiniGridEnv.step(self, action)
        return obs, reward, done, info


register(id='MiniGrid-RandomMazeLarge-v0',
         entry_point='gym_minigrid.envs:RandomMazeLarge')
Ejemplo n.º 4
0
class MultiRoomEnvN6(MultiRoomEnv):
    def __init__(self):
        super().__init__(minNumRooms=6, maxNumRooms=6)


# class MultiRoomEnvN4r(MultiRoomEnv):
#     def __init__(self):
#         super().__init__(
#             minNumRooms=1,
#             maxNumRooms=5,
#             maxRoomSize=7,
#             grid_size=15
#         )

register(id='MiniGrid-MultiRoom-N2-S4-v0',
         entry_point='gym_minigrid.envs:MultiRoomEnvN2S4',
         reward_threshold=1000.0)

register(id='MiniGrid-MultiRoom-N6-v0',
         entry_point='gym_minigrid.envs:MultiRoomEnvN6',
         reward_threshold=1000.0)

# Own environments:

register(id='MiniGrid-MultiRoom-N2r-v0',
         entry_point='gym_minigrid.envs:MultiRoomEnv',
         reward_threshold=1000.0,
         kwargs={
             'minNumRooms': 1,
             'maxNumRooms': 2,
             'maxRoomSize': 6,
Ejemplo n.º 5
0
        # Generate the surrounding walls
        self.grid.wall_rect(0, 0, width, height)

        # Place the agent in the top-left corner
        self.start_pos = (1, 1)
        self.start_dir = 0

        # Place a goal square in the bottom-right corner
        self.grid.set(width - 2, height - 2, Goal())

        self.mission = "get to the green goal square"


class EmptyEnv6x6(EmptyEnv):
    def __init__(self):
        super().__init__(size=6)


class EmptyEnv16x16(EmptyEnv):
    def __init__(self):
        super().__init__(size=16)


register(id='MiniGrid-Empty-6x6-v0',
         entry_point='gym_minigrid.envs:EmptyEnv6x6')

register(id='MiniGrid-Empty-8x8-v0', entry_point='gym_minigrid.envs:EmptyEnv')

register(id='MiniGrid-Empty-16x16-v0',
         entry_point='gym_minigrid.envs:EmptyEnv16x16')
Ejemplo n.º 6
0
        obs, reward, done, info = MiniGridEnv.step(self, action)

        ax, ay = self.agentPos
        tx, ty = self.targetPos

        # Toggle/pickup action terminates the episode
        if action == self.actions.toggle:
            done = True

        # Reward performing the wait action next to the target object
        if action == self.actions.wait:
            if abs(ax - tx) <= 1 and abs(ay - ty) <= 1:
                reward = 1
            done = True

        return obs, reward, done, info

class GotoEnv8x8N2(GoToObjectEnv):
    def __init__(self):
        super().__init__(size=8, numObjs=2)

register(
    id='MiniGrid-GoToObject-6x6-N2-v0',
    entry_point='gym_minigrid.envs:GoToObjectEnv'
)

register(
    id='MiniGrid-GoToObject-8x8-N2-v0',
    entry_point='gym_minigrid.envs:GotoEnv8x8N2'
)
Ejemplo n.º 7
0
class EmptyEnvNxN(EmptyEnv):
    def __init__(self, size=None, start=None, goal=None, four_corners=False):
        '''
        if _agent_start_pos == None:
            _agent_start_pos_ = ((_size+1)/2 , (_size+1)/2)
        if _goal_pos=None:
            _goal_pos = (_size - 2, _size - 2)
        '''
        super().__init__(size=size + 2,
                         agent_start_pos=start,
                         goal_pos=goal,
                         four_corners=four_corners)


register(id='MiniGrid-Empty-NxN-v0',
         entry_point='gym_minigrid.envs:EmptyEnvNxN')
register(id='MiniGrid-Empty-5x5-v0',
         entry_point='gym_minigrid.envs:EmptyEnv5x5')

register(id='MiniGrid-Empty-Random-5x5-v0',
         entry_point='gym_minigrid.envs:EmptyRandomEnv5x5')

register(id='MiniGrid-Empty-6x6-v0',
         entry_point='gym_minigrid.envs:EmptyEnv6x6')

register(id='MiniGrid-Empty-Random-6x6-v0',
         entry_point='gym_minigrid.envs:EmptyRandomEnv6x6')

register(id='MiniGrid-Empty-8x8-v0', entry_point='gym_minigrid.envs:EmptyEnv')

register(id='MiniGrid-Empty-16x16-v0',
Ejemplo n.º 8
0
        ox, oy = (self.agent_pos[0] + u, self.agent_pos[1] + v)
        tx, ty = self.target_pos

        # If we picked up the wrong object, terminate the episode
        if action == self.actions.pickup and self.carrying:
            if self.carrying.type != self.move_type or self.carrying.color != self.moveColor:
                done = True

        # If successfully dropping an object near the target
        if action == self.actions.drop and preCarrying:
            if self.grid.get(ox, oy) is preCarrying:
                if abs(ox - tx) <= 1 and abs(oy - ty) <= 1:
                    reward = self._reward()
            done = True

        return obs, reward, done, info

class PutNear8x8N3(PutNearEnv):
    def __init__(self):
        super().__init__(size=8, numObjs=3)

register(
    id='MiniGrid-PutNear-6x6-N2-v0',
    entry_point='gym_minigrid.envs:PutNearEnv'
)

register(
    id='MiniGrid-PutNear-8x8-N3-v0',
    entry_point='gym_minigrid.envs:PutNear8x8N3'
)
Ejemplo n.º 9
0
            if success:
                break

        return True


class MultiRoomEnvN2S4(MultiRoomEnv):
    def __init__(self):
        super().__init__(minNumRooms=2, maxNumRooms=2, maxRoomSize=4)


class MultiRoomEnvN4S5(MultiRoomEnv):
    def __init__(self):
        super().__init__(minNumRooms=4, maxNumRooms=4, maxRoomSize=5)


class MultiRoomEnvN6(MultiRoomEnv):
    def __init__(self):
        super().__init__(minNumRooms=6, maxNumRooms=6)


register(id='MiniGrid-MultiRoom-N2-S4-v0',
         entry_point='gym_minigrid.envs:MultiRoomEnvN2S4')

register(id='MiniGrid-MultiRoom-N4-S5-v0',
         entry_point='gym_minigrid.envs:MultiRoomEnvN4S5')

register(id='MiniGrid-MultiRoom-N6-v0',
         entry_point='gym_minigrid.envs:MultiRoomEnvN6')
Ejemplo n.º 10
0
        # Select a random room to contain the key
        while True:
            keyRoom = self._rand_elem(self.rooms)
            if keyRoom != lockedRoom:
                break
        keyPos = keyRoom.rand_pos(self)
        self.grid.set(*keyPos, Key(lockedRoom.color))

        # Randomize the player start position and orientation
        self.start_pos = self.place_agent(
            top=(lWallIdx, 0),
            size=(rWallIdx-lWallIdx, height)
        )

        # Generate the mission string
        self.mission = (
            'get the %s key from the %s room, '
            'then use it to unlock the %s door '
            'so you can get to the goal'
        ) % (lockedRoom.color, keyRoom.color, lockedRoom.color)

    def step(self, action):
        obs, reward, done, info = MiniGridEnv.step(self, action)
        return obs, reward, done, info

register(
    id='MiniGrid-LockedRoom-v0',
    entry_point='gym_minigrid.envs:LockedRoom'
)
Ejemplo n.º 11
0
                break

        return True

class MultiRoomEnvN2S4(MultiRoomEnv):
    def __init__(self):
        super().__init__(
            minNumRooms=2,
            maxNumRooms=2,
            maxRoomSize=4
        )

class MultiRoomEnvN6(MultiRoomEnv):
    def __init__(self):
        super().__init__(
            minNumRooms=6,
            maxNumRooms=6
        )

register(
    id='MiniGrid-MultiRoom-N2-S4-v0',
    entry_point='gym_minigrid.envs:MultiRoomEnvN2S4',
    reward_threshold=1000.0
)

register(
    id='MiniGrid-MultiRoom-N6-v0',
    entry_point='gym_minigrid.envs:MultiRoomEnvN6',
    reward_threshold=1000.0
)
Ejemplo n.º 12
0
        # Reward performing done action in front of the target door
        if action == self.actions.done:
            if (ax == tx and abs(ay - ty) == 1) or (ay == ty and abs(ax - tx) == 1):
                reward = self._reward()
            done = True

        return obs, reward, done, info

class GoToDoor8x8Env(GoToDoorEnv):
    def __init__(self):
        super().__init__(size=8)

class GoToDoor6x6Env(GoToDoorEnv):
    def __init__(self):
        super().__init__(size=6)

register(
    id='MiniGrid-GoToDoor-5x5-v0',
    entry_point='gym_minigrid.envs:GoToDoorEnv'
)

register(
    id='MiniGrid-GoToDoor-6x6-v0',
    entry_point='gym_minigrid.envs:GoToDoor6x6Env'
)

register(
    id='MiniGrid-GoToDoor-8x8-v0',
    entry_point='gym_minigrid.envs:GoToDoor8x8Env'
)
Ejemplo n.º 13
0
        self.mission = "use the key to open the door and then get to the goal"

class DoorKeyEnv5x5(DoorKeyEnv):
    def __init__(self):
        super().__init__(size=5)

class DoorKeyEnv6x6(DoorKeyEnv):
    def __init__(self):
        super().__init__(size=6)

class DoorKeyEnv16x16(DoorKeyEnv):
    def __init__(self):
        super().__init__(size=16)

register(
    id='MiniGrid-DoorKey-5x5-v0',
    entry_point='gym_minigrid.envs:DoorKeyEnv5x5'
)

register(
    id='MiniGrid-DoorKey-6x6-v0',
    entry_point='gym_minigrid.envs:DoorKeyEnv6x6'
)

register(
    id='MiniGrid-DoorKey-8x8-v0',
    entry_point='gym_minigrid.envs:DoorKeyEnv'
)

register(
    id='MiniGrid-DoorKey-16x16-v0',
    entry_point='gym_minigrid.envs:DoorKeyEnv16x16'
Ejemplo n.º 14
0
        self.start_pos = (1, 1)
        self.start_dir = 0

        # Place a goal square in the bottom-right corner
        self.grid.set(width - 2, height - 2, Goal())

        self.mission = "get to the green goal square"

class EmptyEnv6x6(EmptyEnv):
    def __init__(self):
        super().__init__(size=6)

class EmptyEnv16x16(EmptyEnv):
    def __init__(self):
        super().__init__(size=16)

register(
    id='MiniGrid-Empty-6x6-v0',
    entry_point='gym_minigrid.envs:EmptyEnv6x6'
)

register(
    id='MiniGrid-Empty-8x8-v0',
    entry_point='gym_minigrid.envs:EmptyEnv'
)

register(
    id='MiniGrid-Empty-16x16-v0',
    entry_point='gym_minigrid.envs:EmptyEnv16x16'
)
        self._t = 0
        self.state = self.np_random.rand() * 0.5

    def get_state(self):
        return self.state

    def get_signature(self):
        sig = {'agent_pos': np.copy(self.state), 't': copy(self._t)}
        return sig

    def set_signature(self, sig):
        self.state = np.copy(sig['agent_pos'])
        self._t = copy(sig['t'])


register(id='MiniGrid-RiverSwim-continuous-v0',
         entry_point='envs.river_swim_continuous:RiverSwimContinuous')

if __name__ == '__main__':
    fail = [i * 0.1 for i in range(10)]
    for f in fail:
        mdp = RiverSwimContinuous(horizon=40, dim=10, fail=f)
        gamma = 0.99
        num_episodes = 1000
        rets = []
        for i in range(num_episodes):
            ret = 0
            t = 0
            done = False
            s = mdp.reset()
            while not done:
                a = 1
Ejemplo n.º 16
0
    def __init__(self):
        super().__init__(minNumRooms=6, maxNumRooms=6)


class MultiRoomEnvN2S8_noterm_po(MultiRoomEnv):
    def __init__(self):
        super().__init__(minNumRooms=2,
                         maxNumRooms=2,
                         maxRoomSize=8,
                         terminate_at_goal=False,
                         max_steps=1000,
                         partial_obs=True)


register(id='MiniGrid-MultiRoom-N2-S4-v0',
         entry_point='gym_minigrid.envs:MultiRoomEnvN2S4',
         reward_threshold=1000.0)
register(id='MiniGrid-MultiRoom-N2-S8-v0',
         entry_point='gym_minigrid.envs:MultiRoomEnvN2S8',
         reward_threshold=1000.0)
register(id='MiniGrid-MultiRoom-N2-S8-v4',
         entry_point='gym_minigrid.envs:MultiRoomEnvN2S8_po',
         reward_threshold=1000.0)
register(id='MiniGrid-MultiRoom-N2-S8-NT-v0',
         entry_point='gym_minigrid.envs:MultiRoomEnvN2S8_noterm',
         reward_threshold=1000.0)
register(id='MiniGrid-MultiRoom-N2-S8-NT-v4',
         entry_point='gym_minigrid.envs:MultiRoomEnvN2S8_noterm_po',
         reward_threshold=1000.0)
register(id='MiniGrid-MultiRoom-N6-v0',
         entry_point='gym_minigrid.envs:MultiRoomEnvN6',
Ejemplo n.º 17
0
                reward = self._reward()
            done = True

        return obs, reward, done, info


class GoToDoor8x8Env(GoToDoorEnv):
    def __init__(self):
        super().__init__(size=8)


class GoToDoor6x6Env(GoToDoorEnv):
    def __init__(self):
        super().__init__(size=6)


register(
    id='MiniGrid-GoToDoor-5x5-v0',
    entry_point='gym_minigrid.envs:GoToDoorEnv'
)

register(
    id='MiniGrid-GoToDoor-6x6-v0',
    entry_point='gym_minigrid.envs:GoToDoor6x6Env'
)

register(
    id='MiniGrid-GoToDoor-8x8-v0',
    entry_point='gym_minigrid.envs:GoToDoor8x8Env'
)
Ejemplo n.º 18
0
class DoorKeyEnv12x12(DoorKeyEnv):
    def __init__(self):
        super().__init__(size=12)


class DoorKeyEnv14x14(DoorKeyEnv):
    def __init__(self):
        super().__init__(size=14)


class DoorKeyEnv16x16(DoorKeyEnv):
    def __init__(self):
        super().__init__(size=16)


register(id='MiniGrid-DoorKey-5x5-v0',
         entry_point='gym_minigrid.envs:DoorKeyEnv5x5')

register(id='MiniGrid-DoorKey-6x6-v0',
         entry_point='gym_minigrid.envs:DoorKeyEnv6x6')

register(id='MiniGrid-DoorKey-8x8-v0',
         entry_point='gym_minigrid.envs:DoorKeyEnv')

register(id='MiniGrid-DoorKey-16x16-v0',
         entry_point='gym_minigrid.envs:DoorKeyEnv16x16')

register(id='MiniGrid-DoorKey-10x10-v0',
         entry_point='gym_minigrid.envs:DoorKeyEnv10x10')

register(id='MiniGrid-DoorKey-12x12-v0',
         entry_point='gym_minigrid.envs:DoorKeyEnv12x12')
Ejemplo n.º 19
0
                    color = self._rand_elem(COLOR_NAMES)
                    self.grid.set(*pos, Door(color))

        # Randomize the player start position and orientation
        self.place_agent()

        # Place random objects in the world
        types = ['key', 'ball', 'box']
        for i in range(0, 12):
            objType = self._rand_elem(types)
            objColor = self._rand_elem(COLOR_NAMES)
            if objType == 'key':
                obj = Key(objColor)
            elif objType == 'ball':
                obj = Ball(objColor)
            elif objType == 'box':
                obj = Box(objColor)
            self.place_obj(obj)

        # No explicit mission in this environment
        self.mission = ''

    def step(self, action):
        obs, reward, done, info = MiniGridEnv.step(self, action)
        return obs, reward, done, info

register(
    id='MiniGrid-Playground-v0',
    entry_point='gym_minigrid.envs:PlaygroundV0'
)
Ejemplo n.º 20
0
#!/usr/bin/env python3

import time
import random
import argparse
import numpy as np
import gym
import gym_minigrid
from gym_minigrid.wrappers import *
from gym_minigrid.window import Window
from gym_minigrid.register import register
register(id='MiniGrid-Relational-Obstacles-10x10-v0',
         entry_point='env:RelationalObstaclesEnv10x10')
parser = argparse.ArgumentParser()
parser.add_argument("--env",
                    help="gym environment to load",
                    default='MiniGrid-Relational-Obstacles-10x10-v0')
parser.add_argument("--seed",
                    type=int,
                    help="random seed to generate the environment with",
                    default=-1)
parser.add_argument("--tile_size",
                    type=int,
                    help="size at which to render tiles",
                    default=32)
parser.add_argument('--agent_view',
                    default=False,
                    help="draw the agent sees (partially observable view)",
                    action='store_true')

args = parser.parse_args()
Ejemplo n.º 21
0
        if self.carrying and self.carrying.type == 'key' and done is True:
            # delayed reward if carrying key at goal
            reward += self.key_reward

        return obs, reward, done, info


class KeyGoalEnv6x6(KeyGoalEnv):
    def __init__(self):
        super().__init__(size=6, max_steps=10 * 6**2)


class KeyGoalEnv8x8(KeyGoalEnv):
    def __init__(self):
        super().__init__(size=8, max_steps=10 * 8**2)


class KeyGoalEnv10x10(KeyGoalEnv):
    def __init__(self):
        super().__init__(size=10, max_steps=10 * 10**2)


register(id='MiniGrid-KeyGoal-6x6-v0',
         entry_point='gym_minigrid.envs:KeyGoalEnv6x6')

register(id='MiniGrid-KeyGoal-8x8-v0',
         entry_point='gym_minigrid.envs:KeyGoalEnv8x8')

register(id='MiniGrid-KeyGoal-10x10-v0',
         entry_point='gym_minigrid.envs:KeyGoalEnv10x10')
Ejemplo n.º 22
0
                    help="gym environment to load",
                    default='hwft-5e')
parser.add_argument("--seed",
                    type=int,
                    help="random seed to generate the environment with",
                    default=-1)
parser.add_argument("--tile_size",
                    type=int,
                    help="size at which to render tiles",
                    default=32)
parser.add_argument('--agent_view',
                    default=False,
                    help="draw the agent sees (partially observable view)",
                    action='store_true')

args = parser.parse_args()
register(id=env_dict[args.env_name][0], entry_point=env_dict[args.env_name][1])
env = gym.make(env_dict[args.env_name][0])

if args.agent_view:
    env = RGBImgPartialObsWrapper(env)
    env = ImgObsWrapper(env)

window = Window('gym_minigrid - ' + args.env_name)
window.reg_key_handler(key_handler)

reset()

# Blocking event loop
window.show(block=True)
Ejemplo n.º 23
0
class EmptyEnv18x18(EmptyEnv):
    def __init__(self, **kwargs):
        super().__init__(size=18, **kwargs)


class EmptyEnv30x30(EmptyEnv):
    def __init__(self, **kwargs):
        super().__init__(size=30, **kwargs)


class EmptyEnv50x50(EmptyEnv):
    def __init__(self, **kwargs):
        super().__init__(size=50, **kwargs)


register(id='MiniGrid-EmptyCorridor-5x1-v0',
         entry_point='gym_minigrid.envs:EmptyCorridor5x1')

register(id='MiniGrid-EmptyCorridor-10x1-v0',
         entry_point='gym_minigrid.envs:EmptyCorridor10x1')

register(id='MiniGrid-Empty-5x5-v0',
         entry_point='gym_minigrid.envs:EmptyEnv5x5')

register(id='MiniGrid-Empty-InverseGoal-5x5-v0',
         entry_point='gym_minigrid.envs:EmptyEnv5x5InverseGoal')

register(id='MiniGrid-Empty-Random-5x5-v0',
         entry_point='gym_minigrid.envs:EmptyRandomEnv5x5')

register(id='MiniGrid-Empty-6x6-v0',
         entry_point='gym_minigrid.envs:EmptyEnv6x6')
Ejemplo n.º 24
0
        # Set goal
        assert self.goal_pos is not None, "Goal position is None. Call env.reset_task() before env.reset()"
        self.put_obj(Goal(), self.goal_pos[0] + 1, self.goal_pos[1] + 1)

    def _reward(self):
        dist = np.linalg.norm(np.array(self.agent_pos) - self.goal_pos)
        return -dist

    def reset_task(self, task):
        if task is None:
            task = self.np_random.randint(0, self.size - 2, size=(2, ))
        assert len(task) == 2, "Must in format of (col, row)"
        assert task[0] >= 0 and task[0] < self.size - 2
        assert task[1] >= 0 and task[1] < self.size - 2
        self.goal_pos = np.array(task)

    def sample_tasks(self, num_tasks):
        tasks = self.np_random.randint(0, self.size - 2, size=(num_tasks, 2))
        # tasks = self.np_random.randint(1, 2, size=(num_tasks, 2))
        return tasks


class EmptyEnv5x5(EmptyEnv):
    def __init__(self, **kwargs):
        super().__init__(size=5, **kwargs)


register(id='MiniGrid-Empty-5x5-v0',
         entry_point='gym_minigrid.envs:EmptyEnv5x5')
Ejemplo n.º 25
0
                                                 value=value,
                                                 color="blue")

        self.mission = "find the highest reward"

    def reset(self):
        if self.fixed_seed is not None:
            self.seed(1)
        return super().reset()


register(
    id="MiniGrid-MultipleRewardRoomS4R1-v0",
    entry_point="gym_minigrid.envs:MultipleRewardRoom",
    kwargs={
        "room_size": 4,
        "num_rows": 1,
        "fixed_seed": 1
    },
)

register(
    id="MiniGrid-MultipleRewardRoomS4R2-v0",
    entry_point="gym_minigrid.envs:MultipleRewardRoom",
    kwargs={
        "room_size": 4,
        "num_rows": 2,
        "fixed_seed": 1
    },
)
Ejemplo n.º 26
0
class DynamicObstaclesEnv6x6(DynamicObstaclesEnv):
    def __init__(self):
        super().__init__(size=6, n_obstacles=3)


class DynamicObstaclesRandomEnv6x6(DynamicObstaclesEnv):
    def __init__(self):
        super().__init__(size=6, agent_start_pos=None, n_obstacles=3)


class DynamicObstaclesRandomEnv10x10(DynamicObstaclesEnv):
    def __init__(self):
        super().__init__(size=10, agent_start_pos=None, n_obstacles=5)


register(id='MiniGrid-Dynamic-Obstacles-5x5-v0',
         entry_point='gym_minigrid.envs:DynamicObstaclesEnv5x5')

register(id='MiniGrid-Dynamic-Obstacles-Random-5x5-v0',
         entry_point='gym_minigrid.envs:DynamicObstaclesRandomEnv5x5')

register(id='MiniGrid-Dynamic-Obstacles-6x6-v0',
         entry_point='gym_minigrid.envs:DynamicObstaclesEnv6x6')

register(id='MiniGrid-Dynamic-Obstacles-Random-6x6-v0',
         entry_point='gym_minigrid.envs:DynamicObstaclesRandomEnv6x6')

register(id='MiniGrid-Dynamic-Obstacles-8x8-v0',
         entry_point='gym_minigrid.envs:DynamicObstaclesEnv')

register(id='MiniGrid-Dynamic-Obstacles-Random-10x10-v0',
         entry_point='gym_minigrid.envs:DynamicObstaclesRandomEnv10x10')
Ejemplo n.º 27
0
            maxRoomSize=5,
            gridSize=14,
        )


class MultiRoomEnvN4S7Random(MultiRoomEnv):
    def __init__(self):
        super().__init__(
            minNumRooms=1,
            maxNumRooms=4,
            maxRoomSize=7,
            gridSize=13,
        )


register(id='MiniGrid-MultiRoom-N2-S4-v0',
         entry_point='gym_minigrid.envs:MultiRoomEnvN2S4')

register(id='MiniGrid-MultiRoom-N4-S5-v0',
         entry_point='gym_minigrid.envs:MultiRoomEnvN4S5')

register(id='MiniGrid-MultiRoom-N6-v0',
         entry_point='gym_minigrid.envs:MultiRoomEnvN6')

register(id='MiniGrid-MultiRoom-N4-Random-v0',
         entry_point='gym_minigrid.envs:MultiRoomEnvN4Random')

# Custom levels
register(id='MiniGrid-MultiRoom-N4-S7-Random-v0',
         entry_point='gym_minigrid.envs:MultiRoomEnvN4S7Random')

register(id='MiniGrid-MultiRoom-N2-S4-G14-v0',
Ejemplo n.º 28
0
class FetchKeyEnv6x6N5(FetchKeyEnv):
    def __init__(self):
        super().__init__(size=6, numObjs=5)


class FetchKeyEnv8x8N5(FetchKeyEnv):
    def __init__(self):
        super().__init__(size=8, numObjs=5)


class FetchKeyEnv16x16N5(FetchKeyEnv):
    def __init__(self):
        super().__init__(size=16, numObjs=5)


register(id='MiniGrid-fetchKey-5x5-N5-v0',
         entry_point='gym_minigrid.envs:FetchKeyEnv5x5N5')

register(id='MiniGrid-fetchKey-6x6-N5-v0',
         entry_point='gym_minigrid.envs:FetchKeyEnv6x6N5')

register(id='MiniGrid-fetchKey-8x8-N5-v0',
         entry_point='gym_minigrid.envs:FetchKeyEnv8x8N5')

register(id='MiniGrid-fetchKey-16x16-N5-v0',
         entry_point='gym_minigrid.envs:FetchKeyEnv16x16N5')

#############################################################


class FetchKeyEnv5x5N3(FetchKeyEnv):
    def __init__(self):
Ejemplo n.º 29
0
        self.grid.set(width - 2, height - 2, Goal())

        # Place water
        self.grid.set(width - 5, height - 2, Water())

        # Set start position
        self.start_pos = (1, 1)
        self.start_dir = 0

        self.mission = "get to the green goal square without moving on water"


class UnsafeEnv6x6(UnsafeEnv):
    def __init__(self):
        super().__init__(size=6)


class UnsafeEnv16x16(UnsafeEnv):
    def __init__(self):
        super().__init__(size=16)


register(id='MiniGrid-Unsafe-6x6-v0',
         entry_point='gym_minigrid.envs:UnsafeEnv6x6')

register(id='MiniGrid-Unsafe-8x8-v0',
         entry_point='gym_minigrid.envs:UnsafeEnv')

register(id='MiniGrid-Unsafe-16x16-v0',
         entry_point='gym_minigrid.envs:UnsafeEnv16x16')
Ejemplo n.º 30
0
                         num_cols=2,
                         room_size=room_size,
                         max_steps=8 * room_size**2,
                         seed=seed)

    def _gen_grid(self, width, height):
        super()._gen_grid(width, height)

        # Make sure the two rooms are directly connected by a locked door
        door, _ = self.add_door(0, 0, 0, locked=True)
        # Add a key to unlock the door
        self.add_object(0, 0, 'key', door.color)

        self.place_agent(0, 0)

        self.door = door
        self.mission = "open the door"

    def step(self, action):
        obs, reward, done, info = super().step(action)

        if action == self.actions.toggle:
            if self.door.is_open:
                reward = self._reward()
                done = True

        return obs, reward, done, info


register(id='MiniGrid-Unlock-v0', entry_point='gym_minigrid.envs:Unlock')
Ejemplo n.º 31
0
        return obs, reward, done, info

    def _reward(self):
        """
        Reward received upon goal collection
        """
        return 1


class CollectEnv9x9(CollectEnv):
    def __init__(self):
        super().__init__(size=9,
                         agent_start_pos=None,
                         n_goals=15,
                         num_crossings=0)


class CollectEnvStochastic9x9(CollectEnv):
    def __init__(self):
        super().__init__(size=9,
                         agent_start_pos=None,
                         n_goals=15,
                         num_crossings=0,
                         reward_noise=0.15)


register(id='MiniGrid-Collect-9x9-v0',
         entry_point='gym_minigrid.envs:CollectEnv9x9')
register(id='MiniGrid-Collect-Stochastic-9x9-v0',
         entry_point='gym_minigrid.envs:CollectEnvStochastic9x9')
Ejemplo n.º 32
0
        obj, _ = self.add_object(1, 0, kind="box")
        # Make sure the two rooms are directly connected by a locked door
        door, pos = self.add_door(0, 0, 0, locked=True)
        # Block the door with a ball
        color = self._rand_color()
        self.grid.set(pos[0] - 1, pos[1], Ball(color))
        # Add a key to unlock the door
        self.add_object(0, 0, 'key', door.color)

        self.place_agent(0, 0)

        self.obj = obj
        self.mission = "pick up the %s %s" % (obj.color, obj.type)

    def step(self, action):
        obs, reward, done, info = super().step(action)

        if action == self.actions.pickup:
            if self.carrying and self.carrying == self.obj:
                reward = self._reward()
                done = True
        # print("DONE: ", done)
        if done:
            self.count += 1
        print("COUNT: ", self.count)
        return obs, reward, done, info


register(id='MiniGrid-BlockedUnlockPickup-v0',
         entry_point='gym_minigrid.envs:BlockedUnlockPickup')
Ejemplo n.º 33
0
class EmptyGridEnvOmniNoGoal6x6(EmptyEnvNoGoal):
    def __init__(self):
        super().__init__(size=6, mode='grid', action_mode='omni')


class EmptyGridEnvOmniNoGoal8x8(EmptyEnvNoGoal):
    def __init__(self):
        super().__init__(size=8, mode='grid', action_mode='omni')


class EmptyGridEnvOmniNoGoal16x16(EmptyEnvNoGoal):
    def __init__(self):
        super().__init__(size=16, mode='grid', action_mode='omni')


register(id='MiniGrid-Empty-NoGoal-6x6-v0',
         entry_point='gym_minigrid.envs:EmptyEnvNoGoal6x6')

register(id='MiniGrid-Empty-NoGoal-8x8-v0',
         entry_point='gym_minigrid.envs:EmptyEnvNoGoal')

register(id='MiniGrid-Empty-NoGoal-16x16-v0',
         entry_point='gym_minigrid.envs:EmptyEnvNoGoal16x16')

register(id='MiniGrid-Empty-NoGoal-6x6-v1',
         entry_point='gym_minigrid.envs:EmptyGridEnvNoGoal6x6')

register(id='MiniGrid-Empty-NoGoal-8x8-v1',
         entry_point='gym_minigrid.envs:EmptyGridEnvNoGoal')

register(id='MiniGrid-Empty-NoGoal-16x16-v1',
         entry_point='gym_minigrid.envs:EmptyGridEnvNoGoal16x16')
Ejemplo n.º 34
0
        if self.carrying:
            if self.carrying.color == self.targetColor and \
               self.carrying.type == self.targetType:
                reward = 1
                done = True
            else:
                reward = 0
                done = True

        return obs, reward, done, info


class FetchEnv5x5N2(FetchEnv):
    def __init__(self):
        super().__init__(size=5, numObjs=2)


class FetchEnv6x6N2(FetchEnv):
    def __init__(self):
        super().__init__(size=6, numObjs=2)


register(id='MiniGrid-Fetch-5x5-N2-v0',
         entry_point='gym_minigrid.envs:FetchEnv5x5N2')

register(id='MiniGrid-Fetch-6x6-N2-v0',
         entry_point='gym_minigrid.envs:FetchEnv6x6N2')

register(id='MiniGrid-Fetch-8x8-N3-v0',
         entry_point='gym_minigrid.envs:FetchEnv')
Ejemplo n.º 35
0
                if j + 1 < 2:
                    self.grid.horz_wall(xL, yB, room_w)
                    pos = (self._rand_int(xL + 1, xR), yB)
                    self.grid.set(*pos, None)

        # Randomize the player start position and orientation
        if self._agent_default_pos is not None:
            self.agent_pos = self._agent_default_pos
            self.grid.set(*self._agent_default_pos, None)
            self.agent_dir = self._rand_int(0, 4)  # assuming random start direction
        else:
            self.place_agent()

        if self._goal_default_pos is not None:
            goal = Goal()
            self.put_obj(goal, *self._goal_default_pos)
            goal.init_pos, goal.cur_pos = self._goal_default_pos
        else:
            self.place_obj(Goal())

        self.mission = 'Reach the goal'

    def step(self, action):
        obs, reward, done, info = MiniGridEnv.step(self, action)
        return obs, reward, done, info

register(
    id='MiniGrid-FourRooms-v0',
    entry_point='gym_minigrid.envs:FourRoomsEnv'
)
Ejemplo n.º 36
0
        self.mission = "use the key to open the door and then get to the goal"

class DoorKeyEnv5x5(DoorKeyEnv):
    def __init__(self):
        super().__init__(size=5)

class DoorKeyEnv6x6(DoorKeyEnv):
    def __init__(self):
        super().__init__(size=6)

class DoorKeyEnv16x16(DoorKeyEnv):
    def __init__(self):
        super().__init__(size=16)

register(
    id='MiniGrid-DoorKey-5x5-v0',
    entry_point='gym_minigrid.envs:DoorKeyEnv5x5'
)

register(
    id='MiniGrid-DoorKey-6x6-v0',
    entry_point='gym_minigrid.envs:DoorKeyEnv6x6'
)

register(
    id='MiniGrid-DoorKey-8x8-v0',
    entry_point='gym_minigrid.envs:DoorKeyEnv'
)

register(
    id='MiniGrid-DoorKey-16x16-v0',
    entry_point='gym_minigrid.envs:DoorKeyEnv16x16'
Ejemplo n.º 37
0
        # Generate the wall which separate the rooms
        self.grid.vert_wall(3, 0, 5)
        self.grid.horz_wall(0, 4, 5)
        # Place the door which separate the rooms
        self.grid.set(3, 2, Door(self._rand_elem(sorted(set(COLOR_NAMES)))))

        # Place a goal square in the bottom-right corner
        self.grid.set(4, 2, Goal())

        # Add the rooms
        self.roomList = []
        self.roomList.append(Room(0, (width / 2 - 1, height), (0, 0), True))
        self.roomList.append(Room(1, (width, height), (width / 2, 0), False))

        # Set room entry and exit that are needed
        self.roomList[1].setEntryDoor((3, 2))
        self.roomList[0].setExitDoor((3, 2))

        # Add the switch of the second room in the first one
        switchRoom2 = LightSwitch()
        switchRoom2.affectRoom(self.roomList[1])
        self.grid.set(2, 3, switchRoom2)
        self.switchPosition = []
        self.switchPosition.append((2, 3))

        self.mission = "get to the green goal square without moving on water"


register(id='MiniGrid-DoorEnv-10x10-v0',
         entry_point='gym_minigrid.envs:DoorEnv')
Ejemplo n.º 38
0
        blue_door_opened_after = self.blue_door.is_open

        if blue_door_opened_after:
            if red_door_opened_before:
                reward = self._reward()
                done = True
            else:
                reward = 0
                done = True

        elif red_door_opened_after:
            if blue_door_opened_before:
                reward = 0
                done = True

        return obs, reward, done, info

class RedBlueDoorEnv6x6(RedBlueDoorEnv):
    def __init__(self):
        super().__init__(size=6)

register(
    id='MiniGrid-RedBlueDoors-6x6-v0',
    entry_point='gym_minigrid.envs:RedBlueDoorEnv6x6'
)

register(
    id='MiniGrid-RedBlueDoors-8x8-v0',
    entry_point='gym_minigrid.envs:RedBlueDoorEnv'
)