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): door, _ = self.add_door(1, 1, locked=True) # Put the key in the box, then place the box in the room key = Key(door.color) box = Box(self._rand_color(), key) self.place_in_room(1, 1, box) self.place_agent(1, 1) self.instrs = [Instr(action="open", object=Object(door.type))]