Пример #1
0
    def test_bent_vertical(self):
        """
        Test that horizontal corridor with bend can be made
        """
        edge_connection = Connection(connection=None,
                                     location=(9, 0),
                                     direction="down",
                                     section=self.section)

        room_connection = Connection(connection=None,
                                     location=(2, 9),
                                     direction="up",
                                     section=self.section)

        add_section_connection(self.section, edge_connection)
        add_room_connection(self.section, (2, 9), "up")

        generator = CorridorGenerator(start_point=edge_connection,
                                      end_point=room_connection,
                                      wall_tile=None,
                                      floor_tile=self.floor_rock)

        generator.generate()

        assert_that(wall_tile(self.level, (9, 0)),
                    is_(equal_to(None)))
        assert_that(wall_tile(self.level, (2, 9)),
                    is_(equal_to(None)))
        assert_that(self.level, is_fully_accessible())
Пример #2
0
    def test_unconnected_level(self):
        """
        Test that unconnected level is reported correctly
        """
        for loc_x in range(2, 5):
            wall_tile(self.level, (loc_x, 2), self.wall_empty)
            wall_tile(self.level, (loc_x, 5), self.wall_empty)

        assert_that(self.matcher._matches(self.level), is_(equal_to(False)))
Пример #3
0
    def test_unconnected_level(self):
        """
        Test that unconnected level is reported correctly
        """
        for loc_x in range(2, 5):
            wall_tile(self.level, (loc_x, 2), self.wall_empty)
            wall_tile(self.level, (loc_x, 5), self.wall_empty)

        assert_that(self.matcher._matches(self.level), is_(equal_to(False)))
Пример #4
0
    def get_wall_tile(self, level, location):
        """
        Calculate correct wall tile

        :param level: level to decorate
        :type level: Level
        :param location: location in level
        :type location: (int, int)
        :rtype: int
        """

        directions = []
        loc_x, loc_y = location
        wall_tiles = []
        wall_tiles.append(self.configuration.wall)
        wall_tiles.extend(self.tiles.values())

        pillar = self.check_pillar(level, location)
        if pillar:
            return pillar

        if wall_tile(level, (loc_x, loc_y - 1)) in self.configuration.tiles:
            if not (is_wall(level, (loc_x - 1, loc_y - 1), wall_tiles)
                    and is_wall(level, (loc_x + 1, loc_y - 1), wall_tiles)
                    and is_wall(level, (loc_x - 1, loc_y), wall_tiles)
                    and is_wall(level, (loc_x + 1, loc_y), wall_tiles)):
                directions.append('1')
        if wall_tile(level, (loc_x + 1, loc_y)) in self.configuration.tiles:
            if not (is_wall(level, (loc_x + 1, loc_y - 1), wall_tiles)
                    and is_wall(level, (loc_x + 1, loc_y + 1), wall_tiles)
                    and is_wall(level, (loc_x, loc_y - 1), wall_tiles)
                    and is_wall(level, (loc_x, loc_y + 1), wall_tiles)):
                directions.append('3')
        if wall_tile(level, (loc_x, loc_y + 1)) in self.configuration.tiles:
            if not (is_wall(level, (loc_x - 1, loc_y + 1), wall_tiles)
                    and is_wall(level, (loc_x + 1, loc_y + 1), wall_tiles)
                    and is_wall(level, (loc_x - 1, loc_y), wall_tiles)
                    and is_wall(level, (loc_x + 1, loc_y), wall_tiles)):
                directions.append('5')
        if wall_tile(level, (loc_x - 1, loc_y)) in self.configuration.tiles:
            if not (is_wall(level, (loc_x - 1, loc_y - 1), wall_tiles)
                    and is_wall(level, (loc_x - 1, loc_y + 1), wall_tiles)
                    and is_wall(level, (loc_x, loc_y - 1), wall_tiles)
                    and is_wall(level, (loc_x, loc_y + 1), wall_tiles)):
                directions.append('7')

        key = ''.join(directions)

        if key in self.tiles:
            return self.tiles[''.join(directions)]
        else:
            return self.configuration.four_way
