-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[tests] Testing the diversty of generated mazes.
Testing the distribution of random mazes for two different mixer seeds, in the process validating the amount of overlaps remains below a 1% threshold.
- Loading branch information
Showing
5 changed files
with
204 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
--[[ Copyright (C) 2018 Google Inc. | ||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 2 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License along | ||
with this program; if not, write to the Free Software Foundation, Inc., | ||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
]] | ||
|
||
local custom_observations = require 'decorators.custom_observations' | ||
local debug_observations = require 'decorators.debug_observations' | ||
local make_map = require 'common.make_map' | ||
local map_maker = require 'dmlab.system.map_maker' | ||
local maze_generation = require 'dmlab.system.maze_generation' | ||
local random = require 'common.random' | ||
|
||
local randomMap = random(map_maker:randomGen()) | ||
|
||
local api = {} | ||
|
||
function api:nextMap() | ||
return api._map | ||
end | ||
|
||
function api:start(episode, seed) | ||
local mapName = 'maze' | ||
random:seed(seed) | ||
randomMap:seed(seed) | ||
api._maze = maze_generation.randomMazeGeneration{ | ||
seed = seed, | ||
width = 17, | ||
height = 17, | ||
maxRooms = 4, | ||
roomMaxSize = 5, | ||
roomMinSize = 3, | ||
extraConnectionProbability = 0.0, | ||
} | ||
api._map = make_map.makeMap{ | ||
mapName = mapName, | ||
mapEntityLayer = api._maze:entityLayer(), | ||
mapVariationsLayer = api._maze:variationsLayer(), | ||
useSkybox = true, | ||
} | ||
debug_observations.setMaze(api._maze) | ||
end | ||
|
||
custom_observations.decorate(api) | ||
|
||
return api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Copyright 2018 Google Inc. | ||
# | ||
# This program is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation; either version 2 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along | ||
# with this program; if not, write to the Free Software Foundation, Inc., | ||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
|
||
import os | ||
import unittest | ||
import numpy as np | ||
|
||
import deepmind_lab | ||
|
||
MAZE_LAYOUT_OBSERVATION = 'DEBUG.MAZE.LAYOUT' | ||
MAZE_LAYOUT_TRIALS = 50 | ||
|
||
|
||
class MazeGenerationTest(unittest.TestCase): | ||
|
||
def test_maze_layout_spread(self): | ||
layouts = set() | ||
for i in xrange(MAZE_LAYOUT_TRIALS): | ||
print('phase 1: trial {} out of {}'.format(i+1, MAZE_LAYOUT_TRIALS)) | ||
env = deepmind_lab.Lab( | ||
'tests/maze_generation_test', [MAZE_LAYOUT_OBSERVATION], config={}) | ||
env.reset(seed=i+1) | ||
layouts.add(env.observations()[MAZE_LAYOUT_OBSERVATION]) | ||
num_layouts = len(layouts) | ||
self.assertTrue(np.isclose(num_layouts, MAZE_LAYOUT_TRIALS)) | ||
for i in xrange(MAZE_LAYOUT_TRIALS): | ||
print('phase 2: trial {} out of {}'.format(i+1, MAZE_LAYOUT_TRIALS)) | ||
env = deepmind_lab.Lab( | ||
'tests/maze_generation_test', [MAZE_LAYOUT_OBSERVATION], | ||
config={ | ||
'mixerSeed': '0', | ||
}) | ||
env.reset(seed=i+1) | ||
layouts.add(env.observations()[MAZE_LAYOUT_OBSERVATION]) | ||
self.assertEqual(len(layouts), num_layouts) | ||
for i in xrange(MAZE_LAYOUT_TRIALS): | ||
print('phase 3: trial {} out of {}'.format(i+1, MAZE_LAYOUT_TRIALS)) | ||
env = deepmind_lab.Lab( | ||
'tests/maze_generation_test', [MAZE_LAYOUT_OBSERVATION], | ||
config={ | ||
'mixerSeed': '1', | ||
}) | ||
env.reset(seed=i+1) | ||
layouts.add(env.observations()[MAZE_LAYOUT_OBSERVATION]) | ||
self.assertTrue(np.isclose(len(layouts) - num_layouts, MAZE_LAYOUT_TRIALS)) | ||
|
||
if __name__ == '__main__': | ||
if 'TEST_SRCDIR' in os.environ: | ||
deepmind_lab.set_runfiles_path( | ||
os.path.join(os.environ['TEST_SRCDIR'], | ||
'org_deepmind_lab')) | ||
unittest.main() |