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 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): # Create the grid self.grid = minigrid.Grid(width, height) # Generate the surrounding walls self.grid.horz_wall(0, 0) self.grid.horz_wall(0, height - 1) self.grid.vert_wall(0, 0) self.grid.vert_wall(width - 1, 0) wall_loc = self._size - 5 for i in [0, 1, 2, 3, 5, 6, 7]: self.grid.vert_wall(wall_loc, i) self._door = minigrid.Door(self.door_color) self.grid.set(wall_loc, height // 2, self._door) self.grid.set(wall_loc, (height // 2) - 1, self._door) self.grid.set(wall_loc, (height // 2) + 1, self._door) # for i in [1,2,3]: # self.grid.set(width // 2, height // 2 - i, Door(self.door_color)) # self.grid.set(width // 2, height // 2 + i, Door(self.door_color)) # 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 #self.agent_dir = 0 else: self.place_agent(size=(width // 2, height)) #self.agent_dir = 0 ''' if self._goal_default_pos is not None: goal = Goal() self.grid.set(*self._goal_default_pos, goal) goal.init_pos, goal.cur_pos = self._goal_default_pos else: self.place_obj(Goal()) ''' self.mission = 'Reach the goal' # Place obstacles self.obstacles = [] for i_obst in range(self.n_obstacles): self.obstacles.append(minigrid.Ball()) self.place_obj(self.obstacles[i_obst], size=(width // 3, height // 2), max_tries=100) old_pos = self.obstacles[0].cur_pos self.obstacles[0].cur_pos = [self._size // 3, self._size // 2] self.grid.set(*old_pos, None) self._direction = 1
def _gen_grid(self, width, height): self.grid = multigrid.Grid(width, height) self.grid.wall_rect(0, 0, width, height) self.objects = [] self.colors = (np.random.choice(len(minigrid.IDX_TO_COLOR) - 1, size=self.n_colors, replace=False) + 1).tolist() for i in range(self.n_goals): if self.random_colors: color = minigrid.IDX_TO_COLOR[np.random.choice(self.colors)] else: color = minigrid.IDX_TO_COLOR[self.colors[i % self.n_colors]] self.objects.append(minigrid.Ball(color=color)) self.place_obj(self.objects[i], max_tries=100) for _ in range(self.n_clutter): self.place_obj(minigrid.Wall(), max_tries=100) self.place_agent() self.mission = 'pick up objects'