Implementing a new environment type

To create a new environment type, you need to create a new class that inherits from the GenericEnvironment class.

An environment object has three separate configuration attributes:

  • settings is an class attribute. It should be an instance of EnvSettings. It contains all kinds of attributes that are relevant for every environment instance of this type. For example, it can specify whether higher or lower ratings are better.

  • env_info contains general information about the environment instance: its identifier and its display name.

  • config_json contains arbitrary (JSON-based) configuration of the environment instance. For example, for a chess environment, it might contain the opponent strength or the color of the player (if it is not chosen randomly).

The environment class must implement the following methods:

  • new_run() creates a new run. Concretely, it should return the state of the new run (JSON-based). For example, for a chess environment, it might return the initial board state.

  • get_action_request() should return a new action request for a given run. It gets passed a RunData object, which contains the history of the run so far, including the state. It should return a ActionRequest, which contains the data that should be conveyed to the agent (it might be the state/sensor information/…).

  • act() gets passed the action sent by the agent (arbitrary JSON) and a RunData object. It should return a ActionResult that might contain the new state, the outcome, or an error message.

  • view_env() gets passed an EnvData object containing some data about the agents and recent runs in the environment instance. It should return an HTML string that is displayed in the environment view. For example, it can contain a leader board. You can get a simple default implementation by also inheriting from SimpleViewEnv.

  • view_agent() gets passed an AgentDataSummary object containing some data about the agent. It should return an HTML string that is displayed when viewing the agent (e.g. its rating and its recent runs). If you do not implement it, viewing an agent is not possible. You can get a simple default implementation by also inheriting from SimpleViewAgent.

  • view_run() gets passed a RunData object containing some data about the run. It should return an HTML string that is displayed when viewing the run. For example, it can contain a visualization of the run (e.g. an animation of the chess game). If you do not implement it, viewing a run is not possible.