Exemplo n.º 1
0
  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'
Exemplo n.º 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
Exemplo n.º 3
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