Beispiel #1
0
def build_random_shape(agent, rand_range=(10, 0, 10), no_chat=False):
    """Pick a random shape from shapes.py and build that"""
    target_loc = agent.pos
    for i in range(3):
        target_loc[i] += np.random.randint(-rand_range[i], rand_range[i] + 1)
    shape = random.choice(sh.SHAPE_NAMES)
    opts = sh.SHAPE_HELPERS[shape]()
    opts["bid"] = sh.bid()
    schematic = sh.SHAPE_FNS[shape](**opts)
    relations = [
        {"pred": "has_name", "obj": shape.lower()},
        {"pred": "has_tag", "obj": shape.lower()},
    ]
    task_data = {
        "blocks_list": schematic,
        "origin": target_loc,
        "verbose": False,
        "schematic_tags": relations,
        "default_behavior": "build_random_shape",  # must == function name. Hacky and I hate it.
    }
    logging.info("Default behavior: building {}".format(shape))
    agent.memory.task_stack_push(tasks.Build(agent, task_data))

    if not no_chat:
        shape_name = prepend_a_an(shape.lower())
        agent.dialogue_manager.dialogue_stack.append_new(
            Say, "I am building {} while you decide what you what me to do!".format(shape_name)
        )

    return schematic
Beispiel #2
0
 def handle_task_refobj_string(self, task, refobj_attr):
     if refobj_attr == "name":
         for pred, val in task.task.target:
             if pred == "has_name":
                 return "I am going to the " + prepend_a_an(val), None
     elif refobj_attr == "location":
         target = tuple(task.task.target)
         return "I am going to {}".format(target), None
     else:
         raise ErrorWithResponse(
             "trying get attribute {} from action".format(refobj_attr))
    def handle_answer_type_tag(
            self, mems: Sequence[MemoryNode]) -> Tuple[Optional[str], Any]:
        if len(mems) == 0:
            raise ErrorWithResponse("I don't know what you're referring to")
        mem = mems[0]

        tag_name = self.action_dict["tag_name"]
        if tag_name.startswith("has_"):
            triples = self.memory.get_triples(subj=mem.memid, pred=tag_name)
            if len(triples) == 0:
                # first backoff to tags
                triples = self.memory.get_triples(subj=mem.memid,
                                                  pred="has_tag")
                if len(triples) == 0:
                    return "I don't know", None
                else:
                    tag_name = "has_tag"
            all_tags = [t[2] for t in triples]
            _, _, val = triples[0]

            if tag_name == "has_name":
                if "_in_progress" in self.memory.get_tags_by_memid(mem.memid):
                    return "It will be a %r" % (val), None
                else:
                    return "It is a %r" % (val), None
            elif tag_name == "has_tag":
                return "That has tags " + " ".join(all_tags), None
            else:
                return "It is %r" % (val), None
        elif tag_name == "action_name":
            assert type(mem) == TaskNode, mem
            return "I am {}".format(
                ACTION_ING_MAPPING[mem.action_name.lower()]), None
        elif tag_name == "action_reference_object_name":
            assert isinstance(mems[0], TaskNode), mems[0]
            assert isinstance(mems[0].task, Build), mems[0].task
            for pred, val in mems[0].task.schematic_tags:
                if pred == "has_name":
                    return "I am building " + prepend_a_an(val), None
            return "I am building something that is {}".format(val), None
        elif tag_name == "move_target":
            assert mem.action_name == "Move", mem
            target = tuple(mem.task.target)
            return "I am going to {}".format(target), None
        elif tag_name == "location":
            if isinstance(mems[0], ReferenceObjectNode):
                return str(mems[0].get_pos()), None
            else:
                raise TypeError("Can't get location of {} {}".format(
                    mems[0], mems[0].memid))
        else:
            raise ErrorWithResponse("I don't understand what you're asking")
 def handle_task_refobj_string(self, task, refobj_attr):
     if refobj_attr == "name":
         assert isinstance(task.task, Build), task.task
         for pred, val in task.task.schematic_tags:
             if pred == "has_name":
                 return "I am building " + prepend_a_an(val), None
             return "I am building something that is {}".format(val), None
     elif refobj_attr == "location":
         assert task.action_name == "Move", task.action_name
         target = tuple(task.task.target)
         return "I am going to {}".format(target), None
     else:
         raise ErrorWithResponse("trying get attribute {} from action".format(refobj_attr))
     return None, None