Пример #5
0
    def get_wall_tile(self, level, location):
        """
        Calculate correct wall tile

        :param level: level to decorate
        :type level: Level
        :param location: location in level
        :type location: (int, int)
        :rtype: int
        """

        directions = []
        loc_x, loc_y = location
        wall_tiles = []
        wall_tiles.append(self.configuration.wall)
        wall_tiles.extend(self.tiles.values())

        pillar = self.check_pillar(level, location)
        if pillar:
            return pillar

        if wall_tile(level, (loc_x, loc_y - 1)) in self.configuration.tiles:
            if not (is_wall(level, (loc_x - 1, loc_y - 1), wall_tiles)
                    and is_wall(level, (loc_x + 1, loc_y - 1), wall_tiles)
                    and is_wall(level, (loc_x - 1, loc_y), wall_tiles)
                    and is_wall(level, (loc_x + 1, loc_y), wall_tiles)):
                directions.append('1')
        if wall_tile(level, (loc_x + 1, loc_y)) in self.configuration.tiles:
            if not (is_wall(level, (loc_x + 1, loc_y - 1), wall_tiles)
                    and is_wall(level, (loc_x + 1, loc_y + 1), wall_tiles)
                    and is_wall(level, (loc_x, loc_y - 1), wall_tiles)
                    and is_wall(level, (loc_x, loc_y + 1), wall_tiles)):
                directions.append('3')
        if wall_tile(level, (loc_x, loc_y + 1)) in self.configuration.tiles:
            if not (is_wall(level, (loc_x - 1, loc_y + 1), wall_tiles)
                    and is_wall(level, (loc_x + 1, loc_y + 1), wall_tiles)
                    and is_wall(level, (loc_x - 1, loc_y), wall_tiles)
                    and is_wall(level, (loc_x + 1, loc_y), wall_tiles)):
                directions.append('5')
        if wall_tile(level, (loc_x - 1, loc_y)) in self.configuration.tiles:
            if not (is_wall(level, (loc_x - 1, loc_y - 1), wall_tiles)
                    and is_wall(level, (loc_x - 1, loc_y + 1), wall_tiles)
                    and is_wall(level, (loc_x, loc_y - 1), wall_tiles)
                    and is_wall(level, (loc_x, loc_y + 1), wall_tiles)):
                directions.append('7')

        key = ''.join(directions)

        if key in self.tiles:
            return self.tiles[''.join(directions)]
        else:
            return self.configuration.four_way
Пример #6
0
    def check_pillar(self, level, location):
        "check for possible pillar"
        tiles = self.configuration.tiles
        x_loc, y_loc = location
        
        if (wall_tile(level, (x_loc - 1, y_loc)) not in tiles
                and wall_tile(level, (x_loc + 1, y_loc)) not in tiles
                and wall_tile(level, (x_loc, y_loc - 1)) not in tiles
                and wall_tile(level, (x_loc, y_loc + 1)) not in tiles):

            return self.configuration.wall

        return None
Пример #7
0
    def check_pillar(self, level, location):
        "check for possible pillar"
        tiles = self.configuration.tiles
        x_loc, y_loc = location

        if (wall_tile(level, (x_loc - 1, y_loc)) not in tiles
                and wall_tile(level, (x_loc + 1, y_loc)) not in tiles
                and wall_tile(level, (x_loc, y_loc - 1)) not in tiles
                and wall_tile(level, (x_loc, y_loc + 1)) not in tiles):

            return self.configuration.wall

        return None
Пример #8
0
    def check_and_replace(self, location, level):
        """
        Check location and replace tile if it matches configuration

        :param location: location to check
        :type location: (integer, integer)
        :param level: level to use
        :type level: Level
        """
        proto_tile = wall_tile(level, location)

        if proto_tile in self.configuration.wall_config:
            tile = self.configuration.wall_config[proto_tile]
            wall_tile(level, location, tile)
Пример #9
0
    def test_targeting_wall(self):
        """
        When targeting wall, it should be reported
        """
        wall_tile(self.level, (10, 20), SOLID_WALL)

        params = SpellCastingParameters(caster=self.caster,
                                        direction=5,
                                        spell_name='proto')

        targets = targeting_single_target(params)
        target = targets[0]

        assert_that(target, is_(wall_target_at((10, 20))))
Пример #10
0
    def test_retrieving_previous_tile(self):
        """
        When reporting target, the previous tile should be reported too
        """
        wall_tile(self.level, (10, 20), SOLID_WALL)

        params = SpellCastingParameters(caster=self.caster,
                                        direction=5,
                                        spell_name='proto')

        targets = targeting_single_target(params)
        target = targets[0].previous_target

        assert_that(target, is_(void_target_at((10, 19))))
