def render(self, grid: Grid, **kwargs: Any) -> None: horizontal_wall = "\u2501" vertical_wall = "\u2503" output = self.JUNCTIONS[12] for x in range(grid.columns - 1): output += (horizontal_wall * 3 + self.get_topmost_junction( cast(Cell, grid.cell_at(row=0, column=x)))) output += horizontal_wall * 3 + self.JUNCTIONS[10] + "\n" for row in grid.each_row(): top = vertical_wall bottom = self.get_leftmost_junction(row[0]) for cell in row: body = grid.contents_of(cell) east_boundary = " " if cell.linked_to( cell.east) else vertical_wall top += body + east_boundary south_boundary = " " if cell.linked_to( cell.south) else horizontal_wall * 3 bottom += south_boundary + self.get_south_east_junction(cell) output += top + "\n" output += bottom + "\n" print(output)
def on(self, grid: Grid) -> None: for row in grid.each_row(): 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 += cast(Cell, cell.east)
def on(grid: Grid) -> Grid: for row in grid.each_row(): 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.link(member.north) run.clear() else: cell.link(cell.east) return grid
def render(self, grid: Grid, **kwargs: Any) -> None: output = "+" + "---+" * grid.columns + "\n" for row in grid.each_row(): top = "|" bottom = "+" for cell in row: # NOTE: Book here creates dummy (-1,-1) cell. Not doing it until needed body = grid.contents_of(cell) east_boundary = " " if cell.linked_to(cell.east) else "|" top += body + east_boundary south_boundary = " " if cell.linked_to(cell.south) else "---" corner = "+" bottom += south_boundary + corner output += top + "\n" output += bottom + "\n" print(output)
def render(grid: Grid) -> None: """ Renders to stdout an ASCII representation of the maze. Rendering starts with top walls and nortwest corner setup, so it only needs to care of each cell's east and south walls. """ output = "+" + "---+" * grid.columns + "\n" for row in grid.each_row(): top = "|" bottom = "+" for cell in row: # NOTE: Book here creates dummy (-1,-1) cell. Not doing it until needed body = " " east_boundary = " " if cell.linked_to(cell.east) else "|" top += body + east_boundary south_boundary = " " if cell.linked_to(cell.south) else "---" corner = "+" bottom += south_boundary + corner output += top + "\n" output += bottom + "\n" print(output)