Exemplo n.º 1
0
    def __init__(self, args):

        self.num_agents = args.num_agents
        self.num_preies = args.num_preies
        self.num_obstacles = args.num_obstacles
        self.scenario_name = args.scenario_name
        self.direction_alpha = args.direction_alpha
        self.use_human_command = args.use_human_command

        register(
            id=self.scenario_name,
            num_agents=self.num_agents,
            num_preies=self.num_preies,
            num_obstacles=self.num_obstacles,
            direction_alpha=self.direction_alpha,
            use_human_command=self.use_human_command,
            entry_point='onpolicy.envs.gridworld.gym_minigrid.envs:HumanEnv')
        self.env = gym.make(self.scenario_name)
        self.max_steps = self.env.max_steps
        print("max step is {}".format(self.max_steps))

        self.observation_space = self.env.observation_space
        self.share_observation_space = self.env.observation_space
        self.action_space = self.env.action_space
Exemplo n.º 2
0
        super().__init__(size=5, agent_start_pos=None, n_obstacles=2)

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 DynamicObstaclesEnv16x16(DynamicObstaclesEnv):
    def __init__(self):
        super().__init__(size=16, n_obstacles=8)

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

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

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

register(
    id='MiniGrid-Dynamic-Obstacles-Random-6x6-v0',
    entry_point='onpolicy.envs.gridworld.gym_minigrid.envs:DynamicObstaclesRandomEnv6x6'
Exemplo n.º 3
0
        self.grid.set(*self.gap_pos, None)

        self.mission = ("avoid the lava and get to the green goal square"
                        if self.obstacle_type == Lava else
                        "find the opening and get to the green goal square")


class LavaGapS5Env(LavaGapEnv):
    def __init__(self):
        super().__init__(size=5)


class LavaGapS6Env(LavaGapEnv):
    def __init__(self):
        super().__init__(size=6)


class LavaGapS7Env(LavaGapEnv):
    def __init__(self):
        super().__init__(size=7)


register(id='MiniGrid-LavaGapS5-v0',
         entry_point='onpolicy.envs.gridworld.gym_minigrid.envs:LavaGapS5Env')

register(id='MiniGrid-LavaGapS6-v0',
         entry_point='onpolicy.envs.gridworld.gym_minigrid.envs:LavaGapS6Env')

register(id='MiniGrid-LavaGapS7-v0',
         entry_point='onpolicy.envs.gridworld.gym_minigrid.envs:LavaGapS7Env')
Exemplo n.º 4
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='onpolicy.envs.gridworld.gym_minigrid.envs:DoorKeyEnv5x5')

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

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

register(
    id='MiniGrid-DoorKey-16x16-v0',
    entry_point='onpolicy.envs.gridworld.gym_minigrid.envs:DoorKeyEnv16x16')
Exemplo n.º 5
0
                         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='onpolicy.envs.gridworld.gym_minigrid.envs:Unlock')
Exemplo n.º 6
0
    def __init__(self):
        super().__init__(size=9, num_crossings=2)


class LavaCrossingS9N3Env(CrossingEnv):
    def __init__(self):
        super().__init__(size=9, num_crossings=3)


class LavaCrossingS11N5Env(CrossingEnv):
    def __init__(self):
        super().__init__(size=11, num_crossings=5)


register(
    id='MiniGrid-LavaCrossingS9N1-v0',
    entry_point='onpolicy.envs.gridworld.gym_minigrid.envs:LavaCrossingEnv')

register(
    id='MiniGrid-LavaCrossingS9N2-v0',
    entry_point='onpolicy.envs.gridworld.gym_minigrid.envs:LavaCrossingS9N2Env'
)

register(
    id='MiniGrid-LavaCrossingS9N3-v0',
    entry_point='onpolicy.envs.gridworld.gym_minigrid.envs:LavaCrossingS9N3Env'
)

