Example #1
0
    def handle_destroy(self, speaker, d) -> Tuple[Any, Optional[str], Any]:
        """This function reads the dictionary, resolves the missing details using memory
        and perception and handles a 'destroy' command by either pushing a dialogue object
        or pushing a Destroy task to the task stack. 

        Args:
            speaker: speaker_id or name.
            d: the complete action dictionary
        """
        default_ref_d = {"filters": {"location": SPEAKERLOOK}}
        ref_d = d.get("reference_object", default_ref_d)
        objs = self.subinterpret["reference_objects"](
            self, speaker, ref_d, extra_tags=["_destructible"])
        if len(objs) == 0:
            raise ErrorWithResponse(
                "I don't understand what you want me to destroy.")

        # don't kill mobs
        if all(isinstance(obj, MobNode) for obj in objs):
            raise ErrorWithResponse("I don't kill animals, sorry!")
        if all(isinstance(obj, PlayerNode) for obj in objs):
            raise ErrorWithResponse("I don't kill players, sorry!")
        objs = [obj for obj in objs if not isinstance(obj, MobNode)]
        tasks = []
        for obj in objs:
            if hasattr(obj, "blocks"):
                schematic = list(obj.blocks.items())
                task_data = {"schematic": schematic, "action_dict": d}
                tasks.append(self.task_objects["destroy"](self.agent,
                                                          task_data))
        logging.info("Added {} Destroy tasks to stack".format(len(tasks)))
        return maybe_task_list_to_control_block(tasks, self.agent), None, None
Example #2
0
	def move(self, vect):
		if self.task:
			self.task.close()
			self.task = None
		if not vect:
			return
		self.task = self.move_task(vect)
		tasks.append(self.task)
Example #3
0
    def handle_modify(self, speaker, d) -> Tuple[Any, Optional[str], Any]:
        """This function reads the dictionary, resolves the missing details using memory
        and handles a 'modify' command by either replying back or pushing 
        appropriate tasks to the task stack. 

        Args:
            speaker: speaker_id or name.
            d: the complete action dictionary
        """
        default_ref_d = {"filters": {"location": SPEAKERLOOK}}
        ref_d = d.get("reference_object", default_ref_d)
        # only modify blockobjects...
        objs = self.subinterpret["reference_objects"](
            self,
            speaker,
            ref_d,
            extra_tags=["_physical_object", "VOXEL_OBJECT"])
        if len(objs) == 0:
            raise ErrorWithResponse(
                "I don't understand what you want me to modify.")

        m_d = d.get("modify_dict")
        if not m_d:
            raise ErrorWithResponse(
                "I think you want me to modify an object but am not sure what to do"
            )
        tasks = []
        for obj in objs:
            if m_d["modify_type"] == "THINNER" or m_d[
                    "modify_type"] == "THICKER":
                destroy_task_data, build_task_data = handle_thicken(
                    self, speaker, m_d, obj)
            elif m_d["modify_type"] == "REPLACE":
                destroy_task_data, build_task_data = handle_replace(
                    self, speaker, m_d, obj)
            elif m_d["modify_type"] == "SCALE":
                destroy_task_data, build_task_data = handle_scale(
                    self, speaker, m_d, obj)
            elif m_d["modify_type"] == "RIGIDMOTION":
                destroy_task_data, build_task_data = handle_rigidmotion(
                    self, speaker, m_d, obj)
            elif m_d["modify_type"] == "FILL" or m_d["modify_type"] == "HOLLOW":
                destroy_task_data, build_task_data = handle_fill(
                    self, speaker, m_d, obj)
            else:
                raise ErrorWithResponse(
                    "I think you want me to modify an object but am not sure what to do (parse error)"
                )

            if build_task_data:
                tasks.append(self.task_objects["build"](self.agent,
                                                        build_task_data))

            if destroy_task_data:
                tasks.append(self.task_objects["build"](self.agent,
                                                        destroy_task_data))

        return maybe_task_list_to_control_block(tasks, self.agent), None, None
Example #4
0
def create_tasks(angles, n_levels, n_nodes):
    tasks = []
    for a in angles:
        for r in range(n_levels + 1):
            print 'Creating task: r%da%dn%d' % (r, a, n_nodes)
            taskName = 'r%da%dn%d' % (r, a, n_nodes)
            # Add task to queue and append return value to tasks
            tasks.append((taskName, (a, a, 1, n_nodes, r)))
    return list(set(tasks))
