Skip to content

01 User Defined Level

Lavi22 edited this page Sep 8, 2019 · 2 revisions

In this section, we will demonstrate how to create user-defined levels in DMLab.

Introduction

To create a user-defined level, we should focus on the scripts in lab/game_scripts/levels/ and lab/game_scripts/factories/. For simplicity, we will call these two types of scripts as level script and factory script, respectively. After we complete designing the level, a bazel rebuild is required if we want to use it later in python.

Level

In level scripts, we specify which factory we want to use as the base of our level.
Take lab/game_scripts/levels/seekavoid_arena_01.lua for example:

-- use lab/game_scripts/factories/seek_avoid_factory.lua as the base
local factory = require 'factories.seek_avoid_factory' 

-- pass variables into the factory to build a game
return factory.createLevelApi{
    mapName = 'seekavoid_arena_01',
    episodeLengthSeconds = 20,
    camera = {250, -100, 900},
}

level scripts

Factory

In factory scripts, we build the base of our game, including map, textures, pickup items, etc.
factory scripts


Example

Create seekavoid_arena_01 with negative reward set.

original reward set negative reward set
green apple 1 -1
yellow lemon -1 1

Prepare the required scripts

Place these codes at the specific locations in the lab/ and rebuild DMLab.

  • sk_neg.lua under lab/game_scripts/levels/
  • seek_avoid_factory.lua under lab/game_scripts/factories/ (replace the original)
  • pickups.lua under lab/game_scripts/common/ (replace the original)

In sk_neg.lua, we tell the factory to build a seekavoid_arena_01 with a negative reward set by passing the variable pu='neg'. When the seek_avoid_factory.lua start creating API for the pickup items, it will choose pickups.defaults_neg instead of pickups.defaults as its reward set.

We have created another set of pickup item, pickups.defaults_neg, for this example. However, we will not discuss how to create user-defined pickup items in this section but will go through it later.

(Desktop version only) You may test if the scripts work fine by the following command:

# bazel run :game -- -l <level_name> -s logToStdErr=true 
bazel run :game -- -l sk_neg -s logToStdErr=true

Rebuild DMLab

We suggest people to remove the unnecessary level scripts to speedup this process.

$ bazel build -c opt python/pip_package:build_pip_package
$ ./bazel-bin/python/pip_package/build_pip_package /tmp/dmlab_pkg
$ pip install /tmp/dmlab_pkg/DeepMind_Lab-1.0-py3-none-any.whl --force-reinstall

Then again, you may test it via this script

python test.py sk_neg sk_neg.png

Result

The reward objects with positive and negative value have exchanged their appearance. Result

Clone this wiki locally