register(
    id='MiniGrid-LavaCrossingS11N5-v0',
    entry_point='onpolicy.envs.gridworld.gym_minigrid.envs:LavaCrossingS11N5Env'
Exemplo n.º 7
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='onpolicy.envs.gridworld.gym_minigrid.envs:RedBlueDoorEnv6x6')

register(
    id='MiniGrid-RedBlueDoors-8x8-v0',
    entry_point='onpolicy.envs.gridworld.gym_minigrid.envs:RedBlueDoorEnv')
Exemplo n.º 8
0
        if self.carrying:
            if self.carrying.color == self.targetColor and \
               self.carrying.type == self.targetType:
                reward = self._reward()
                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='onpolicy.envs.gridworld.gym_minigrid.envs:FetchEnv5x5N2')

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

register(id='MiniGrid-Fetch-8x8-N3-v0',
         entry_point='onpolicy.envs.gridworld.gym_minigrid.envs:FetchEnv')
Exemplo n.º 9
0
    def step(self, action):
        obs, reward, done, info = MiniGridEnv.step(self, action)

        ax, ay = self.agent_pos
        tx, ty = self.target_pos

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

        # Reward performing the done action next to the target object
        if action == self.actions.done:
            if abs(ax - tx) <= 1 and abs(ay - ty) <= 1:
                reward = self._reward()
            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='onpolicy.envs.gridworld.gym_minigrid.envs:GoToObjectEnv')

register(id='MiniGrid-GoToObject-8x8-N2-v0',
         entry_point='onpolicy.envs.gridworld.gym_minigrid.envs:GotoEnv8x8N2')
Exemplo n.º 10
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='onpolicy.envs.gridworld.gym_minigrid.envs:FourRoomsEnv'
)
Exemplo n.º 11
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='onpolicy.envs.gridworld.gym_minigrid.envs:GoToDoorEnv')

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

register(
    id='MiniGrid-GoToDoor-8x8-v0',
    entry_point='onpolicy.envs.gridworld.gym_minigrid.envs:GoToDoor8x8Env')
Exemplo n.º 12
0
class EmptyEnv6x6(EmptyEnv):
    def __init__(self, **kwargs):
        super().__init__(size=6, **kwargs)


class EmptyRandomEnv6x6(EmptyEnv):
    def __init__(self):
        super().__init__(size=6, agent_start_pos=None)


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


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

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

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

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

register(id='MiniGrid-Empty-8x8-v0',
         entry_point='onpolicy.envs.gridworld.gym_minigrid.envs:EmptyEnv')
Exemplo n.º 13
0
                    pos = (self._rand_int(xL + 1, xR - 1), yB)
                    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='onpolicy.envs.gridworld.gym_minigrid.envs:PlaygroundV0')
Exemplo n.º 14
0
        u, v = self.dir_vec
        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='onpolicy.envs.gridworld.gym_minigrid.envs:PutNearEnv')

register(id='MiniGrid-PutNear-8x8-N3-v0',
         entry_point='onpolicy.envs.gridworld.gym_minigrid.envs:PutNear8x8N3')
Exemplo n.º 15
0
            reward = self._reward()
            done = True
        if tuple(self.agent_pos) == self.failure_pos:
            reward = 0
            done = True

        return obs, reward, done, info


class MemoryS17Random(MemoryEnv):
    def __init__(self, seed=None):
        super().__init__(seed=seed, size=17, random_length=True)


register(
    id='MiniGrid-MemoryS17Random-v0',
    entry_point='onpolicy.envs.gridworld.gym_minigrid.envs:MemoryS17Random',
)


class MemoryS13Random(MemoryEnv):
    def __init__(self, seed=None):
        super().__init__(seed=seed, size=13, random_length=True)


register(
    id='MiniGrid-MemoryS13Random-v0',
    entry_point='onpolicy.envs.gridworld.gym_minigrid.envs:MemoryS13Random',
)


class MemoryS13(MemoryEnv):
Exemplo n.º 16
0
        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='onpolicy.envs.gridworld.gym_minigrid.envs:MultiRoomEnvN2S4')

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

