From 961b5e36f76e737e3c343696c87d9c4840badd30 Mon Sep 17 00:00:00 2001 From: Chanumask Date: Mon, 13 Nov 2023 10:59:55 +0100 Subject: [PATCH] started maintainer test --- marl_factory_grid/testing/test_config.yaml | 2 +- marl_factory_grid/testing/test_run.py | 2 +- marl_factory_grid/utils/states.py | 40 ++++++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/marl_factory_grid/testing/test_config.yaml b/marl_factory_grid/testing/test_config.yaml index 5c6c8e0..29d36f2 100644 --- a/marl_factory_grid/testing/test_config.yaml +++ b/marl_factory_grid/testing/test_config.yaml @@ -64,7 +64,7 @@ General: individual_rewards: true level_name: large pomdp_r: 3 - verbose: True + verbose: false tests: false Rules: diff --git a/marl_factory_grid/testing/test_run.py b/marl_factory_grid/testing/test_run.py index caf25d3..35112ca 100644 --- a/marl_factory_grid/testing/test_run.py +++ b/marl_factory_grid/testing/test_run.py @@ -7,7 +7,7 @@ from marl_factory_grid.environment.factory import Factory if __name__ == '__main__': # Render at each step? - render = False + render = True # Path to config File path = Path('test_config.yaml') diff --git a/marl_factory_grid/utils/states.py b/marl_factory_grid/utils/states.py index b5f794c..8baf012 100644 --- a/marl_factory_grid/utils/states.py +++ b/marl_factory_grid/utils/states.py @@ -1,3 +1,5 @@ +import json +import os from itertools import islice from typing import List, Tuple @@ -242,6 +244,44 @@ class Gamestate(object): else: return c.NOT_VALID + # def save_gamestate_to_json(self, file_path): + # entity_dicts = {} + # + # for entity_class in self.entities: + # entity_dicts[str(entity_class)] = [] + # for e in entity_class: + # entity_dict = { + # 'name': e.name, + # 'position': getattr(e, 'position', None) if e.var_has_position else None, + # 'var_has_position': e.var_has_position, + # 'var_is_blocking_light': e.var_is_blocking_light, + # 'var_can_move': e.var_can_move, + # 'var_is_blocking_pos': e.var_is_blocking_pos, + # 'var_can_collide': e.var_can_collide + # } + # entity_dicts[str(entity_class)].append(entity_dict) + # + # gamestate_dict = { + # 'entities': entity_dicts, + # # 'parsed_agents_conf': gamestate.agents_conf, + # # 'env_rules': gamestate.rules, + # # 'env_tests': gamestate.tests, + # # 'lvl_shape': gamestate.lvl_shape + # } + # + # if not os.path.exists(file_path): + # open(file_path, 'w').close() + # + # with open(file_path, 'w') as json_file: + # json.dump(gamestate_dict, json_file, indent=4) + # + # with open(file_path, 'r+') as json_file: + # existing_content = json.load(json_file) if os.stat(file_path).st_size > 0 else {} + # existing_content.update(gamestate_dict) + # json_file.seek(0) + # json.dump(existing_content, json_file, indent=4) + + class StepTests: def __init__(self, *args): if args: