def __init__(self, agent, task_data, featurizer=None): super(Build, self).__init__(featurizer=featurizer) self.task_data = task_data self.embed = task_data.get("embed", False) self.schematic, _ = blocks_list_to_npy(task_data["blocks_list"]) self.origin = task_data["origin"] self.verbose = task_data.get("verbose", True) self.relations = task_data.get("relations", []) self.default_behavior = task_data.get("default_behavior") self.force = task_data.get("force", False) self.block_memory = None self.attempts = 3 * np.ones(self.schematic.shape[:3], dtype=np.uint8) self.fill_message = task_data.get("fill_message", False) self.schematic_memid = task_data.get("schematic_memid", None) self.schematic_tags = task_data.get("schematic_tags", []) self.giving_up_message_sent = False self.wait = False self.old_blocks_list = None self.old_origin = None # modify the schematic to avoid placing certain blocks for bad, good in BUILD_BLOCK_REPLACE_MAP.items(): self.schematic[self.schematic[:, :, :, 0] == bad] = good self.new_blocks = [] # a list of (xyz, idm) of newly placed blocks # snap origin to ground if bottom level has dirt blocks # NOTE(kavyasrinet): except for when we are rebuilding the old dirt blocks, we # don't want to change the origin then, hence the self.force check. if not self.force and not self.embed and np.isin(self.schematic[:, :, :, 0], (2, 3)).any(): h = perception.ground_height(agent, self.origin, 0) self.origin[1] = h[0, 0]
def __init__(self, agent, task_data): super(Build, self).__init__() self.task_data = task_data self.embed = task_data.get("embed", False) self.schematic, _ = blocks_list_to_npy(task_data["blocks_list"]) self.origin = task_data["origin"] self.verbose = task_data.get("verbose", True) self.relations = task_data.get("relations", []) self.default_behavior = task_data.get("default_behavior") self.force = task_data.get("force", False) self.attempts = 3 * np.ones(self.schematic.shape[:3], dtype=np.uint8) self.fill_message = task_data.get("fill_message", False) self.schematic_memid = task_data.get("schematic_memid", None) self.schematic_tags = task_data.get("schematic_tags", []) self.giving_up_message_sent = False self.wait = False self.old_blocks_list = None self.old_origin = None self.PLACE_REACH = task_data.get("PLACE_REACH", 3) # negative schematic related self.is_destroy_schm = task_data.get("is_destroy_schm", False) self.dig_message = task_data.get("dig_message", False) self.blockobj_memid = None self.DIG_REACH = task_data.get("DIG_REACH", 3) self.last_stepped_time = agent.memory.get_time() if self.is_destroy_schm: # is it destroying a whole block object? if so, save its tags self.destroyed_block_object_triples = [] xyzs = set(strip_idmeta(task_data["blocks_list"])) mem = agent.memory.get_block_object_by_xyz(next(iter(xyzs))) # TODO what if there are several objects being destroyed? if mem and all(xyz in xyzs for xyz in mem.blocks.keys()): for pred in ["has_tag", "has_name", "has_colour"]: self.destroyed_block_object_triples.extend( agent.memory.get_triples(subj=mem.memid, pred_text=pred)) logging.info("Destroying block object {} tags={}".format( mem.memid, self.destroyed_block_object_triples)) # modify the schematic to avoid placing certain blocks for bad, good in BUILD_BLOCK_REPLACE_MAP.items(): self.schematic[self.schematic[:, :, :, 0] == bad] = good self.new_blocks = [] # a list of (xyz, idm) of newly placed blocks # snap origin to ground if bottom level has dirt blocks # NOTE(kavyasrinet): except for when we are rebuilding the old dirt blocks, we # don't want to change the origin then, hence the self.force check. if not self.force and not self.embed and np.isin( self.schematic[:, :, :, 0], (2, 3)).any(): h = ground_height(agent, self.origin, 0) self.origin[1] = h[0, 0] # get blocks occupying build area and save state for undo() ox, oy, oz = self.origin sy, sz, sx, _ = self.schematic.shape current = agent.get_blocks(ox, ox + sx - 1, oy, oy + sy - 1, oz, oz + sz - 1) self.old_blocks_list = npy_to_blocks_list(current, self.origin) if len(self.old_blocks_list) > 0: self.old_origin = np.min(strip_idmeta(self.old_blocks_list), axis=0)