Пример #11
0
    def test_targeting_wall(self):
        """
        When targeting wall, it should be reported
        """
        wall_tile(self.level, (10, 20), SOLID_WALL)

        params = SpellCastingParameters(caster = self.caster,
                                        direction = 5,
                                        spell_name = 'proto')

        targets = targeting_single_target(params)
        target = targets[0]

        assert_that(target, is_(wall_target_at((10, 20))))
Пример #12
0
    def check_and_replace(self, location, level):
        """
        Check location and replace tile if it matches configuration

        :param location: location to check
        :type location: (integer, integer)
        :param level: level to use
        :type level: Level
        """
        proto_tile = wall_tile(level, location)

        if proto_tile in self.configuration.wall_config:
            tile = self.configuration.wall_config[proto_tile]
            wall_tile(level, location, tile)
Пример #13
0
    def test_retrieving_previous_tile(self):
        """
        When reporting target, the previous tile should be reported too
        """
        wall_tile(self.level, (10, 20), SOLID_WALL)

        params = SpellCastingParameters(caster = self.caster,
                                        direction = 5,
                                        spell_name = 'proto')

        targets = targeting_single_target(params)
        target = targets[0].previous_target

        assert_that(target, is_(void_target_at((10, 19))))
    def setup(self):
        """
        Setup the test case
        """
        self.wall_empty = 1
        self.level = (LevelBuilder().with_size((10, 15)).with_floor_tile(
            FLOOR_NATURAL).with_wall_tile(WALL_NATURAL).build())

        for loc_y in range(2, 8):
            for loc_x in range(2, 8):
                wall_tile(self.level, (loc_x, loc_y), self.wall_empty)

        self.config = WallBuilderDecoratorConfig(
            ['crypt'], {WALL_NATURAL: WALL_CONSTRUCTED}, self.wall_empty)

        self.decorator = WallBuilderDecorator(self.config)
    def test_building_walls(self):
        """
        Test that tiles next to empty space are replaced
        """
        self.decorator.decorate_level(self.level)

        for loc in range(2, 8):
            assert_that(wall_tile(self.level, (loc, 1)),
                        is_(equal_to(WALL_CONSTRUCTED)))
            assert_that(wall_tile(self.level, (loc, 8)),
                        is_(equal_to(WALL_CONSTRUCTED)))
            assert_that(wall_tile(self.level, (1, loc)),
                        is_(equal_to(WALL_CONSTRUCTED)))
            assert_that(wall_tile(self.level, (8, loc)),
                        is_(equal_to(WALL_CONSTRUCTED)))

        assert_that(wall_tile(self.level, (0, 0)), is_(equal_to(WALL_NATURAL)))
Пример #16
0
    def test_that_open_corners_work(self):
        """
        Test that finding connectivity with open corners work
        """
        wall_tile(self.level, (0, 0), self.wall_empty)
        wall_tile(self.level, (20, 0), self.wall_empty)
        wall_tile(self.level, (0, 10), self.wall_empty)
        wall_tile(self.level, (20, 10), self.wall_empty)

        assert_that(self.matcher._matches(self.level), is_(equal_to(False)))
Пример #17
0
    def test_that_open_corners_work(self):
        """
        Test that finding connectivity with open corners work
        """
        wall_tile(self.level, (0, 0), self.wall_empty)
        wall_tile(self.level, (20, 0), self.wall_empty)
        wall_tile(self.level, (0, 10), self.wall_empty)
        wall_tile(self.level, (20, 10), self.wall_empty)

        assert_that(self.matcher._matches(self.level), is_(equal_to(False)))
Пример #18
0
    def test_building_walls(self):
        """
        Test that tiles next to empty space are replaced
        """
        self.decorator.decorate_level(self.level)

        for loc in range(2, 8):
            assert_that(wall_tile(self.level, (loc, 1)),
                        is_(equal_to(WALL_CONSTRUCTED)))
            assert_that(wall_tile(self.level, (loc, 8)),
                        is_(equal_to(WALL_CONSTRUCTED)))
            assert_that(wall_tile(self.level, (1, loc)),
                        is_(equal_to(WALL_CONSTRUCTED)))
            assert_that(wall_tile(self.level, (8, loc)),
                        is_(equal_to(WALL_CONSTRUCTED)))

        assert_that(wall_tile(self.level, (0, 0)),
                    is_(equal_to(WALL_NATURAL)))
