def pick_and_place(self, objecttype, receptacletype):
    if self.name2type(self.holding) == objecttype:
        # If already holding the correct object, find the receptacle to place it in
        r_entity = self.find_receptacle(receptacletype)
        if r_entity is None:
            # If receptacle not found, explore the environment
            self.explore()
            return
        else:
            self.goto(r_entity.name)
            if r_entity.openable and not r_entity.isopen:
                self.open_receptacle(r_entity.name)
            self.put(self.holding, r_entity.name)
    else:
        # If not holding the correct object, pick the object first
        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)