-
Notifications
You must be signed in to change notification settings - Fork 0
01 User Defined Level
In this section, we will demonstrate how to create user-defined levels in DMLab.
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.
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},
}In factory scripts, we build the base of our game, including map, textures, pickup items, etc.
factory scripts
Create seekavoid_arena_01 with negative reward set.
| original reward set | negative reward set | |
|---|---|---|
| green apple | 1 | -1 |
| yellow lemon | -1 | 1 |
Place these codes at the specific locations in the lab/ and rebuild DMLab.
-
sk_neg.luaunderlab/game_scripts/levels/ -
seek_avoid_factory.luaunderlab/game_scripts/factories/(replace the original) -
pickups.luaunderlab/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=trueWe 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-reinstallThen again, you may test it via this script
python test.py sk_neg sk_neg.png
The reward objects with positive and negative value have exchanged their appearance.