Пример #19
0
    def setup(self):
        """
        Setup the test case
        """
        self.wall_empty = 1
        self.level = (LevelBuilder()
                      .with_size((10, 15))
                      .with_floor_tile(FLOOR_NATURAL)
                      .with_wall_tile(WALL_NATURAL)
                      .build())

        for loc_y in range(2, 8):
            for loc_x in range(2, 8):
                wall_tile(self.level, (loc_x, loc_y), self.wall_empty)

        self.config = WallBuilderDecoratorConfig(['crypt'],
                                            {WALL_NATURAL: WALL_CONSTRUCTED},
                                            self.wall_empty)

        self.decorator = WallBuilderDecorator(self.config)
Пример #20
0
    def build(self):
        """
        Build level

        Returns:
            Level
        """
        level = new_level(self.model)

        for x_loc in range(self.level_size[0]):
            for y_loc in range(self.level_size[1]):
                wall_tile(level, (x_loc, y_loc), self.wall_tile)
                floor_tile(level, (x_loc, y_loc), self.floor_tile)

        for wall in self.walls:
            wall_tile(level, wall, self.solid_wall_tile)

        for creature in self.characters:
            add_character(level, creature.location, creature)

        return level
Пример #21
0
    def test_ornamentation_rate_can_be_controlled(self):
        """
        There should be way to control how frequently walls are ornamented
        """
        wall_tile(self.level, (2, 2), self.wall)
        wall_tile(self.level, (3, 2), self.wall)
        wall_tile(self.level, (4, 2), self.wall)

        rng = mock()
        when(rng).randint(any(), any()).thenReturn(0).thenReturn(100).thenReturn(0)
        when(rng).choice(any()).thenReturn(self.ornamentation)

        self.config = WallOrnamentDecoratorConfig(
                                        ['any level'],
                                        wall_tile = self.wall,
                                        ornamentation = [self.ornamentation],
                                        rng = rng,
                                        rate = 50)
        self.decorator = WallOrnamentDecorator(self.config)

        self.decorator.decorate_level(self.level)

        candle_count = 0
        for location, tile in get_tiles(self.level):
            if self.ornamentation in tile['\ufdd0:ornamentation']:
                candle_count = candle_count + 1

        assert_that(candle_count, is_(equal_to(2)))
    def test_ornamentation_rate_can_be_controlled(self):
        """
        There should be way to control how frequently walls are ornamented
        """
        wall_tile(self.level, (2, 2), self.wall)
        wall_tile(self.level, (3, 2), self.wall)
        wall_tile(self.level, (4, 2), self.wall)

        rng = mock()
        when(rng).randint(any(),
                          any()).thenReturn(0).thenReturn(100).thenReturn(0)
        when(rng).choice(any()).thenReturn(self.ornamentation)

        self.config = WallOrnamentDecoratorConfig(
            ['any level'],
            wall_tile=self.wall,
            ornamentation=[self.ornamentation],
            rng=rng,
            rate=50)
        self.decorator = WallOrnamentDecorator(self.config)

        self.decorator.decorate_level(self.level)

        candle_count = 0
        for location, tile in get_tiles(self.level):
            if self.ornamentation in tile['\ufdd0:ornamentation']:
                candle_count = candle_count + 1

        assert_that(candle_count, is_(equal_to(2)))
Пример #23
0
    def test_generate_simple_room(self):
        """
        Test that generator can create a simple room
        """
        self.generator.generate_room(self.section)

        room_found = False
        for y_loc in range(20):
            for x_loc in range(20):
                if wall_tile(self.level, (x_loc, y_loc)) != self.wall_empty:
                    room_found = True

        assert_that(room_found, is_(True))
Пример #24
0
    def test_generate_simple_room(self):
        """
        Test that generator can create a simple room
        """
        self.generator.generate_room(self.section)

        room_found = False
        for y_loc in range(20):
            for x_loc in range(20):
                if wall_tile(self.level, (x_loc, y_loc)) != self.wall_empty:
                    room_found = True

        assert_that(room_found, is_(True))
Пример #25
0
    def test_simple_level_creation(self):
        """
        Test that simple level creation works
        """
        level = (LevelBuilder()
                 .with_size((20, 20))
                 .with_floor_tile(self.floor_rock)
                 .with_wall_tile(self.wall_empty)
                 .build())

        assert not (level is None)
        assert(floor_tile(level, (5, 5)) == self.floor_rock)
        assert(wall_tile(level, (0, 0)) == self.wall_empty)
