Beispiel #1
0
def town(grid, fill_room=True, add_entrances=False):
    """Adds buildings to a grid"""
    town_dim = (min(grid.cols, grid.rows) - 2) // 7
    room_dim = (grid.cols - 2) // town_dim, (grid.rows - 2) // town_dim

    for x in xrange(town_dim):
        for y in xrange(town_dim):
            pos = types.Coordinate(x * room_dim[0] + 1, y * room_dim[1] + 1)
            room = _create_room(pos, room_dim, .75)
            if room[1][0] - room[0][0] <= 1:
                continue

            if fill_room:
                _fill_room(grid, room, False)
            else:
                _outline_room(grid, room, False)

            if add_entrances:
                if dice.coinflip():
                    doorx = room[0][0] if dice.coinflip() else room[1][0] - 1
                    doory = dice.randrange(room[0][1] + 1, room[1][1] - 1)
                else:
                    doorx = dice.randrange(room[0][0] + 1, room[1][0] - 1)
                    doory = room[0][1] if dice.coinflip() else room[1][1] - 1
                grid[doorx, doory] = True
Beispiel #2
0
def _abstract_half_braid(cols, rows):
    maze = _abstract_perfect(cols, rows)
    deadends = _find_deadends(maze)
    deadends = [end for end in deadends if dice.coinflip()]
    _remove_deadends(maze, deadends)
    return maze