pymasep.engine
Submodules
Classes
Sub application that manages the main 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 |
|
External controller to receive action from an interface (local or remote) |
Package Contents
- class pymasep.engine.Engine(app, received_q_id, cfg, max_connection=-1)
Bases:
pymasep.application.SubAppSub application that manages the main environment
- Parameters:
app – main application
received_q_id (int) – id of the queue used by the engine to receive messages.
cfg (omegaconf.DictConfig) – configuration of the engine
max_connection (int) – max number of TCP connection to the engine. -1 means no possible remote communication.
- environment
environment engine
- old_step = None
keep last step of the environment. TODO Maybe deprecated
- end_game = False
is the game is finished? (all episodes)
- env_logger
logger of the environment of the engine
- eps
Expected engine loop per second
- set_engine_for_external_controller()
set the engine of all external controllers during registering
- Return type:
None
- define()
Wait for the “Define” message and initialize the engine according to message parameters (game, …)
- Return type:
None
- register(msg_register)
Register an interface to the engine. For role “ACTOR”, create the external agent, and configure its external controller
- Parameters:
msg_register – Message containing all interface parameters (id, role)
- Return type:
None
- 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.
- Return type:
None
- handle_event()
Handle received event. Wait for QUIT, ACTION or REGISTER
- Return type:
None
- update()
Update the engine. Mainly the environment
- Return type:
None
- init(id_episode=0)
Init an episode of the environment
- Parameters:
id_episode – ID of the episode to initialize
- Return type:
None
- clean()
Clean the engine, mainly the environment
- Return type:
None
- run()
Main loop of the application.
- Return type:
None
- class pymasep.engine.EnvironmentEngine(id_env=None, cfg=None)
Bases:
pymasep.common.environment.EnvironmentRepresents 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
- Parameters:
id_env (str) – the id of the environment. If None, a new uuid will be set
cfg (omegaconf.DictConfig)
- Parm cfg:
the configuration of the environment
- get_type_controller(xml_node=None, template=None, control=None)
Get the type of controller according to a template or (exclusive) an XML node.
- Parameters:
xml_node (Optional[xml.etree.ElementTree.Element]) – XML node used to get the controller type. Use the attribute “controller”.
template (Optional[pymasep.common.template.Template]) – The template used to get the controller type.
control (Optional[str]) – ‘Interface’ if the agent is controlled by interface (only inside engine, and if template is used)
- Returns:
the class of the controller to use. Default is ExternalController
- Return type:
- class pymasep.engine.ExternalController(environment)
Bases:
pymasep.common.ControllerExternal controller to receive action from an interface (local or remote)
- Parameters:
environment – environment for the controller
- engine = None
- 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.
- Parameters:
observation (pymasep.common.State) – The observation used to choose the action.
agent (pymasep.common.Agent) – The agent who chooses the action.
- Returns:
The action chosen for the agent.
- Return type: