"""Helpers to mutate a quadrant fixture at grid coordinates.""" def grid_lines(text: str) -> list[str]: """Grid lines without comments, right-padded to full width, as the parser sees them.""" lines = [line for line in text.splitlines() if line.strip() and not line.startswith("#")] width = len(lines[0]) return [line.ljust(width) for line in lines] def edit(text: str, line: int, column: int, replacement: str) -> str: """Overwrite characters of grid line ``line`` (0-based, comments excluded) at ``column``.""" lines = grid_lines(text) target = lines[line] lines[line] = target[:column] + replacement + target[column + len(replacement) :] return "\n".join(lines) + "\n" def cell_line(row: int) -> int: return 2 * row + 1 def wall_line_above(row: int) -> int: return 2 * row def cell_column(col: int) -> int: return 4 * col + 2 def wall_column_left_of(col: int) -> int: return 4 * col def h_segment_column(col: int) -> int: return 4 * col + 1