fix MemoryTree init, add testcase

This commit is contained in:
SereneWalden 2023-10-05 20:11:38 +08:00
parent f4bb76914b
commit ab91bcc9a2
3 changed files with 13 additions and 4 deletions

View file

@ -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):

View file

@ -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

View file

@ -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()
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")