def get_topmost_junction(cell: Cell) -> str: # special case for 1st row's junctions # # [ X ] [X-east] # junction = UnicodeExporter.EAST + UnicodeExporter.WEST if not cell.linked_to(cast(Cell, cell.east)): junction += UnicodeExporter.SOUTH return UnicodeExporter.JUNCTIONS[junction]
def test_linking() -> None: a_cell = Cell(1, 1) another_cell = Cell(1, 2) yet_another_cell = Cell(2, 1) assert a_cell.linked_to(another_cell) is False assert another_cell.linked_to(a_cell) is False assert a_cell.linked_to(yet_another_cell) is False assert another_cell.linked_to(yet_another_cell) is False a_cell.link(another_cell) assert a_cell.linked_to(another_cell) is True assert another_cell.linked_to(a_cell) is True assert a_cell.linked_to(yet_another_cell) is False assert another_cell.linked_to(yet_another_cell) is False
def get_south_east_junction(cell: Cell) -> str: # Taking advantage that we always go forward east and south, just need to calculate available posibilities # # [ X ] [X-east] # # [ X-south] [X-southeast] # junction = 0 if cell.east: if not cell.linked_to(cell.east): junction += UnicodeExporter.NORTH if not cell.east.south: junction += UnicodeExporter.EAST else: junction += UnicodeExporter.NORTH if cell.south: if not cell.linked_to(cell.south): junction += UnicodeExporter.WEST if not cell.south.east: junction += UnicodeExporter.SOUTH else: junction += UnicodeExporter.WEST if cell.east and cell.south: south_east_cell = cast(Cell, cell.south.east) if not cell.east.linked_to(south_east_cell): junction += UnicodeExporter.EAST if not cell.south.linked_to(south_east_cell): junction += UnicodeExporter.SOUTH try: return UnicodeExporter.JUNCTIONS[junction] except IndexError as ie: print("junction:{} error:{}".format(junction, ie)) return " "
def get_leftmost_junction(cell: Cell) -> str: # # [ X ] # # [ X-south] # junction = UnicodeExporter.NORTH if cell.south: junction += UnicodeExporter.SOUTH if not cell.linked_to(cell.south): junction += UnicodeExporter.EAST else: junction += UnicodeExporter.EAST return UnicodeExporter.JUNCTIONS[junction]