示例#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
文件: story.py 项目: jlund3/pyre
    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
文件: model.py 项目: 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)
示例#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
文件: model.py 项目: jlund3/pyre
 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
文件: data.py 项目: jlund3/pyre
 def choice(self):
     """Returns a random Entry from the InfoDB"""
     return dice.choice(self.data.values())