def perceive(self, force=False): if self.perceive_freq == 0 and not force: return if self.agent.count % self.perceive_freq != 0 and not force: return for obj in all_nearby_objects(self.agent.get_blocks, self.agent.pos): BlockObjectNode.create(self.agent.memory, obj) get_all_nearby_holes(self.agent, self.agent.pos, radius=self.radius) get_nearby_airtouching_blocks(self.agent, self.agent.pos, radius=self.radius)
def perceive(self, force=False): """Called by the core event loop for the agent to run all perceptual models and save their state to memory. Args: force (boolean): set to True to run all perceptual heuristics right now, as opposed to waiting for perceive_freq steps (default: False) """ if self.perceive_freq == 0 and not force: return if self.agent.count % self.perceive_freq != 0 and not force: return if force or not self.agent.memory.task_stack_peek(): # perceive blocks in marked areas for pos, radius in self.agent.areas_to_perceive: for obj in all_nearby_objects(self.agent.get_blocks, pos, radius): memid = BlockObjectNode.create(self.agent.memory, obj) color_tags = [] for idm in obj: type_name = BLOCK_DATA["bid_to_name"][idm] color_tags.extend(COLOUR_DATA["name_to_colors"].get( type_name, [])) for color_tag in list(set(color_tags)): self.agent.memory.add_triple(subj=memid, pred_text="has_colour", obj_text=color_tag) get_all_nearby_holes(self.agent, pos, radius) get_nearby_airtouching_blocks(self.agent, pos, radius) # perceive blocks near the agent for objs in all_nearby_objects(self.agent.get_blocks, self.agent.pos): memid = BlockObjectNode.create(self.agent.memory, objs) color_tags = [] for obj in objs: idm = obj[1] type_name = BLOCK_DATA["bid_to_name"][idm] color_tags.extend(COLOUR_DATA["name_to_colors"].get( type_name, [])) for color_tag in list(set(color_tags)): self.agent.memory.add_triple(subj=memid, pred_text="has_colour", obj_text=color_tag) get_all_nearby_holes(self.agent, self.agent.pos, radius=self.radius) get_nearby_airtouching_blocks(self.agent, self.agent.pos, radius=self.radius)
def get_object_by_id(self, memid: str, table="BlockObjects") -> "VoxelObjectNode": if table == "BlockObjects": return BlockObjectNode(self, memid) elif table == "InstSeg": return InstSegNode(self, memid) else: raise ValueError("Bad table={}".format(table))
def perceive(self, force=False): if self.perceive_freq == 0 and not force: return if self.agent.count % self.perceive_freq != 0 and not force: return if force or not self.agent.memory.task_stack_peek(): # perceive blocks in marked areas for pos, radius in self.agent.areas_to_perceive: for obj in all_nearby_objects(self.agent.get_blocks, pos, radius): BlockObjectNode.create(self.agent.memory, obj) get_all_nearby_holes(self.agent, pos, radius) get_nearby_airtouching_blocks(self.agent, pos, radius) # perceive blocks near the agent for obj in all_nearby_objects(self.agent.get_blocks, self.agent.pos): BlockObjectNode.create(self.agent.memory, obj) get_all_nearby_holes(self.agent, self.agent.pos, radius=self.radius) get_nearby_airtouching_blocks(self.agent, self.agent.pos, radius=self.radius)
def get_object_by_id(self, memid: str, table="BlockObjects") -> "ObjectNode": # sanity check... r = self._db_read( "SELECT x, y, z, bid, meta FROM {} WHERE uuid=? ORDER BY updated".format(table), memid ) assert r, memid # end sanity check if table == "BlockObjects": return BlockObjectNode(self, memid) elif table == "ComponentObjects": return ComponentObjectNode(self, memid) else: raise ValueError("Bad table={}".format(table))
def get_object_by_id(self, memid: str, table="BlockObjects") -> "VoxelObjectNode": """ Returns: The memory node for the given memid """ if table == "BlockObjects": return BlockObjectNode(self, memid) elif table == "InstSeg": return InstSegNode(self, memid) else: raise ValueError("Bad table={}".format(table))
def maybe_add_block_to_memory(self, xyz: XYZ, idm: IDM, agent_placed=False): if not agent_placed: interesting, player_placed, agent_placed = self.is_placed_block_interesting( xyz, idm[0]) else: interesting = True player_placed = False if not interesting: return # TODO remove this, clean up if agent_placed: try: self.pending_agent_placed_blocks.remove(xyz) except: pass adjacent = [ self.memory.get_object_info_by_xyz(a, "BlockObjects", just_memid=False) for a in diag_adjacent(xyz) ] if idm[0] == 0: # block removed / air block added adjacent_memids = [ a[0][0] for a in adjacent if len(a) > 0 and a[0][1] == 0 ] else: # normal block added adjacent_memids = [ a[0][0] for a in adjacent if len(a) > 0 and a[0][1] > 0 ] adjacent_memids = list(set(adjacent_memids)) if len(adjacent_memids) == 0: # new block object BlockObjectNode.create(self.agent.memory, [(xyz, idm)]) elif len(adjacent_memids) == 1: # update block object memid = adjacent_memids[0] self.memory.upsert_block((xyz, idm), memid, "BlockObjects", player_placed, agent_placed) self.memory.set_memory_updated_time(memid) self.memory.set_memory_attended_time(memid) else: chosen_memid = adjacent_memids[0] self.memory.set_memory_updated_time(chosen_memid) self.memory.set_memory_attended_time(chosen_memid) # merge tags where = " OR ".join(["subj=?"] * len(adjacent_memids)) self.memory._db_write("UPDATE Triples SET subj=? WHERE " + where, chosen_memid, *adjacent_memids) # merge multiple block objects (will delete old ones) where = " OR ".join(["uuid=?"] * len(adjacent_memids)) cmd = "UPDATE VoxelObjects SET uuid=? WHERE " self.memory._db_write(cmd + where, chosen_memid, *adjacent_memids) # insert new block self.memory.upsert_block((xyz, idm), chosen_memid, "BlockObjects", player_placed, agent_placed)