Пример #26
0
    def test_simple_level_creation(self):
        """
        Test that simple level creation works
        """
        level = (LevelBuilder()
                 .with_size((20, 20))
                 .with_floor_tile(self.floor_rock)
                 .with_wall_tile(self.wall_empty)
                 .build())

        assert not (level is None)
        assert(floor_tile(level, (5, 5)) == self.floor_rock)
        assert(wall_tile(level, (0, 0)) == self.wall_empty)
Пример #27
0
    def get_connected_points(self, level, start, open_tile, connected_points):
        """
        Get all points that are connected to a given point

        Args:
            level: level to check
            start: start location
            open: ID of tile considered open

        Returns:
            list of connected points
        """
        x_loc = start[0]
        y_loc = start[1]

        if start in connected_points:
            return None

        if get_tile(level, start) is None:
            return None

        if wall_tile(level, start) is None:
            connected_points.append(start)
            self.get_connected_points(level, (x_loc, y_loc - 1),
                                      open_tile,
                                      connected_points)
            self.get_connected_points(level, (x_loc, y_loc + 1),
                                      open_tile,
                                      connected_points)
            self.get_connected_points(level, (x_loc - 1, y_loc),
                                      open_tile,
                                      connected_points)
            self.get_connected_points(level, (x_loc + 1, y_loc),
                                      open_tile,
                                      connected_points)

            self.get_connected_points(level, (x_loc - 1, y_loc - 1),
                                      open_tile,
                                      connected_points)
            self.get_connected_points(level, (x_loc - 1, y_loc + 1),
                                      open_tile,
                                      connected_points)
            self.get_connected_points(level, (x_loc - 1, y_loc - 1),
                                      open_tile,
                                      connected_points)
            self.get_connected_points(level, (x_loc + 1, y_loc + 1),
                                      open_tile,
                                      connected_points)

        return connected_points
Пример #28
0
    def test_connected_level(self):
        """
        Test that connected level is reported correctly
        """
        for loc_x in range(2, 8):
            wall_tile(self.level, (loc_x, 3), self.wall_empty)
            wall_tile(self.level, (loc_x, 6), self.wall_empty)
            wall_tile(self.level, (5, loc_x), self.wall_empty)

        assert_that(self.matcher._matches(self.level), is_(equal_to(True)))
Пример #29
0
    def test_connected_level(self):
        """
        Test that connected level is reported correctly
        """
        for loc_x in range(2, 8):
            wall_tile(self.level, (loc_x, 3), self.wall_empty)
            wall_tile(self.level, (loc_x, 6), self.wall_empty)
            wall_tile(self.level, (5, loc_x), self.wall_empty)

        assert_that(self.matcher._matches(self.level), is_(equal_to(True)))
Пример #30
0
    def test_that_all_points_are_found(self):
        """
        Test that connectivity can find all open points
        """
        wall_tile(self.level, (0, 0), self.wall_empty)
        wall_tile(self.level, (5, 5), self.wall_empty)
        wall_tile(self.level, (20, 10), self.wall_empty)

        points = self.matcher.get_all_points(self.level, self.wall_empty)

        assert_that(points, has_length(3))
Пример #31
0
    def test_that_all_points_are_found(self):
        """
        Test that connectivity can find all open points
        """
        wall_tile(self.level, (0, 0), self.wall_empty)
        wall_tile(self.level, (5, 5), self.wall_empty)
        wall_tile(self.level, (20, 10), self.wall_empty)

        points = self.matcher.get_all_points(self.level, self.wall_empty)

        assert_that(points, has_length(3))
Пример #32
0
    def test_building_basic_walls(self):
        """
        Test that basic wall can be built
        """
        self.decorator.decorate_level(self.level)

        assert_that(wall_tile(self.level, (1, 1)), is_(equal_to('east-south')))
        assert_that(wall_tile(self.level, (2, 1)), is_(equal_to('east-west')))
        assert_that(wall_tile(self.level, (3, 1)), is_(equal_to('west-south')))
        assert_that(wall_tile(self.level, (1, 2)), is_(equal_to('north-south')))
        assert_that(wall_tile(self.level, (1, 3)), is_(equal_to('east-north')))
        assert_that(wall_tile(self.level, (3, 3)), is_(equal_to('west-north')))
    def test_building_basic_walls(self):
        """
        Test that basic wall can be built
        """
        self.decorator.decorate_level(self.level)

        assert_that(wall_tile(self.level, (1, 1)), is_(equal_to('east-south')))
        assert_that(wall_tile(self.level, (2, 1)), is_(equal_to('east-west')))
        assert_that(wall_tile(self.level, (3, 1)), is_(equal_to('west-south')))
        assert_that(wall_tile(self.level, (1, 2)),
                    is_(equal_to('north-south')))
        assert_that(wall_tile(self.level, (1, 3)), is_(equal_to('east-north')))
        assert_that(wall_tile(self.level, (3, 3)), is_(equal_to('west-north')))
