예제 #1
0
    def decode(type_idx, color_idx, state):
        """Create an object from a 3-tuple state description."""

        obj_type = minigrid.IDX_TO_OBJECT[type_idx]
        if obj_type != 'agent':
            color = minigrid.IDX_TO_COLOR[color_idx]

        if obj_type == 'empty' or obj_type == 'unseen':
            return None

        if obj_type == 'wall':
            v = minigrid.Wall(color)
        elif obj_type == 'floor':
            v = minigrid.Floor(color)
        elif obj_type == 'ball':
            v = minigrid.Ball(color)
        elif obj_type == 'key':
            v = minigrid.Key(color)
        elif obj_type == 'box':
            v = minigrid.Box(color)
        elif obj_type == 'door':
            # State, 0: open, 1: closed, 2: locked
            is_open = state == 0
            is_locked = state == 2
            v = Door(color, is_open, is_locked)
        elif obj_type == 'goal':
            v = minigrid.Goal()
        elif obj_type == 'lava':
            v = minigrid.Lava()
        elif obj_type == 'agent':
            v = Agent(color_idx, state)
        else:
            assert False, "unknown object type in decode '%s'" % obj_type

        return v
예제 #2
0
    def decode(type_idx, color_idx, state):
        """Create an object from a 3-tuple state description."""

        obj_type = minigrid.IDX_TO_OBJECT[type_idx]
        if obj_type != "agent":
            color = minigrid.IDX_TO_COLOR[color_idx]

        if obj_type == "empty" or obj_type == "unseen":
            return None

        if obj_type == "wall":
            v = minigrid.Wall(color)
        elif obj_type == "floor":
            v = minigrid.Floor(color)
        elif obj_type == "ball":
            v = minigrid.Ball(color)
        elif obj_type == "key":
            v = minigrid.Key(color)
        elif obj_type == "box":
            v = minigrid.Box(color)
        elif obj_type == "door":
            # State, 0: open, 1: closed, 2: locked
            is_open = state == 0
            is_locked = state == 2
            v = Door(color, is_open, is_locked)
        elif obj_type == "goal":
            v = minigrid.Goal()
        elif obj_type == "lava":
            v = minigrid.Lava()
        elif obj_type == "agent":
            v = Agent(color_idx, state)
        else:
            assert False, "unknown object type in decode '%s'" % obj_type

        return v
예제 #3
0
    def _gen_grid(self, width, height):
        self.grid = multigrid.Grid(width, height)
        self.grid.wall_rect(0, 0, width, height)
        if self.randomize_goal:
            self.place_obj(minigrid.Goal(), max_tries=100)
        else:
            self.put_obj(minigrid.Goal(), width - 2, height - 2)
        for _ in range(self.n_clutter):
            if self.walls_are_lava:
                self.place_obj(minigrid.Lava(), max_tries=100)
            else:
                self.place_obj(minigrid.Wall(), max_tries=100)

        self.place_agent()

        self.mission = 'get to the green square'