From 70033acd58c1cc986e1157516ff98281505a5697 Mon Sep 17 00:00:00 2001 From: better629 Date: Sat, 14 Oct 2023 23:58:19 +0800 Subject: [PATCH] fix --- examples/st_game/actions/task_decomp.py | 8 ++++---- examples/st_game/memory/agent_memory.py | 6 +++--- examples/st_game/memory/scratch.py | 3 ++- examples/st_game/memory/spatial_memory.py | 2 +- examples/st_game/plan/st_plan.py | 5 +++-- examples/st_game/roles/st_role.py | 9 ++++++--- 6 files changed, 19 insertions(+), 14 deletions(-) diff --git a/examples/st_game/actions/task_decomp.py b/examples/st_game/actions/task_decomp.py index 33b6fddcb..5dab18fe1 100644 --- a/examples/st_game/actions/task_decomp.py +++ b/examples/st_game/actions/task_decomp.py @@ -43,10 +43,10 @@ class TaskDecomp(STAction): i_task = i[0] i_duration = i[1] - i_duration -= (i_duration % 5) - if i_duration > 0: - for j in range(i_duration): - curr_min_slot += [(i_task, count)] + i_duration -= (i_duration % 5) + if i_duration > 0: + for j in range(i_duration): + curr_min_slot += [(i_task, count)] curr_min_slot = curr_min_slot[1:] if len(curr_min_slot) > total_expected_min: diff --git a/examples/st_game/memory/agent_memory.py b/examples/st_game/memory/agent_memory.py index 722246c6b..861273cdb 100644 --- a/examples/st_game/memory/agent_memory.py +++ b/examples/st_game/memory/agent_memory.py @@ -139,16 +139,16 @@ class AgentMemory(Memory): memory_node = memory_node.save_to_dict() memory_json.update(memory_node) with open(memory_saved + "/nodes.json", "w") as outfile: - json.dump(memory_json, outfile) + json.dump(memory_json, outfile, ensure_ascii=False, indent=4) with open(memory_saved + "/embeddings.json", "w") as outfile: - json.dump(self.embeddings, outfile) + json.dump(self.embeddings, outfile, ensure_ascii=False, indent=4) strength_json = dict() strength_json["kw_strength_event"] = self.kw_strength_event strength_json["kw_strength_thought"] = self.kw_strength_thought with open(memory_saved + "/kw_strength.json", "w") as outfile: - json.dump(strength_json, outfile) + json.dump(strength_json, outfile, ensure_ascii=False, indent=4) def load(self, memory_saved: str): """ diff --git a/examples/st_game/memory/scratch.py b/examples/st_game/memory/scratch.py index 39e116fef..00e81b639 100644 --- a/examples/st_game/memory/scratch.py +++ b/examples/st_game/memory/scratch.py @@ -226,7 +226,7 @@ class Scratch: scratch["planned_path"] = self.planned_path with open(out_json, "w") as outfile: - json.dump(scratch, outfile, indent=2) + json.dump(scratch, outfile, ensure_ascii=False, indent=4) def get_f_daily_schedule_index(self, advance=0): """ @@ -453,6 +453,7 @@ class Scratch: x = (x + datetime.timedelta(minutes=1)) end_time = (x + datetime.timedelta(minutes=self.act_duration)) + if end_time.strftime("%H:%M:%S") == self.curr_time.strftime("%H:%M:%S"): return True return False diff --git a/examples/st_game/memory/spatial_memory.py b/examples/st_game/memory/spatial_memory.py index ffd06f930..cf3a9c7f8 100644 --- a/examples/st_game/memory/spatial_memory.py +++ b/examples/st_game/memory/spatial_memory.py @@ -37,7 +37,7 @@ class MemoryTree: def save(self, out_json: str) -> None: with open(out_json, "w") as outfile: - json.dump(self.tree, outfile) + json.dump(self.tree, outfile, ensure_ascii=False, indent=4) def get_str_accessible_sectors(self, curr_world: str) -> str: """ diff --git a/examples/st_game/plan/st_plan.py b/examples/st_game/plan/st_plan.py index b17819ca0..a2349fdc9 100644 --- a/examples/st_game/plan/st_plan.py +++ b/examples/st_game/plan/st_plan.py @@ -29,8 +29,9 @@ def plan(role: "STRole", maze: Maze, roles: dict["STRole"], new_day: bool, retri _long_term_planning(role, new_day) # PART 2: If the current action has expired, we want to create a new plan. - if role.scratch.act_check_finished(): - logger.info("act_check_finished is True") + act_check_finished = role.scratch.act_check_finished() + logger.info(f"Role: {role.name} act_check_finished is {act_check_finished}") + if act_check_finished: _determine_action(role, maze) # PART 3: If you perceived an event that needs to be responded to (saw diff --git a/examples/st_game/roles/st_role.py b/examples/st_game/roles/st_role.py index 5132f62f2..6ace9b46e 100644 --- a/examples/st_game/roles/st_role.py +++ b/examples/st_game/roles/st_role.py @@ -304,14 +304,14 @@ class STRole(Role): .act_description) chat_embedding_pair = (self._rc.scratch.act_description, chat_embedding) - chat_poignancy = generate_poig_score(self._rc.scratch, "chat", + chat_poignancy = generate_poig_score(self, "chat", self._rc.scratch.act_description) chat_node = self._rc.memory.add_chat(self._rc.scratch.curr_time, None, curr_event[0], curr_event[1], curr_event[2], self._rc.scratch.act_description, keywords, chat_poignancy, chat_embedding_pair, self._rc.scratch.chat) - chat_node_ids = [chat_node.node_id] + chat_node_ids = [chat_node.memory_id] # Finally, we add the current event to the agent's memory. ret_events += [self._rc.memory.add_event(self._rc.scratch.curr_time, None, @@ -502,6 +502,9 @@ class STRole(Role): self._rc.env.maze.add_event_from_tile(self.scratch.get_curr_event_and_desc(), new_tile) blank = (self.scratch.get_curr_obj_event_and_desc()[0], None, None, None) self._rc.env.maze.remove_event_from_tile(blank, new_tile) + + # update role's new tile + self._rc.scratch.curr_tile = new_tile else: ret = False time.sleep(1) @@ -547,7 +550,7 @@ class STRole(Role): save_movement(self.name, role_move, step=self.step, sim_code=self.sim_code, curr_time=self.curr_time) # step update - logger.info(f"Role: {self.name} run at {self.step} step on {self.curr_time}") + logger.info(f"Role: {self.name} run at {self.step} step on {self.curr_time} at tile: {self.scratch.curr_tile}") self.step += 1 save_environment(self.name, self.step, self.sim_code, next_tile) self.curr_time += datetime.timedelta(seconds=self.sec_per_step)