# 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
        child_return = self._child.step(obs)
        self._action_list = child_return["actions"]
        try:
            self._success_callback = child_return["success_callback"]
        except KeyError:
            self._success_callback = None
        try:
            self._failure_callback = child_return["failure_callback"]
        except KeyError:
            self._failure_callback = None

        return self._check_and_return_action(obs)

    def _check_and_return_action(self, obs):
        """
        Check that the first action in self._action_list is among available actions, and return it.
        If it is not, return call the callback argument provided by the last agent, empty the action list,
        and return NO_OP.
        Precondition: self._action_list is not empty.
        :param obs: The observation provided by pysc2.
        :return: The first action of the action list if it is valid, else NO_OP
        """
        current_action = self._action_list.pop(0)
        if current_action.function in obs.observation["available_actions"] \
                and self._check_argument(current_action):
            self._success = True
            return current_action
        else:
            self._action_list = []
            self._success = False

# 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

        child_return = self._child.step(obs)
        self._action_list = child_return["actions"]
        try:
            self._success_callback = child_return["success_callback"]
        except KeyError:
            self._success_callback = None
        try:
            self._failure_callback = child_return["failure_callback"]
        except KeyError:
            self._failure_callback = None

        return self._check_and_return_action(obs)

    def _check_and_return_action(self, obs):
        """
        Check that the first action in self._action_list is among available actions, and return it.
        If it is not, return call the callback argument provided by the last agent, empty the action list,
        and return NO_OP.
        Precondition: self._action_list is not empty.
        :param obs: The observation provided by pysc2.
        :return: The first action of the action list if it is valid, else NO_OP
        """
        current_action = self._action_list.pop(0)
        if current_action.function in obs.observation["available_actions"] \
                and self._check_argument(current_action):
            self._success = True
            return current_action
        else:
            self._action_list = []
            self._success = False

            return actions.FunctionCall(NO_OP, [])