def pick_and_place(self, objecttype, receptacletype):
    # Pick an object with the given objecttype
    if self.name2type(self.holding) != self.name2type(objecttype):
        entity = self.find_object(objecttype)
        if entity is None:
            r_types = self.find_canbe_contained(objecttype)
            if r_types is None:
                self.explore()
                return
            else:
                for r_type in r_types:
                    r_entitys = self.find_receptacles(r_type)
                    if r_entitys is None:
                        continue
                    for r_entity in r_entitys:
                        self.goto(r_entity.name)
                        if r_entity.openable and not r_entity.isopen:
                            self.open_receptacle(r_entity.name)
                            return
        else:
            self.goto(entity.in_on)
            r_entity = self.seen_entitys[entity.in_on]
            if r_entity.openable and not r_entity.isopen:
                self.open_receptacle(r_entity.name)
            self.take(entity.name, entity.in_on)
            return
    
    # Place the object in the receptacle
    r_entities = self.find_receptacles(receptacletype)
    if r_entities is None:
        self.explore()
        return
    for r_entity in r_entities:
        self.goto(r_entity.name)
        if r_entity.openable and not r_entity.isopen:
            self.open_receptacle(r_entity.name)
            return
        if r_entity.isopen and self.holding:
            self.put(self.holding, r_entity.name)
            return