def pick_two_obj_then_place(self, objecttype, receptacletype):
    def pick_two_obj_then_place():
        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:
                if hasattr(self, "old_object_name") and self.old_object_name == entity.name:
                    object_entitys = self.find_objects(objecttype)
                    if len(object_entitys) == 1:
                        self.explore()
                        return
                    else:
                        pick_two_obj_then_place()
                        return
                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)
                self.put(entity.name, receptacletype)
                return
        else:
            r_entity = self.find_receptacle(receptacletype)
            if r_entity is None:
                self.explore()
                return
            else:
                self.goto(r_entity.name)
                self.put(self.holding, r_entity.name)
                setattr(self, "old_object_name", self.holding)
                return
    
    pick_two_obj_then_place()