def test_cell_access() -> None: grid = Grid(2, 2) assert grid.cell_at(0, 0) == Cell(0, 0) # type: ignore assert grid.cell_at(0, 1) == Cell(0, 1) # type: ignore assert grid.cell_at(1, 0) == Cell(1, 0) # type: ignore assert grid.cell_at(1, 1) == Cell(1, 1) # type: ignore assert grid.cell_at(-1, 0) is None assert grid.cell_at(0, -1) is None assert grid.cell_at(4, 0) is None assert grid.cell_at(0, 4) is None
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 _rotate_cell_neighbors(new_cell: Cell, old_cell: Cell, grid: Grid) -> None: for link in old_cell.links: row, column = Rotator._rotated_coordinates(link, grid) neighbor = grid.cell_at(row, column) if neighbor is None: raise IndexError("Cell not found at row {} column {}".format( row, column)) new_cell.link(neighbor)
def test_neighbors_setup_when_grid_is_created() -> None: grid = Grid(2, 2) assert grid.cell_at(0, 0).north is None # type: ignore assert grid.cell_at(0, 0).south == Cell(1, 0) # type: ignore assert grid.cell_at(0, 0).east == Cell(0, 1) # type: ignore assert grid.cell_at(0, 0).west is None # type: ignore assert grid.cell_at(0, 1).north is None # type: ignore assert grid.cell_at(0, 1).south == Cell(1, 1) # type: ignore assert grid.cell_at(0, 1).east is None # type: ignore assert grid.cell_at(0, 1).west == Cell(0, 0) # type: ignore assert grid.cell_at(1, 0).north == Cell(0, 0) # type: ignore assert grid.cell_at(1, 0).south is None # type: ignore assert grid.cell_at(1, 0).east == Cell(1, 1) # type: ignore assert grid.cell_at(1, 0).west is None # type: ignore assert grid.cell_at(1, 1).north == Cell(0, 1) # type: ignore assert grid.cell_at(1, 1).south is None # type: ignore assert grid.cell_at(1, 1).east is None # type: ignore assert grid.cell_at(1, 1).west == Cell(1, 0) # type: ignore