def add_object(self, i, j, kind=None, color=None, goalidx=None): """ Add a new object to room (i, j) """ if kind == None: kind = self._rand_elem(['key', 'ball', 'box']) if color == None: color = self._rand_color() assert kind in ['key', 'ball', 'box', 'goal', 'goalcolor'] if kind == 'key': obj = Key(color) elif kind == 'ball': obj = Ball(color) elif kind == 'box': obj = Box(color) elif kind == 'goal': obj: Goal() elif kind =='goalcolor': obj = GoalColor('green') return self.put_obj(GoalColor(color), self.width - 2, self.height - (2*(1+goalidx))) return self.place_in_room(i, j, obj)
def gen_mission(self): # Add a box to the room on the right obj, _ = self.add_object(1, 0, kind="box") # Make sure the two rooms are directly connected by a locked door door, pos = self.add_door(0, 0, 0, locked=True) # Block the door with a ball color = self._rand_color() self.grid.set(pos[0]-1, pos[1], Ball(color)) # Add a key to unlock the door self.add_object(0, 0, 'key', door.color) self.place_agent(0, 0) self.instrs = [Instr(action="pickup", object=Object(obj.type))]
def __init__(self, player, opponent, width=5, height=5, max_steps=100): self.width = width self.height = height self.max_steps = max_steps self.step_count = 0 self.player = player self.opponent = opponent action_space_dim = len(player.action_space) self.action_space = gym.spaces.MultiDiscrete([action_space_dim, action_space_dim]) self.grid: Grid = None self.player_obj = Ball(color="green") self.opponent_obj = Lava() self.wall_type = Wall().__class__.__name__ self.reset()