Example #5
0
File: view.py Project: kovrov/scrap
def pan(vect):
    global task
    if task:
        task.close()
        task = None
    if not vect:
        return
    task = pan_task(vect)
    tasks.append(task)
Example #6
0
def on_mouse_press(x, y, button, modifiers):
	if ui.on_mouse_press(x, y, button, modifiers):
		return True
	real_x, real_y = view.screen2world(x, y)
	ship.translate(real_x, real_y)
	# background flash
	tasks.append(fx.flash_task(0.5))
	# sparks test
	sparks = fx.Sparks((real_x, real_y, 0.0))
	scene.models.append(sparks)
	tasks.append(sparks.update_task())
Example #7
0
def get_training_tasks(args):
    tasks = []
    for task_name in args.training_tasks:
        if 'SemEval18' == task_name:
            for emotion in SemEval18SingleEmotionTask.EMOTIONS:
                tasks.append(
                    SemEval18SingleEmotionTask(emotion,
                                               cls_dim=args.mlp_dims[-1]))
        else:
            tasks.append(get_task_by_name(args, task_name))
    return tasks
Example #8
0
def parse_tasks(config_file, dry_run=False):
    tasks = []
    f = open(config_file, 'r')
    config = configparser.ConfigParser()
    config.read_file(f)
    f.close()
    for s in config.sections():
        actions = config.get(s, "actions")
        for a in actions.split(","):
            a = a.strip(" []{}")
            config_items = dict(config.items(s))
            period = parse_period(config_items["period"])
            drives_filepaths = []
            t = actions_classes[a](s, period, drives_filepaths, config_items,
                                   dry_run)
            tasks.append(t)
    return tasks
Example #9
0
    def handle_spawn(self, speaker, d) -> Tuple[Any, Optional[str], Any]:
        """This function reads the dictionary, resolves the missing details using memory
        and handles a 'spawn' command by either replying back or 
        pushing a Spawn task to the task stack. 

        Args:
            speaker: speaker_id or name.
            d: the complete action dictionary
        """
        # FIXME! use filters appropriately, don't search by hand
        spawn_triples = d.get("reference_object",
                              {}).get("filters", {}).get("triples", [])
        if not spawn_triples:
            raise ErrorWithResponse(
                "I don't understand what you want me to spawn.")
        names = [
            t.get("obj_text") for t in spawn_triples
            if t.get("pred_text", "") == "has_name"
        ]
        if not any(names):
            raise ErrorWithResponse(
                "I don't understand what you want me to spawn.")
        # if multiple possible has_name triples, just pick the first:
        object_name = names[0]
        schematic = self.memory.get_mob_schematic_by_name(object_name)
        if not schematic:
            raise ErrorWithResponse("I don't know how to spawn: %r." %
                                    (object_name))

        object_idm = list(schematic.blocks.values())[0]
        location_d = d.get("location", SPEAKERLOOK)
        mems = self.subinterpret["reference_locations"](self, speaker,
                                                        location_d)
        steps, reldir = interpret_relative_direction(self, location_d)
        pos, _ = self.subinterpret["specify_locations"](self, speaker, mems,
                                                        steps, reldir)
        repeat_times = get_repeat_num(d)
        tasks = []
        for i in range(repeat_times):
            task_data = {
                "object_idm": object_idm,
                "pos": pos,
                "action_dict": d
            }
            tasks.append(self.task_objects["spawn"](self.agent, task_data))
        return maybe_task_list_to_control_block(tasks, self.agent), None, None
Example #10
0
	def translate(self, x, y):
		if self.task:
			self.task.close()
		if self.pos != (x, y):
			self.task = self.translate_task((x, y))
			tasks.append(self.task)
