Пример #1
0
Файл: gen.py Проект: jlund3/pyre
 def _get_flood_start(self):
     try:
         candidates = []
         for x in xrange(self.cols):
             for y in xrange(self.rows):
                 if self.state[y][x]:
                     candidates.append(types.Coordinate(x, y))
         return dice.choice(candidates)
     except IndexError:  # no open pos
         return None
Пример #2
0
    def respond(self, query, rstrip='?!.'):
        """Gets a response to the given query"""
        if rstrip:
            query = query.rstrip(rstrip)

        match, answers = -1, ['?']
        for trigger, response in self.responses.iteritems():
            if query.startswith(trigger) and len(trigger) > match:
                match, answers = len(trigger), response
        return dice.choice(answers)
Пример #3
0
    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)
Пример #4
0
Файл: gen.py Проект: 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
Пример #5
0
 def _write(pos, passable):
     tile = dice.choice(floors if passable else walls)
     grid.set_tile(pos, tile, passable)
Пример #6
0
Файл: gen.py Проект: jlund3/pyre
def _remove_deadends(maze, deadends):
    for end in deadends:
        candidates = [end + (1, 0), end + (-1, 0), end + (0, 1), end + (0, -1)]
        candidates = [pos for pos in candidates if pos in maze]
        candidates = [pos for pos in candidates if end not in maze[pos]]
        maze[end].add(dice.choice(candidates))
Пример #7
0
 def choice(self):
     """Returns a random Entry from the InfoDB"""
     return dice.choice(self.data.values())