From ab91bcc9a2e4f2bf761efc1523911323d7aa770f Mon Sep 17 00:00:00 2001 From: SereneWalden <22496084+SereneWalden@users.noreply.github.com> Date: Thu, 5 Oct 2023 20:11:38 +0800 Subject: [PATCH] fix MemoryTree init, add testcase --- examples/st_game/memory/spatial_memory.py | 6 +++++- examples/st_game/tests/test_maze.py | 3 +++ examples/st_game/tests/test_spatial_memory.py | 8 +++++--- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/examples/st_game/memory/spatial_memory.py b/examples/st_game/memory/spatial_memory.py index f9a4847c8..87d16b635 100644 --- a/examples/st_game/memory/spatial_memory.py +++ b/examples/st_game/memory/spatial_memory.py @@ -8,10 +8,14 @@ memory that aids in grounding their behavior in the game world. import json import os +from ..utils.utils import check_if_file_exists class MemoryTree: - def __init__(self) -> None: + def __init__(self, f_saved: str): self.tree = {} + if check_if_file_exists(f_saved): + with open(f_saved) as f: + self.tree = json.load(f) def set_mem_path(self, f_saved: str): if os.path.isfile(f_saved) and os.path.exists(f_saved): diff --git a/examples/st_game/tests/test_maze.py b/examples/st_game/tests/test_maze.py index 9c2327703..c81179fe9 100644 --- a/examples/st_game/tests/test_maze.py +++ b/examples/st_game/tests/test_maze.py @@ -3,6 +3,9 @@ from ..maze import Maze def test_maze_init(): maze = Maze(maze_asset_path=MAZE_ASSET_PATH) + assert maze.maze_height == 100 + assert maze.maze_width == 140 + diff --git a/examples/st_game/tests/test_spatial_memory.py b/examples/st_game/tests/test_spatial_memory.py index ee8acd600..579fc9f6f 100644 --- a/examples/st_game/tests/test_spatial_memory.py +++ b/examples/st_game/tests/test_spatial_memory.py @@ -2,6 +2,8 @@ from ..utils.const import STORAGE_PATH from ..memory.spatial_memory import MemoryTree def test_spatial_memory(): - x = STORAGE_PATH.joinpath("base_the_ville_isabella_maria_klaus\personas\Isabella Rodriguez\bootstrap_memory\spatial_memory.json") - x = MemoryTree(x) - x.print_tree() \ No newline at end of file + f_path = STORAGE_PATH.joinpath("base_the_ville_isabella_maria_klaus/personas/Isabella Rodriguez/bootstrap_memory/spatial_memory.json") + x = MemoryTree(f_path) + assert x.tree + assert "the Ville" in x.tree + assert "Isabella Rodriguez's apartment" in x.get_str_accessible_sectors("the Ville") \ No newline at end of file