コード例 #1
0
ファイル: dance.py プロジェクト: youkarin/craftassist
    def __init__(
        self,
        agent,
        ref_object=None,
        relative_direction="CLOCKWISE",  # this is the memory of the object
    ):
        self.agent = agent
        self.tick = 0
        blocks = [(bpos, bid) for bpos, bid in ref_object.blocks.items()]
        bounds = shapes.get_bounds(blocks)
        center = np.mean([b[0] for b in blocks], axis=0)

        d = max(bounds[1] - bounds[0], bounds[3] - bounds[2], bounds[5] - bounds[4])
        if relative_direction == "CLOCKWISE":
            offsets = shapes.arrange(
                "circle", schematic=None, shapeparams={"encircled_object_radius": d}
            )
        elif relative_direction == "ANTICLOCKWISE":
            offsets = shapes.arrange(
                "circle", schematic=None, shapeparams={"encircled_object_radius": d}
            )
            offsets = offsets[::-1]
        else:
            raise NotImplementedError("TODO other kinds of paths")
        self.path = [np.round(center + o) for o in offsets]
        self.path.append(self.path[0])

        # check each offset to find a nearby reachable point, see if a path
        # is possible now, and error otherwise

        for i in range(len(self.path) - 1):
            path = search.astar(agent, self.path[i + 1], approx=2, pos=self.path[i])
            if path is None:
                raise ErrorWithResponse("I cannot find an appropriate path.")
コード例 #2
0
def get_repeat_arrangement(d,
                           interpreter,
                           speaker,
                           schematic,
                           repeat_num=-1,
                           extra_space=1) -> List[XYZ]:
    shapeparams = {}
    # eventually fix this to allow number based on shape
    shapeparams["N"] = repeat_num
    shapeparams["extra_space"] = extra_space
    if "repeat" in d:
        direction_name = d.get("repeat", {}).get("repeat_dir", "FRONT")
    elif "schematic" in d:
        direction_name = d["schematic"].get("repeat",
                                            {}).get("repeat_dir", "FRONT")
    if direction_name != "AROUND":
        reldir_vec = rotation.DIRECTIONS[direction_name]
        look = (interpreter.agent.perception_modules["low_level"].
                get_player_struct_by_name(speaker).look)
        # this should be an inverse transform so we set inverted=True
        dir_vec = rotation.transform(reldir_vec, look.yaw, 0, inverted=True)
        shapeparams["orient"] = dir_vec
        offsets = shapes.arrange("line", schematic, shapeparams)
    else:
        # TODO vertical "around"
        shapeparams["orient"] = "xy"
        shapeparams["encircled_object_radius"] = 1
        if d.get("location") is not None:
            central_object = interpret_reference_object(
                interpreter,
                speaker,
                d["location"]["reference_object"],
                limit=1)
            # FIXME: .blocks is unsafe, assumes BlockObject only object could be Mob. Ignoring for now.
            central_object_blocks = central_object[0].blocks  # type: ignore
            # .blocks returns a dict of (x, y, z) : (block_id, meta), convert to list
            # to get bounds
            central_object_list = [
                tuple([k, v]) for k, v in central_object_blocks.items()
            ]
            bounds = shapes.get_bounds(central_object_list)
            b = max(bounds[1] - bounds[0], bounds[3] - bounds[2],
                    bounds[5] - bounds[4])
            shapeparams["encircled_object_radius"] = b
        offsets = shapes.arrange("circle", schematic, shapeparams)
    offsets = [tuple(to_block_pos(o)) for o in offsets]
    return offsets
コード例 #3
0
    def __init__(
            self,
            agent,
            ref_object=None,
            relative_direction="CLOCKWISE",  # this is the memory of the object
    ):
        self.agent = agent
        self.tick = 0
        if not ref_object:
            x, y, z = agent.pos
            bounds = (x, x, y, y, z, z)
            center = (x, y, z)
        else:
            bounds = ref_object.get_bounds()
            center = ref_object.get_pos()
        d = max(bounds[1] - bounds[0], bounds[3] - bounds[2],
                bounds[5] - bounds[4])
        if relative_direction == "CLOCKWISE" or relative_direction == "AROUND":
            offsets = shapes.arrange(
                "circle",
                schematic=None,
                shapeparams={"encircled_object_radius": d})
        elif relative_direction == "ANTICLOCKWISE":
            offsets = shapes.arrange(
                "circle",
                schematic=None,
                shapeparams={"encircled_object_radius": d})
            offsets = offsets[::-1]
        else:
            raise NotImplementedError("TODO other kinds of paths")
        self.path = [np.round(np.add(center, o)) for o in offsets]
        self.path.append(self.path[0])

        # check each offset to find a nearby reachable point, see if a path
        # is possible now, and error otherwise

        for i in range(len(self.path) - 1):
            path = search.astar(agent,
                                self.path[i + 1],
                                approx=2,
                                pos=self.path[i])
            if path is None:
                raise ErrorWithResponse("I cannot find an appropriate path.")
コード例 #4
0
def get_repeat_arrangement(player_look,
                           repeat_num,
                           repeat_dir,
                           ref_mems,
                           schematic=None,
                           padding=(1, 1, 1)):
    shapeparams = {}
    # default repeat dir is LEFT
    if not repeat_dir:
        repeat_dir = "LEFT"
    # eventually fix this to allow number based on shape
    shapeparams["N"] = repeat_num

    if repeat_dir == "AROUND":
        # TODO vertical "around"
        shapeparams["orient"] = "xy"
        shapeparams["extra_space"] = max(padding)
        central_object = ref_mems[0]
        bounds = central_object.get_bounds()
        b = max(bounds[1] - bounds[0], bounds[3] - bounds[2],
                bounds[5] - bounds[4])
        shapeparams["encircled_object_radius"] = b

        offsets = shapes.arrange("circle", schematic, shapeparams)
    else:

        reldir_vec = rotation.DIRECTIONS[repeat_dir]
        # this should be an inverse transform so we set inverted=True
        dir_vec = rotation.transform(reldir_vec,
                                     player_look.yaw,
                                     0,
                                     inverted=True)
        max_ind = np.argmax(dir_vec)
        shapeparams["extra_space"] = padding[max_ind]
        shapeparams["orient"] = dir_vec
        offsets = shapes.arrange("line", schematic, shapeparams)
    offsets = [tuple(to_block_pos(o)) for o in offsets]
    return offsets