Пример #34
0
    def get_connected_points(self, level, start, open_tile, connected_points):
        """
        Get all points that are connected to a given point

        Args:
            level: level to check
            start: start location
            open: ID of tile considered open

        Returns:
            list of connected points
        """
        x_loc = start[0]
        y_loc = start[1]

        if start in connected_points:
            return None

        if get_tile(level, start) is None:
            return None

        if wall_tile(level, start) is None:
            connected_points.append(start)
            self.get_connected_points(level, (x_loc, y_loc - 1), open_tile,
                                      connected_points)
            self.get_connected_points(level, (x_loc, y_loc + 1), open_tile,
                                      connected_points)
            self.get_connected_points(level, (x_loc - 1, y_loc), open_tile,
                                      connected_points)
            self.get_connected_points(level, (x_loc + 1, y_loc), open_tile,
                                      connected_points)

            self.get_connected_points(level, (x_loc - 1, y_loc - 1), open_tile,
                                      connected_points)
            self.get_connected_points(level, (x_loc - 1, y_loc + 1), open_tile,
                                      connected_points)
            self.get_connected_points(level, (x_loc - 1, y_loc - 1), open_tile,
                                      connected_points)
            self.get_connected_points(level, (x_loc + 1, y_loc + 1), open_tile,
                                      connected_points)

        return connected_points
Пример #35
0
    def test_splash_does_not_penetrate_walls(self):
        """
        In normal situations, splash should be stopped by walls
        """
        wall_tile(self.level, (6, 4), SOLID_WALL)
        wall_tile(self.level, (6, 5), SOLID_WALL)
        wall_tile(self.level, (6, 6), SOLID_WALL)

        params = SpellCastingParameters(caster=self.caster,
                                        direction=7,
                                        spell_name='proto')

        data = targeting_spherical_area(params, radius=6)

        targets = [x.target for x in data if x.target]

        assert_that(targets, has_length(0))
Пример #36
0
    def test_splash_does_not_penetrate_walls(self):
        """
        In normal situations, splash should be stopped by walls
        """
        wall_tile(self.level, (6, 4), SOLID_WALL)
        wall_tile(self.level, (6, 5), SOLID_WALL)
        wall_tile(self.level, (6, 6), SOLID_WALL)

        params = SpellCastingParameters(caster = self.caster,
                                        direction = 7,
                                        spell_name = 'proto')

        data = targeting_spherical_area(params,
                                        radius = 6)

        targets = [x.target for x in data
                   if x.target]

        assert_that(targets, has_length(0))
Пример #37
0
    def test_walls_can_be_ornamented(self):
        """
        Ornaments should be placed only on walls
        """
        wall_tile(self.level, (2, 2), self.wall)
        wall_tile(self.level, (3, 2), self.wall)
        wall_tile(self.level, (3, 2), self.wall)

        rng = mock()
        when(rng).randint(any(), any()).thenReturn(0)
        when(rng).choice(any()).thenReturn(self.ornamentation)

        self.config = WallOrnamentDecoratorConfig(
                                        ['any level'],
                                        wall_tile = self.wall,
                                        ornamentation = [self.ornamentation],
                                        rng = rng,
                                        rate = 100)
        self.decorator = WallOrnamentDecorator(self.config)

        self.decorator.decorate_level(self.level)

        assert_that(ornamentation(self.level, (2, 2)),
                    is_(equal_to([self.ornamentation])))
    def test_walls_can_be_ornamented(self):
        """
        Ornaments should be placed only on walls
        """
        wall_tile(self.level, (2, 2), self.wall)
        wall_tile(self.level, (3, 2), self.wall)
        wall_tile(self.level, (3, 2), self.wall)

        rng = mock()
        when(rng).randint(any(), any()).thenReturn(0)
        when(rng).choice(any()).thenReturn(self.ornamentation)

        self.config = WallOrnamentDecoratorConfig(
            ['any level'],
            wall_tile=self.wall,
            ornamentation=[self.ornamentation],
            rng=rng,
            rate=100)
        self.decorator = WallOrnamentDecorator(self.config)

        self.decorator.decorate_level(self.level)

        assert_that(ornamentation(self.level, (2, 2)),
                    is_(equal_to([self.ornamentation])))
