# Path: oscar/env/shared_objects.py
# class SharedObjects:
#     """
#     Container for shared object between the game thread and the learning thread.
#     Share observations and actions during training
#     """
# 
#     def __init__(self):
#         # Semaphore unlocked when the observation are set
#         self.semaphore_obs_ready = threading.Semaphore(value=0)
#         # Semaphore unlocked when the action is set
#         self.semaphore_action_set = threading.Semaphore(value=0)
#         # shared memory containing the action that must be done by the env
#         self.shared_action = None
#         # shared memory containing the observation get by the env
#         self.shared_obs = None
#         # number of possible action (set by the env)
#         self.action_space = None
#         # shape of the observations given by the env
#         self.observation_space = None
#         # vector masking defining the action that are available or not
#         self.available_action_mask = None


import json
from oscar.env.shared_objects import SharedObjects



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

# Path: oscar/env/shared_objects.py
# class SharedObjects:
#     """
#     Container for shared object between the game thread and the learning thread.
#     Share observations and actions during training
#     """
# 
#     def __init__(self):
#         # Semaphore unlocked when the observation are set
#         self.semaphore_obs_ready = threading.Semaphore(value=0)
#         # Semaphore unlocked when the action is set
#         self.semaphore_action_set = threading.Semaphore(value=0)
#         # shared memory containing the action that must be done by the env
#         self.shared_action = None
#         # shared memory containing the observation get by the env
#         self.shared_obs = None
#         # number of possible action (set by the env)
#         self.action_space = None
#         # shape of the observations given by the env
#         self.observation_space = None
#         # vector masking defining the action that are available or not
#         self.available_action_mask = None


# Path: oscar/hiearchy_factory.py
import json
from oscar.env.shared_objects import SharedObjects




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