# Path: oscar/hiearchy_factory.py
# def build_hierarchy(configuration_filename: str):
#     """
#     Builds a hierarchy of agents from a json file
#     :param configuration_filename: the path of the configuration file to be loaded
#     :return: the general agent and a shared memory for training
#     """
#     with open(configuration_filename) as configuration_file:
#         configuration = json.load(configuration_file)
# 
#     # Convert structure ids to integers (in place)
#     configuration["structure"] = {int(k): [int(i) for i in v] for k, v in configuration["structure"].items()}
#     check_configuration(configuration)
# 
#     # Create a maintained set of instantiated agents
#     instantiated = {}
# 
#     # build shared objects to be associated with agents later
#     shared = build_shared(configuration)
# 
#     # Setup a training memory for agent in training mode
#     training_memory = SharedObjects()
# 
#     # Build hierarchy and return general's children
#     general_agent = build_agent(configuration, instantiated, shared, 0, training_memory)
# 
#     # if the training memory is not set with agent value, then nobody use it
#     # then delete it
#     if training_memory.action_space is None:
#         training_memory = None
# 
#     return general_agent, training_memory
# 
# Path: oscar/constants.py
# NO_OP = actions.FUNCTIONS.no_op.id


from pysc2.lib import actions
from pysc2.agents.base_agent import BaseAgent
from oscar.hiearchy_factory import build_hierarchy
from oscar.constants import NO_OP
import time


DEFAULT_CONFIGURATION = "config/full_hierarchy.json"
# DEFAULT_CONFIGURATION = "config/idleSCVtest.json"


class General(BaseAgent):
    """
    The agent at the top of the command chain. It is usually him that will be the interface with PySC2
    """
    def __init__(self, configuration_filename=DEFAULT_CONFIGURATION):
        """
        Initializes members and call hierarchy factory
        :param configuration_filename: The configuration file to pass to the hierarchy factory on launch
        """
        super().__init__()

# Path: oscar/hiearchy_factory.py
# def build_hierarchy(configuration_filename: str):
#     """
#     Builds a hierarchy of agents from a json file
#     :param configuration_filename: the path of the configuration file to be loaded
#     :return: the general agent and a shared memory for training
#     """
#     with open(configuration_filename) as configuration_file:
#         configuration = json.load(configuration_file)
# 
#     # Convert structure ids to integers (in place)
#     configuration["structure"] = {int(k): [int(i) for i in v] for k, v in configuration["structure"].items()}
#     check_configuration(configuration)
# 
#     # Create a maintained set of instantiated agents
#     instantiated = {}
# 
#     # build shared objects to be associated with agents later
#     shared = build_shared(configuration)
# 
#     # Setup a training memory for agent in training mode
#     training_memory = SharedObjects()
# 
#     # Build hierarchy and return general's children
#     general_agent = build_agent(configuration, instantiated, shared, 0, training_memory)
# 
#     # if the training memory is not set with agent value, then nobody use it
#     # then delete it
#     if training_memory.action_space is None:
#         training_memory = None
# 
#     return general_agent, training_memory
# 
# Path: oscar/constants.py
# NO_OP = actions.FUNCTIONS.no_op.id


# Path: oscar/agent/commander/general.py
from pysc2.lib import actions
from pysc2.agents.base_agent import BaseAgent
from oscar.hiearchy_factory import build_hierarchy
from oscar.constants import NO_OP
import time



DEFAULT_CONFIGURATION = "config/full_hierarchy.json"
# DEFAULT_CONFIGURATION = "config/idleSCVtest.json"


class General(BaseAgent):
    """
    The agent at the top of the command chain. It is usually him that will be the interface with PySC2
    """
    def __init__(self, configuration_filename=DEFAULT_CONFIGURATION):
        """
        Initializes members and call hierarchy factory
        :param configuration_filename: The configuration file to pass to the hierarchy factory on launch
        """
        super().__init__()

        self._child, self.training_memory = build_hierarchy(configuration_filename)