def pick_and_place(self, objecttype, receptacletype):
    if self.name2type(self.holding) != self.name2type(objecttype):
        # Check if the agent is already holding the object, if not, pick the object
        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 into the receptacle
    receptacle = self.find_receptacle(receptacletype)
    if receptacle is None:
        r_entitys = self.find_receptacles(receptacletype)
        if r_entitys is None:
            self.explore()
            return
        else:
            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(receptacle.name)
        if receptacle.openable and not receptacle.isopen:
            self.open_receptacle(receptacle.name)
        self.put(self.holding, receptacle.name)