Example #1
0
File: gen.py Project: jlund3/pyre
def _create_room(pos, room_dim, room_chance):
    if dice.chance(room_chance):
        dim = dice.rand_coordinate(3, 3, room_dim[0] - 1, room_dim[1] - 1)
    else:
        dim = types.Coordinate(1, 1)
    off_max = room_dim - dim
    off = dice.rand_coordinate(1, 1, off_max[0], off_max[1])
    return pos + off, pos + off + dim
Example #2
0
File: model.py Project: jlund3/pyre
    def get_random_pos(self, select, tries=100):
        """Returns a random Coordinate for which select(pos) is True"""
        for _ in xrange(tries):
            pos = dice.rand_coordinate(self.cols, self.rows)
            if select(pos):
                return pos

        candidates = []
        for x in xrange(self.cols):
            for y in xrange(self.rows):
                pos = types.Coordinate(x, y)
                if select(pos):
                    candidates.append(pos)
        return dice.choice(candidates)
Example #3
0
File: gen.py Project: jlund3/pyre
def _raise_ellipses(hmap, cols, rows, iters=250):
    radi = cols // 8, rows // 8
    radi2 = radi[0] ** 2, radi[1] ** 2

    for _ in xrange(iters):
        center = dice.rand_coordinate(cols, rows)
        for dx in xrange(-radi[0], radi[0]):
            for dy in xrange(-radi[1], radi[1]):
                # wrap horizontally
                x, y = (center[0] + dx) % cols, center[1] + dy
                if y < 0 or y >= rows:
                    continue

                # find componentwise distance from center
                off_x, off_y = abs(center[0] - x), abs(center[1] - y)
                off_x = min(off_x, cols - off_x)

                # if inside ellipse, raise height
                if off_x ** 2 / radi2[0] + off_y ** 2 / radi2[1] < 1:
                    hmap[x][y] += 1
Example #4
0
File: gen.py Project: jlund3/pyre
def _abstract_perfect(cols, rows):
    maze, visited = {}, {}
    for x in xrange(cols):
        for y in xrange(rows):
            pos = types.Coordinate(x, y)
            maze[pos] = set()
            visited[pos] = False
    start = dice.rand_coordinate(cols, rows)
    stack = [start]
    visited[start] = True

    while stack:
        curr = stack[-1]

        try:
            dig = dice.choice(_expand(curr, visited))
            stack.append(dig)
            visited[dig] = True
            maze[curr].add(dig)
        except IndexError:  # no unvisited adjacent for choice
            stack.pop()

    return maze
Example #5
0
File: gen.py Project: jlund3/pyre
def _room_connect_source(room):
    try:
        return dice.rand_coordinate(room[0][0] + 1, room[0][1] + 1,
                                    room[1][0] - 1, room[1][1] - 1)
    except ValueError:  # room size less than 3x3
        return room[0]