示例#1
0
 def on(self, grid: Grid) -> None:
     for row in grid.eachRow():
         run = []
         for cell in row:
             run.append(cell)
             at_eastern_boundary = cell.east is None
             at_northen_boundary = cell.north is None
             should_close_out = at_eastern_boundary or (not at_northen_boundary and randint(0, 1) == 0)
             if should_close_out:
                 member = choice(run)
                 if member.north:
                     member += member.north
                 run.clear()
             else:
                 cell += cell.east  # type: ignore # Made sure cell is not at eastern boundry
             self.step()
示例#2
0
    def render(self, grid: Grid, **kwargs: Any) -> None:
        output = '+' + '---+' * grid.cols + '\n'

        for row in grid.eachRow():
            top = '|'
            bottom = '+'
            for cell in row:
                # NOTE: Book here creates dummy (-1,-1) cell. Not doing it until needed
                body = grid.contents(cell)
                east_boundary = ' ' if cell & cell.east else '|'
                top += body + east_boundary
                south_boundary = '   ' if cell & cell.south else '---'
                corner = '+'
                bottom += south_boundary + corner
            output += top + '\n'
            output += bottom + '\n'

        print(output)
    def render(self, grid: Grid, **kwargs: Any) -> None:
        horizontal_wall = '\u2501'
        vertical_wall = '\u2503'

        output = self.JUNCTIONS[12]
        for x in range(grid.cols - 1):
            output += (horizontal_wall * 3 +
                       self.get_topmost_junction(cast(Cell, grid[0, x])))
        output += horizontal_wall * 3 + self.JUNCTIONS[10] + '\n'

        for row in grid.eachRow():
            top = vertical_wall
            bottom = self.get_leftmost_junction(row[0])
            for cell in row:
                body = grid.contents(cell)
                east_boundary = ' ' if cell & cell.east else vertical_wall
                top += body + east_boundary
                south_boundary = '   ' if cell & cell.south else horizontal_wall * 3
                bottom += south_boundary + self.get_south_east_junction(cell)
            output += top + '\n'
            output += bottom + '\n'

        print(output)