pymasep.engine ============== .. py:module:: pymasep.engine Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/pymasep/engine/engine/index /autoapi/pymasep/engine/environment_engine/index /autoapi/pymasep/engine/external_controller/index Classes ------- .. autoapisummary:: pymasep.engine.Engine pymasep.engine.EnvironmentEngine pymasep.engine.ExternalController Package Contents ---------------- .. py:class:: Engine(app, received_q_id, cfg, max_connection = -1) Bases: :py:obj:`pymasep.application.SubApp` Sub application that manages the main environment :param app: main application :param received_q_id: id of the queue used by the engine to receive messages. :param cfg: configuration of the engine :param max_connection: max number of TCP connection to the engine. -1 means no possible remote communication. .. py:attribute:: environment environment engine .. py:attribute:: old_step :value: None keep last step of the environment. TODO Maybe deprecated .. py:attribute:: end_game :value: False is the game is finished? (all episodes) .. py:attribute:: env_logger logger of the environment of the engine .. py:attribute:: eps Expected engine loop per second .. py:method:: set_engine_for_external_controller() set the engine of all external controllers during registering .. py:method:: define() Wait for the "Define" message and initialize the engine according to message parameters (game, ...) .. py:method:: register(msg_register) Register an interface to the engine. For role "ACTOR", create the external agent, and configure its external controller :param msg_register: Message containing all interface parameters (id, role) .. py:method:: render() Render the engine, i.e., get all observations and send them to the interfaces in the case of an interface with the observer role, the observation is exactly the current state Warning: this method may modify the current state of the environment (the belief part). I.e., assert current_state_before_render ==/!== current_state_after_render. .. py:method:: handle_event() Handle received event. Wait for QUIT, ACTION or REGISTER .. py:method:: update() Update the engine. Mainly the environment .. py:method:: init(id_episode=0) Init an episode of the environment :param id_episode: ID of the episode to initialize .. py:method:: clean() Clean the engine, mainly the environment .. py:method:: run() Main loop of the application. .. py:class:: EnvironmentEngine(id_env = None, cfg = None) Bases: :py:obj:`pymasep.common.environment.Environment` Represents the environment of the game (Engine part). This object keeps all dynamic values of the game. This environment handles all controllers for external agents (interface) as ExternalController :param id_env: the id of the environment. If None, a new uuid will be set :parm cfg: the configuration of the environment .. py:method:: get_type_controller(xml_node = None, template = None, control = None) Get the type of controller according to a template or (exclusive) an XML node. :param xml_node: XML node used to get the controller type. Use the attribute "controller". :param template: The template used to get the controller type. :param control: 'Interface' if the agent is controlled by interface (only inside engine, and if template is used) :return: the class of the controller to use. Default is ExternalController .. py:class:: ExternalController(environment) Bases: :py:obj:`pymasep.common.Controller` External controller to receive action from an interface (local or remote) :param environment: environment for the controller .. py:attribute:: engine :value: None .. py:method:: action_choice(observation, agent) Choose the action. Get it from the action message in the current_event of the engine. If the current coordination method is MULTIPLAYER_COORDINATION_TURN, Act only if it is the turn of the agent that sends the action message. Otherwise, the agent can act whenever he wants. :param observation: The observation used to choose the action. :param agent: The agent who chooses the action. :return: The action chosen for the agent.