Esempio n. 1
0
def get_repeat_arrangement(player_mem,
                           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 = arrange("circle", schematic, shapeparams)
    else:
        reldir_vec = rotation.DIRECTIONS[repeat_dir]
        # this should be an inverse transform so we set inverted=True
        yaw, _ = player_mem.get_yaw_pitch()
        dir_vec = rotation.transform(reldir_vec, yaw, 0, inverted=True)
        max_ind = np.argmax(dir_vec)
        shapeparams["extra_space"] = padding[max_ind]
        shapeparams["orient"] = dir_vec
        offsets = arrange("line", schematic, shapeparams)
    offsets = [tuple(to_block_pos(o)) for o in offsets]
    return offsets
Esempio n. 2
0
def compute_location_heuristic(player_mem, mems, steps, reldir,
                               get_locs_from_entity):
    loc = mems[0].get_pos()
    if reldir is not None:
        steps = steps or DEFAULT_NUM_STEPS
        if reldir == "BETWEEN":
            loc = (np.add(mems[0].get_pos(), mems[1].get_pos())) / 2
            loc = (loc[0], loc[1], loc[2])
        elif reldir == "INSIDE":
            for i in range(len(mems)):
                mem = mems[i]
                # FIXME
                locs = heuristic_perception.find_inside(
                    mem, get_locs_from_entity)
                if len(locs) > 0:
                    break
            if len(locs) == 0:
                raise ErrorWithResponse("I don't know how to go inside there")
            else:
                loc = locs[0]
        elif reldir == "NEAR":
            pass
        elif reldir == "AROUND":
            pass
        else:  # LEFT, RIGHT, etc...
            reldir_vec = rotation.DIRECTIONS[reldir]
            # this should be an inverse transform so we set inverted=True
            yaw, _ = player_mem.get_yaw_pitch()
            dir_vec = rotation.transform(reldir_vec, yaw, 0, inverted=True)
            loc = steps * np.array(dir_vec) + to_block_center(loc)
    elif steps is not None:
        loc = to_block_center(loc) + [0, 0, steps]
    return to_block_pos(loc)
Esempio n. 3
0
 def __init__(self, agent, task_data):
     super().__init__(agent, task_data)
     if self.finished:
         return
     self.target = to_block_pos(np.array(task_data["target"]))
     self.approx = task_data.get("approx", 1)
     self.path = None
     self.replace = set()
     self.last_stepped_time = agent.memory.get_time()
     TaskNode(agent.memory, self.memid).update_task(task=self)
Esempio n. 4
0
def capped_line_of_sight(agent, player_struct, cap=20):
    """Return the block directly in the entity's line of sight, or a point in the distance"""
    xsect = agent.get_player_line_of_sight(player_struct)
    if xsect is not None and euclid_dist(pos_to_np(xsect),
                                         pos_to_np(player_struct.pos)) <= cap:
        return pos_to_np(xsect)

    # default to cap blocks in front of entity
    vec = agent.coordinate_transforms.look_vec(player_struct.look.yaw,
                                               player_struct.look.pitch)
    return cap * np.array(vec) + to_block_pos(pos_to_np(player_struct.pos))
def find_inside(entity, get_locs_from_entity):
    """Return a point inside the entity if it can find one.
    TODO: heuristic quick check to find that there aren't any,
    and maybe make this not d^3"""

    # is this a negative object? if yes, just return its mean:
    if hasattr(entity, "blocks"):
        if all(b == (0, 0) for b in entity.blocks.values()):
            m = np.mean(list(entity.blocks.keys()), axis=0)
            return [to_block_pos(m)]
    l = get_locs_from_entity(entity)
    if l is None:
        return []
    m = np.round(np.mean(l, axis=0))
    maxes = np.max(l, axis=0)
    mins = np.min(l, axis=0)
    inside = []
    for x in range(mins[0], maxes[0] + 1):
        for y in range(mins[1], maxes[1] + 1):
            for z in range(mins[2], maxes[2] + 1):
                if check_inside([(x, y, z), entity], get_locs_from_entity):
                    inside.append((x, y, z))
    return sorted(inside, key=lambda x: euclid_dist(x, m))
Esempio n. 6
0
 def target_to_memory(self, target):
     return to_block_pos(np.array(target))
Esempio n. 7
0
def post_process_loc(loc, interpreter):
    return to_block_pos(loc)
Esempio n. 8
0
    def perceive(self, force=False):
        """
        Every n agent_steps (defined by perceive_freq), update in agent memory
        location/pose of all agents, players, mobs; item stack positions and
        changed blocks.

        Args:
            force (boolean): set to True to run all perceptual heuristics right now,
                as opposed to waiting for perceive_freq steps (default: False)
        """
        # FIXME (low pri) remove these in code, get from sql
        self.agent.pos = to_block_pos(pos_to_np(self.agent.get_player().pos))
        boring_blocks = self.agent.low_level_data["boring_blocks"]
        """
        perceive_info is a dictionary with the following possible members :
            - mobs(list) : List of mobs in perception range
            - agent_pickable_items(dict) - member with the following possible children:
                - in_perception_items(list) - List of item_stack
                - all_items(set) - Set of item stack entityIds
            - agent_attributes(NamedTuple) - returns the namedTuple Player for agent
            - other_player_list(List) - List of [player, location] of all other players
            - changed_block_attributes(dict) - Dictionary of mappings from (xyz, idm) to [
                                                                                        interesting,
                                                                                        player_placed,
                                                                                        agent_placed,
                                                                                    ]
            
        """
        perceive_info = {}
        perceive_info["mobs"] = None
        perceive_info["agent_pickable_items"] = {}
        perceive_info["agent_attributes"] = None
        perceive_info["other_player_list"] = []
        perceive_info["changed_block_attributes"] = {}

        if self.agent.count % self.perceive_freq == 0 or force:
            # Find mobs in perception range
            mobs = []
            for mob in self.agent.get_mobs():
                if (euclid_dist(self.agent.pos, pos_to_np(mob.pos)) <
                        self.agent.memory.perception_range):
                    mobs.append(mob)
            perceive_info["mobs"] = mobs if mobs else None

            # Find items that can be picked by the agent, and in perception range
            all_items = set()
            in_perception_items = []
            for item_stack in self.agent.get_item_stacks():
                all_items.add(item_stack.entityId)
                if (euclid_dist(self.agent.pos, pos_to_np(item_stack.pos)) <
                        self.agent.memory.perception_range):
                    in_perception_items.append(item_stack)
            perceive_info["agent_pickable_items"] = perceive_info.get(
                "agent_pickable_items", {})
            perceive_info["agent_pickable_items"]["in_perception_items"] = (
                in_perception_items if in_perception_items else None)
            perceive_info["agent_pickable_items"][
                "all_items"] = all_items if all_items else None

        # note: no "force"; these run on every perceive call.  assumed to be fast
        perceive_info["agent_attributes"] = self.get_agent_player(
        )  # Get Agent attributes
        # List of other players in-game
        perceive_info["other_player_list"] = self.update_other_players(
            self.agent.get_other_players())
        # Changed blocks and their attributes
        perceive_info["changed_block_attributes"] = {}
        for (xyz, idm) in self.agent.safe_get_changed_blocks():
            interesting, player_placed, agent_placed = self.on_block_changed(
                xyz, idm, boring_blocks)
            perceive_info["changed_block_attributes"][(xyz, idm)] = [
                interesting,
                player_placed,
                agent_placed,
            ]

        return CraftAssistPerceptionData(
            mobs=perceive_info["mobs"],
            agent_pickable_items=perceive_info["agent_pickable_items"],
            agent_attributes=perceive_info["agent_attributes"],
            other_player_list=perceive_info["other_player_list"],
            changed_block_attributes=perceive_info["changed_block_attributes"],
        )