Example #11
0
    def handle_fill(self, speaker, d) -> Tuple[Any, Optional[str], Any]:
        """This function reads the dictionary, resolves the missing details using memory
        and perception and handles a 'fill' command by either pushing a dialogue object
        or pushing a Fill task to the task stack. 

        Args:
            speaker: speaker_id or name.
            d: the complete action dictionary
        """
        tasks = []
        r = d.get("reference_object")
        if not r.get("filters"):
            r["filters"] = {"location", SPEAKERLOOK}

        # Get the reference location
        location_d = r["filters"].get("location", SPEAKERLOOK)
        mems = self.subinterpret["reference_locations"](self, speaker,
                                                        location_d)
        steps, reldir = interpret_relative_direction(self, location_d)
        location, _ = self.subinterpret["specify_locations"](self, speaker,
                                                             mems, steps,
                                                             reldir)

        # Get nearby holes
        holes: List[Hole] = heuristic_perception.get_all_nearby_holes(
            self.agent, location)
        candidates: List[Tuple[XYZ, Hole]] = [
            (to_block_pos(np.mean(hole[0], axis=0)), hole) for hole in holes
        ]

        # Choose the best ones to fill
        repeat = get_repeat_num(d)
        holes = filter_by_sublocation(self,
                                      speaker,
                                      candidates,
                                      r,
                                      limit=repeat,
                                      loose=True)
        if holes is None:
            self.dialogue_stack.append_new(
                Say, "I don't understand what holes you want me to fill.")
            return None, None, None
        tasks = []
        for hole in holes:
            _, hole_info = hole
            poss, hole_idm = hole_info
            schematic, tags = interpret_fill_schematic(self, speaker,
                                                       d.get("schematic", {}),
                                                       poss, hole_idm)
            origin = np.min([xyz for (xyz, bid) in schematic], axis=0)
            task_data = {
                "blocks_list": schematic,
                "force": True,
                "origin": origin,
                "verbose": False,
                "embed": True,
                "fill_message": True,
                "schematic_tags": tags,
            }

            tasks.append(self.task_objects["build"](self.agent, task_data))

        if len(holes) > 1:
            self.dialogue_stack.append_new(Say, "Ok. I'll fill up the holes.")
        else:
            self.dialogue_stack.append_new(Say, "Ok. I'll fill that hole up.")

        return maybe_task_list_to_control_block(tasks, self.agent), None, None
Example #12
0
    def handle_build(self, speaker, d) -> Tuple[Any, Optional[str], Any]:
        """This function reads the dictionary, resolves the missing details using memory
        and perception and handles a 'build' command by either pushing a dialogue object
        or pushing a Build task to the task stack. 

        Args:
            speaker: speaker_id or name.
            d: the complete action dictionary
        """
        # Get the segment to build
        if "reference_object" in d:
            # handle copy
            repeat = get_repeat_num(d)
            objs = self.subinterpret["reference_objects"](
                self,
                speaker,
                d["reference_object"],
                limit=repeat,
                extra_tags=["VOXEL_OBJECT"],
                loose_speakerlook=True,
            )
            if len(objs) == 0:
                raise ErrorWithResponse(
                    "I don't understand what you want me to build")
            tagss = [[(p, v)
                      for (_, p, v) in self.memory.get_triples(subj=obj.memid)]
                     for obj in objs]
            interprets = [[list(obj.blocks.items()), obj.memid, tags]
                          for (obj, tags) in zip(objs, tagss)]
        else:  # a schematic
            if d.get("repeat") is not None:
                repeat_dict = d
            else:
                repeat_dict = None
            interprets = interpret_schematic(self,
                                             speaker,
                                             d.get("schematic", {}),
                                             repeat_dict=repeat_dict)

        # Get the locations to build
        location_d = d.get("location", SPEAKERLOOK)
        mems = self.subinterpret["reference_locations"](self, speaker,
                                                        location_d)
        steps, reldir = interpret_relative_direction(self, location_d)
        origin, offsets = self.subinterpret["specify_locations"](
            self,
            speaker,
            mems,
            steps,
            reldir,
            repeat_dir=get_repeat_dir(location_d),
            objects=interprets,
            enable_geoscorer=True,
        )
        interprets_with_offsets = [(blocks, mem, tags, off)
                                   for (blocks, mem,
                                        tags), off in zip(interprets, offsets)]

        tasks_data = []
        for schematic, schematic_memid, tags, offset in interprets_with_offsets:
            og = np.array(origin) + offset
            task_data = {
                "blocks_list": schematic,
                "origin": og,
                "schematic_memid": schematic_memid,
                "schematic_tags": tags,
                "action_dict": d,
            }

            tasks_data.append(task_data)

        tasks = []
        for td in tasks_data:
            t = self.task_objects["build"](self.agent, td)
            tasks.append(t)
        logging.info("Adding {} Build tasks to stack".format(len(tasks)))
        return maybe_task_list_to_control_block(tasks, self.agent), None, None