Episode Recorder

This example focuses on:

  • Episode recording settings configuration
  • Controller interfacing (Gamepad or Keyboard)

Even if this example shows how to record episode generated by a human player, the same wrapper can be used with any kind of agent, including trained bots. It can thus be leveraged to collect a dataset for offline training.

A dedicated section describing the episode recording wrapper settings is presented here and provides additional details on their usage and purpose.

Depending on the Operating System used, specific permissions may be needed in order to read the keyboard inputs.

- On Windows, by default no specific permissions are needed. However, if you have some third-party security software you may need to white-list Python.
- On Linux you need to add the user the input group: sudo usermod -aG input $USER
- On Mac, it is possible you need to use the settings application to allow your program to access the input devices (see this reference).

Official inputs python package reference guide can be found at this link

import os
from os.path import expanduser
import diambra.arena
from diambra.arena import SpaceTypes, EnvironmentSettings, RecordingSettings
from diambra.arena.utils.controller import get_diambra_controller
import argparse

def main(use_controller):
    # Environment Settings
    settings = EnvironmentSettings()
    settings.step_ratio = 1
    settings.frame_shape = (256, 256, 1)
    settings.action_space = SpaceTypes.MULTI_DISCRETE

    # Recording settings
    home_dir = expanduser("~")
    game_id = "doapp"
    recording_settings = RecordingSettings()
    recording_settings.dataset_path = os.path.join(home_dir, "DIAMBRA/episode_recording", game_id if use_controller else "mock")
    recording_settings.username = "alexpalms"

    env = diambra.arena.make(game_id, settings, episode_recording_settings=recording_settings, render_mode="human")

    if use_controller is True:
        # Controller initialization
        controller = get_diambra_controller(env.get_actions_tuples())

    observation, info = env.reset(seed=42)

    while True:
        if use_controller is True:
            actions = controller.get_actions()
            actions = env.action_space.sample()
        observation, reward, terminated, truncated, info = env.step(actions)
        done = terminated or truncated
        if done:
            observation, info = env.reset()

    if use_controller is True:

    # Return success
    return 0

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument('--use_controller', type=int, default=1, help='Flag to activate use of controller')
    opt = parser.parse_args()