Пример #39
0
    def test_that_convoluted_case_works(self):
        """
        Test a convoluted case with 3 open areas and 2 of them being connected
        to border
        """
        self.level = (
            LevelBuilder().with_size((10, 10)).with_floor_tile(self.floor_rock).with_wall_tile(self.wall_ground).build()
        )

        wall_tile(self.level, (2, 5), self.wall_empty)
        wall_tile(self.level, (2, 6), self.wall_empty)
        wall_tile(self.level, (2, 7), self.wall_empty)
        wall_tile(self.level, (2, 8), self.wall_empty)
        wall_tile(self.level, (2, 9), self.wall_empty)
        wall_tile(self.level, (2, 10), self.wall_empty)

        wall_tile(self.level, (5, 8), self.wall_empty)

        wall_tile(self.level, (5, 2), self.wall_empty)
        wall_tile(self.level, (6, 2), self.wall_empty)
        wall_tile(self.level, (7, 2), self.wall_empty)
        wall_tile(self.level, (8, 2), self.wall_empty)
        wall_tile(self.level, (9, 2), self.wall_empty)
        wall_tile(self.level, (10, 2), self.wall_empty)

        all_points = self.matcher.get_all_points(self.level, self.wall_empty)
        connected_points = self.matcher.get_connected_points(self.level, all_points[0], self.wall_empty, [])

        assert_that(self.matcher._matches(self.level), is_(equal_to(False)))
Пример #40
0
def is_wall(level, location, wall_tiles):
    "check if given location is considered as a wall"
    return (get_tile(level, location) is None 
            or wall_tile(level, location) in wall_tiles)
Пример #41
0
def is_wall(level, location, wall_tiles):
    "check if given location is considered as a wall"
    return (get_tile(level, location) is None
            or wall_tile(level, location) in wall_tiles)
Пример #42
0
    def test_that_convoluted_case_works(self):
        """
        Test a convoluted case with 3 open areas and 2 of them being connected
        to border
        """
        self.level = (LevelBuilder().with_size((10, 10)).with_floor_tile(
            self.floor_rock).with_wall_tile(self.wall_ground).build())

        wall_tile(self.level, (2, 5), self.wall_empty)
        wall_tile(self.level, (2, 6), self.wall_empty)
        wall_tile(self.level, (2, 7), self.wall_empty)
        wall_tile(self.level, (2, 8), self.wall_empty)
        wall_tile(self.level, (2, 9), self.wall_empty)
        wall_tile(self.level, (2, 10), self.wall_empty)

        wall_tile(self.level, (5, 8), self.wall_empty)

        wall_tile(self.level, (5, 2), self.wall_empty)
        wall_tile(self.level, (6, 2), self.wall_empty)
        wall_tile(self.level, (7, 2), self.wall_empty)
        wall_tile(self.level, (8, 2), self.wall_empty)
        wall_tile(self.level, (9, 2), self.wall_empty)
        wall_tile(self.level, (10, 2), self.wall_empty)

        all_points = self.matcher.get_all_points(self.level, self.wall_empty)
        connected_points = self.matcher.get_connected_points(
            self.level, all_points[0], self.wall_empty, [])

        assert_that(self.matcher._matches(self.level), is_(equal_to(False)))
Пример #43
0
    def setup(self):
        """
        Setup the test case
        """
        self.level = (LevelBuilder()
                      .with_size((10, 10))
                      .with_floor_tile('floor')
                      .with_wall_tile(self.empty_wall)
                      .build())

        wall_tile(self.level, (1, 1), self.wall)
        wall_tile(self.level, (2, 1), self.wall)
        wall_tile(self.level, (3, 1), self.wall)

        wall_tile(self.level, (1, 2), self.wall)
        wall_tile(self.level, (1, 3), self.wall)

        wall_tile(self.level, (2, 3), self.wall)
        wall_tile(self.level, (3, 3), self.wall)

        wall_tile(self.level, (3, 2), self.wall)

        self.config = DirectionalWallDecoratorConfig(level_types = ['crypt'],
                                                   east_west = 'east-west',
                                                   east_north = 'east-north',
                                                   east_south = 'east-south',
                                                   west_north = 'west-north',
                                                   west_south = 'west-south',
                                                   north_south = 'north-south',
                                                   east_west_north = 'east-west-north',
                                                   east_west_south = 'east-west-south',
                                                   east_north_south = 'east-north-south',
                                                   west_north_south = 'west-north-south',
                                                   four_way = 'four-way',
                                                   wall = self.wall)

        self.decorator = DirectionalWallDecorator(self.config)
