Beispiel #1
0
 def get_map(self):
     world_map = WorldMap.generate_empty_map(1, 5, self.settings)
     world_map = WorldMapStaticSpawnDecorator(world_map, Location(-2, 0))
     world_map.get_cell(Location(2, 0)).interactable = ScoreLocation(
         world_map.get_cell(Location(2, 0))
     )
     return world_map
Beispiel #2
0
    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))
Beispiel #3
0
    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))
 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 range(6))
     self.assertEqual(expected, actual)
Beispiel #5
0
 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)
Beispiel #6
0
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
    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
Beispiel #8
0
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
Beispiel #9
0
    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
Beispiel #10
0
    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))
Beispiel #11
0
    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 set 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.obstacle = Obstacle.make_obstacle()
                # 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.obstacle = None

        return world_map
Beispiel #12
0
    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))
Beispiel #13
0
 def test_generated_map(self):
     map = WorldMap.generate_empty_map(2, 5)
     self.assertGridSize(map, 5, 2)
Beispiel #14
0
 def get_map(self):
     world_map = WorldMap.generate_empty_map(1, 5, self.settings)
     world_map = WorldMapStaticSpawnDecorator(world_map, Location(-2, 0))
     world_map.get_cell(Location(2, 0)).generates_score = True
     return world_map
Beispiel #15
0
 def get_map(self):
     world_map = WorldMap.generate_empty_map(1, 5, self.settings)
     world_map = WorldMapStaticSpawnDecorator(world_map, Location(-2, 0))
     world_map.get_cell(Location(2, 0)).generates_score = True
     return world_map