class Maze: """A 7×7 maze, with methods for adding and removing walls, checking the existence of walls, and producing both a printable version and a MP8-compatible JSON version of the resulting maze """ def __init__(self): self._cells = [[0 for i in range(7)] for j in range(7)] self.fixBorders() def _toggleWall(self, cell, direction): """Internal helper method, not intended for direct use""" self._cells[cell[1]][cell[0]] ^= (1< cto[0]: return 0 if cfrom[0] < cto[0]: return 2 if cfrom[1] > cto[1]: return 3 if cfrom[1] < cto[1]: return 1 def addWall(self, cell, direction): """Add a wall on the given direction of the given cell. Cells are (column, row) pairs, from (0,0) to (6,6) Directions are 3 == 'north' == 'N' == 'up' == 'U' 2 == 'east' == 'E' = 'right' == 'R' 1 == 'south' == 'S' == 'down' == 'D' 0 == 'west' == 'W' == 'left' == 'L' a neighboring cell returns True if the wall didn't exist before, False if it did """ if type(direction) in (tuple,list): direction = Maze._dirFromCellPair(cell,direction) else: direction = Maze._dirParse(direction) old = self._cells[cell[1]][cell[0]] if old & (1<