Пример #44
0
    def test_only_northern_wall_is_decorated(self):
        """
        Ornamentations should be placed only on northern walls
        """
        wall_tile(self.level, (2, 2), self.wall)
        wall_tile(self.level, (3, 2), self.wall)
        wall_tile(self.level, (4, 2), self.wall)

        floor_tile(self.level, (2, 3), self.floor)
        floor_tile(self.level, (3, 3), self.floor)
        floor_tile(self.level, (4, 3), self.floor)

        wall_tile(self.level, (2, 4), self.wall)
        wall_tile(self.level, (3, 4), self.wall)
        wall_tile(self.level, (4, 4), self.wall)

        floor_tile(self.level, (2, 5), self.empty_floor)
        floor_tile(self.level, (4, 5), self.empty_floor)
        floor_tile(self.level, (4, 5), self.empty_floor)

        rng = mock()
        when(rng).randint(any(), any()).thenReturn(0)
        when(rng).choice(any()).thenReturn(self.ornamentation)

        self.config = WallOrnamentDecoratorConfig(
                                        ['any level'],
                                        wall_tile = self.wall,
                                        ornamentation = [self.ornamentation],
                                        rng = rng,
                                        rate = 100)

        self.decorator = WallOrnamentDecorator(self.config)

        self.decorator.decorate_level(self.level)

        assert_that(ornamentation(self.level, (2, 2)),
                    is_(equal_to([self.ornamentation])))
        assert_that(ornamentation(self.level, (2, 4)),
                    is_(equal_to([])))
    def setup(self):
        """
        Setup the test case
        """
        self.level = (LevelBuilder().with_size(
            (10, 10)).with_floor_tile('floor').with_wall_tile(
                self.empty_wall).build())

        wall_tile(self.level, (1, 1), self.wall)
        wall_tile(self.level, (2, 1), self.wall)
        wall_tile(self.level, (3, 1), self.wall)

        wall_tile(self.level, (1, 2), self.wall)
        wall_tile(self.level, (1, 3), self.wall)

        wall_tile(self.level, (2, 3), self.wall)
        wall_tile(self.level, (3, 3), self.wall)

        wall_tile(self.level, (3, 2), self.wall)

        self.config = DirectionalWallDecoratorConfig(
            level_types=['crypt'],
            east_west='east-west',
            east_north='east-north',
            east_south='east-south',
            west_north='west-north',
            west_south='west-south',
            north_south='north-south',
            east_west_north='east-west-north',
            east_west_south='east-west-south',
            east_north_south='east-north-south',
            west_north_south='west-north-south',
            four_way='four-way',
            wall=self.wall)

        self.decorator = DirectionalWallDecorator(self.config)
    def test_only_northern_wall_is_decorated(self):
        """
        Ornamentations should be placed only on northern walls
        """
        wall_tile(self.level, (2, 2), self.wall)
        wall_tile(self.level, (3, 2), self.wall)
        wall_tile(self.level, (4, 2), self.wall)

        floor_tile(self.level, (2, 3), self.floor)
        floor_tile(self.level, (3, 3), self.floor)
        floor_tile(self.level, (4, 3), self.floor)

        wall_tile(self.level, (2, 4), self.wall)
        wall_tile(self.level, (3, 4), self.wall)
        wall_tile(self.level, (4, 4), self.wall)

        floor_tile(self.level, (2, 5), self.empty_floor)
        floor_tile(self.level, (4, 5), self.empty_floor)
        floor_tile(self.level, (4, 5), self.empty_floor)

        rng = mock()
        when(rng).randint(any(), any()).thenReturn(0)
        when(rng).choice(any()).thenReturn(self.ornamentation)

        self.config = WallOrnamentDecoratorConfig(
            ['any level'],
            wall_tile=self.wall,
            ornamentation=[self.ornamentation],
            rng=rng,
            rate=100)

        self.decorator = WallOrnamentDecorator(self.config)

        self.decorator.decorate_level(self.level)

        assert_that(ornamentation(self.level, (2, 2)),
                    is_(equal_to([self.ornamentation])))
        assert_that(ornamentation(self.level, (2, 4)), is_(equal_to([])))