register(
    id='MiniGrid-MultiRoom-N6-v0',
    entry_point='onpolicy.envs.gridworld.gym_minigrid.envs:MultiRoomEnvN6')
Exemplo n.º 17
0
        # Add a box to the room on the right
        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

        return obs, reward, done, info


register(
    id='MiniGrid-BlockedUnlockPickup-v0',
    entry_point='onpolicy.envs.gridworld.gym_minigrid.envs:BlockedUnlockPickup'
)
Exemplo n.º 18
0
    def __init__(self, seed=None):
        super().__init__((2, 1), True, True, 1, 4, seed)


class ObstructedMaze_1Q(ObstructedMaze_Full):
    def __init__(self, seed=None):
        super().__init__((1, 1), True, True, 1, 5, seed)


class ObstructedMaze_2Q(ObstructedMaze_Full):
    def __init__(self, seed=None):
        super().__init__((1, 1), True, True, 2, 11, seed)


register(
    id="MiniGrid-ObstructedMaze-1Dl-v0",
    entry_point="onpolicy.envs.gridworld.gym_minigrid.envs:ObstructedMaze_1Dl")

register(
    id="MiniGrid-ObstructedMaze-1Dlh-v0",
    entry_point="onpolicy.envs.gridworld.gym_minigrid.envs:ObstructedMaze_1Dlh"
)

register(
    id="MiniGrid-ObstructedMaze-1Dlhb-v0",
    entry_point="onpolicy.envs.gridworld.gym_minigrid.envs:ObstructedMaze_1Dlhb"
)

register(
    id="MiniGrid-ObstructedMaze-2Dl-v0",
    entry_point="onpolicy.envs.gridworld.gym_minigrid.envs:ObstructedMaze_2Dl")
Exemplo n.º 19
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.agent_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, '
            'unlock the %s door and '
            'go 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='onpolicy.envs.gridworld.gym_minigrid.envs:LockedRoom'
)
Exemplo n.º 20
0
    def __init__(self, seed=None):
        super().__init__(room_size=4, num_rows=3, seed=seed)


class KeyCorridorS5R3(KeyCorridor):
    def __init__(self, seed=None):
        super().__init__(room_size=5, num_rows=3, seed=seed)


class KeyCorridorS6R3(KeyCorridor):
    def __init__(self, seed=None):
        super().__init__(room_size=6, num_rows=3, seed=seed)


register(
    id='MiniGrid-KeyCorridorS3R1-v0',
    entry_point='onpolicy.envs.gridworld.gym_minigrid.envs:KeyCorridorS3R1')

register(
    id='MiniGrid-KeyCorridorS3R2-v0',
    entry_point='onpolicy.envs.gridworld.gym_minigrid.envs:KeyCorridorS3R2')

register(
    id='MiniGrid-KeyCorridorS3R3-v0',
    entry_point='onpolicy.envs.gridworld.gym_minigrid.envs:KeyCorridorS3R3')

register(
    id='MiniGrid-KeyCorridorS4R3-v0',
    entry_point='onpolicy.envs.gridworld.gym_minigrid.envs:KeyCorridorS4R3')

register(
Exemplo n.º 21
0
        # Place the lava rows
        for i in range(self.width - 6):
            self.grid.set(3 + i, 1, Lava())
            self.grid.set(3 + i, self.strip2_row, Lava())

        # Place the agent
        if self.agent_start_pos is not None:
            self.agent_pos = self.agent_start_pos
            self.agent_dir = self.agent_start_dir
        else:
            self.place_agent()

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


class DistShift1(DistShiftEnv):
    def __init__(self):
        super().__init__(strip2_row=2)


class DistShift2(DistShiftEnv):
    def __init__(self):
        super().__init__(strip2_row=5)


register(id='MiniGrid-DistShift1-v0',
         entry_point='onpolicy.envs.gridworld.gym_minigrid.envs:DistShift1')

register(id='MiniGrid-DistShift2-v0',
         entry_point='onpolicy.envs.gridworld.gym_minigrid.envs:DistShift2')