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
def _gen_grid(self, width, height): self.height = height # Create an empty grid self.grid = multigrid.Grid(width, height) # Generate the surrounding walls self.grid.wall_rect(0, 0, width, height) # Place a goal in the bottom-right corner self.place_obj(minigrid.Goal(), max_tries=100) self.place_agent() for i in range(self.n_agents): self.doors[i] = multigrid.Door('grey', is_locked=True) self.place_obj(self.doors[i], max_tries=100) self.keys[i] = minigrid.Key('grey') self.place_obj(self.keys[i], max_tries=100) self.balls[i] = minigrid.Ball('purple') self.place_obj(self.balls[i], max_tries=100) self.boxes[i] = minigrid.Box('green') self.place_obj(self.boxes[i], max_tries=100) self.task_idx = [0] * self.n_agents self.mission = 'Do some random tasks'
def _gen_grid(self, width, height): self.height = height # Create an empty grid self.grid = multigrid.Grid(width, height) # Generate the surrounding walls self.grid.wall_rect(0, 0, width, height) # Place a goal in the bottom-right corner self.put_obj(minigrid.Goal(), width - 2, height - 2) # Create a vertical splitting wall if width <= 5: start_idx = 2 else: start_idx = 3 self.split_idx = self._rand_int(start_idx, width - 2) self.grid.vert_wall(self.split_idx, 0) # Place the agent at a random position and orientation # on the left side of the splitting wall self.place_agent(size=(self.split_idx, height)) # Place a door in the wall door_idx = self._rand_int(1, width - 2) self.put_obj(multigrid.Door('yellow', is_locked=True), self.split_idx, door_idx) # Place a yellow key on the left side self.place_obj(obj=minigrid.Key('yellow'), top=(0, 0), size=(self.split_idx, height)) self.mission = 'Use the key to open the door and then get to the goal'
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