def _gen_grid(self, width, height): """Grid is initially empty, because adversary will create it.""" # Create an empty grid self.grid = multigrid.Grid(width, height) # Generate the surrounding walls self.grid.wall_rect(0, 0, width, height)
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 _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): # Create the grid self.grid = multigrid.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) room_w = width // 2 room_h = height // 2 # For each row of rooms for j in range(0, 2): # For each column for i in range(0, 2): x_left = i * room_w y_top = j * room_h x_right = x_left + room_w y_bottom = y_top + room_h # Vertical wall and door if i + 1 < 2: self.grid.vert_wall(x_right, y_top, room_h) if not (j == 1 and self.two_rooms and height < 7): pos = (x_right, self._rand_int(y_top + 1, y_bottom)) if not (pos[0] <= 1 or pos[0] >= width - 1 or pos[1] <= 0 or pos[1] >= height - 1): self.grid.set(*pos, None) # Horizontal wall and door if not self.two_rooms: if j + 1 < 2: self.grid.horz_wall(x_left, y_bottom, room_w) pos = (self._rand_int(x_left + 1, x_right), y_bottom) if not (pos[0] <= 1 or pos[0] >= width - 1 or pos[1] <= 0 or pos[1] >= height - 1): 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) # random start direction else: self.place_agent() if self._goal_default_pos is not None: goal = minigrid.Goal() self.put_obj(goal, *self._goal_default_pos) goal.init_pos, goal.cur_pos = self._goal_default_pos else: self.place_obj(minigrid.Goal()) self.mission = 'Reach the goal'
def _gen_grid(self, width, height): self.grid = multigrid.Grid(width, height) self.grid.wall_rect(0, 0, width, height) for _ in range(self.n_clutter): self.place_obj(minigrid.Wall(), max_tries=100) self.place_agent() self.mission = 'Play tag'
def _gen_grid(self, width, height): self.grid = multigrid.Grid(width, height) self.grid.wall_rect(0, 0, width, height) for i in range(self.n_goals): 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 coins corresponding to your color'
def _gen_grid(self, width, height): self.grid = multigrid.Grid(width, height) self.grid.wall_rect(0, 0, width, height) for stag in self.stags: self.place_obj(stag, max_tries=100) for plant in self.plants: self.place_obj(plant, max_tries=100) for _ in range(self.n_clutter): self.place_obj(minigrid.Wall(), max_tries=100) self.place_agent() self.mission = 'Toggle the stag at the same time'
def _gen_grid(self, width, height): self.grid = multigrid.Grid(width, height) self.grid.wall_rect(0, 0, width, height) for i in range(self.n_goals): pos = self.place_obj(multigrid.Door(color='red', is_locked=True), max_tries=100) self.goal_pos[i] = pos for _ in range(self.n_clutter): self.place_obj(minigrid.Wall(), max_tries=100) self.place_agent() self.mission = 'meet up'
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): self.place_obj(LavaWall(), max_tries=100) self.place_agent() self.mission = 'get to the green square'
def _gen_grid(self, width, height): # Create an empty grid self.grid = multigrid.Grid(width, height) # Generate the surrounding walls self.grid.wall_rect(0, 0, width, height) if self.randomize_goal: self.place_obj(minigrid.Goal(), max_tries=100) else: # Place a goal square in the bottom-right corner self.put_obj(minigrid.Goal(), width - 2, height - 2) # Place the agents self.place_agent() self.mission = 'get to the green goal square'
def _gen_grid(self, width, height): # Create an empty grid self.grid = multigrid.Grid(width, height) # Generate the surrounding walls self.grid.wall_rect(0, 0, width, height) # Goal self.put_obj(minigrid.Goal(), self.goal_pos[0], self.goal_pos[1]) # Agent self.place_agent_at_pos(0, self.start_pos) # Walls for x in range(self.bit_map.shape[0]): for y in range(self.bit_map.shape[1]): if self.bit_map[y, x]: # Add an offset of 1 for the outer walls self.put_obj(minigrid.Wall(), x + 1, y + 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'