本文整理汇总了Python中simulation.world_map.WorldMap.generate_empty_map方法的典型用法代码示例。如果您正苦于以下问题:Python WorldMap.generate_empty_map方法的具体用法?Python WorldMap.generate_empty_map怎么用?Python WorldMap.generate_empty_map使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类simulation.world_map.WorldMap
的用法示例。
在下文中一共展示了WorldMap.generate_empty_map方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_out_of_bounds_random_edge
# 需要导入模块: from simulation.world_map import WorldMap [as 别名]
# 或者: from simulation.world_map.WorldMap import generate_empty_map [as 别名]
def test_out_of_bounds_random_edge(self):
map = WorldMap.generate_empty_map(3, 4, {})
with self.assertRaisesRegexp(ValueError, 'Beyond range'):
get_random_edge_index(map, rng=ConstantRng(-1))
with self.assertRaisesRegexp(ValueError, 'Beyond range'):
get_random_edge_index(map, rng=ConstantRng(6))
示例2: test_get_random_edge_index_can_give_all_possible
# 需要导入模块: from simulation.world_map import WorldMap [as 别名]
# 或者: from simulation.world_map.WorldMap import generate_empty_map [as 别名]
def test_get_random_edge_index_can_give_all_possible(self):
map = WorldMap.generate_empty_map(3, 4, {})
get_random_edge_index(map, rng=ConstantRng(1))
expected = frozenset((
(0, 1), (1, 1),
(-1, 0), (2, 0),
(0, -1), (1, -1),
))
actual = frozenset(get_random_edge_index(map, rng=ConstantRng(i))
for i in xrange(6))
self.assertEqual(expected, actual)
示例3: generate_map
# 需要导入模块: from simulation.world_map import WorldMap [as 别名]
# 或者: from simulation.world_map.WorldMap import generate_empty_map [as 别名]
def generate_map(height, width, obstacle_ratio=0.1):
world_map = WorldMap.generate_empty_map(height, width)
# We designate one non-corner edge cell as empty, to ensure that the map can be expanded
always_empty_edge_x, always_empty_edge_y = get_random_edge_index(world_map)
always_empty_location = Location(always_empty_edge_x, always_empty_edge_y)
for cell in shuffled(world_map.all_cells()):
if cell.location != always_empty_location and random.random() < obstacle_ratio:
cell.habitable = False
# So long as all habitable neighbours can still reach each other,
# then the map cannot get bisected
if not _all_habitable_neighbours_can_reach_each_other(cell, world_map):
cell.habitable = True
return world_map
示例4: get_map
# 需要导入模块: from simulation.world_map import WorldMap [as 别名]
# 或者: from simulation.world_map.WorldMap import generate_empty_map [as 别名]
def get_map(self):
height = self.settings['START_HEIGHT']
width = self.settings['START_WIDTH']
world_map = WorldMap.generate_empty_map(height, width, self.settings)
# We designate one non-corner edge cell as empty, to ensure that the map can be expanded
always_empty_edge_x, always_empty_edge_y = get_random_edge_index(world_map)
always_empty_location = Location(always_empty_edge_x, always_empty_edge_y)
for cell in shuffled(world_map.all_cells()):
if cell.location != always_empty_location and random.random() < self.settings['OBSTACLE_RATIO']:
cell.habitable = False
# So long as all habitable neighbours can still reach each other,
# then the map cannot get bisected
if not _all_habitable_neighbours_can_reach_each_other(cell, world_map):
cell.habitable = True
return world_map
示例5: test_get_random_edge_index
# 需要导入模块: from simulation.world_map import WorldMap [as 别名]
# 或者: from simulation.world_map.WorldMap import generate_empty_map [as 别名]
def test_get_random_edge_index(self):
map = WorldMap.generate_empty_map(3, 4, {})
self.assertEqual(
(0, -1), get_random_edge_index(map, rng=ConstantRng(0)))
self.assertEqual(
(1, -1), get_random_edge_index(map, rng=ConstantRng(1)))
self.assertEqual(
(0, 1), get_random_edge_index(map, rng=ConstantRng(2)))
self.assertEqual(
(1, 1), get_random_edge_index(map, rng=ConstantRng(3)))
self.assertEqual(
(-1, 0), get_random_edge_index(map, rng=ConstantRng(4)))
self.assertEqual(
(2, 0), get_random_edge_index(map, rng=ConstantRng(5)))
# Verify no out of bounds
with self.assertRaisesRegexp(ValueError, 'Beyond range'):
get_random_edge_index(map, rng=ConstantRng(-1))
with self.assertRaisesRegexp(ValueError, 'Beyond range'):
get_random_edge_index(map, rng=ConstantRng(6))
示例6: test_generated_map
# 需要导入模块: from simulation.world_map import WorldMap [as 别名]
# 或者: from simulation.world_map.WorldMap import generate_empty_map [as 别名]
def test_generated_map(self):
map = WorldMap.generate_empty_map(2, 5)
self.assertGridSize(map, 5, 2)