def initializeVisibilityMatrix(self):
    global VISIBILITY_MATRIX_CACHE
    if (reduce(str.__add__, self.layoutText) not in VISIBILITY_MATRIX_CACHE):
        from game import Directions
        vecs = [((- 0.5), 0), (0.5, 0), (0, (- 0.5)), (0, 0.5)]
        dirs = [Directions.NORTH, Directions.SOUTH, Directions.WEST, Directions.EAST]
        vis = Grid(self.width, self.height, {Directions.NORTH: set(), Directions.SOUTH: set(), Directions.EAST: set(), Directions.WEST: set(), Directions.STOP: set()})
        for x in range(self.width):
            for y in range(self.height):
                if (self.walls[x][y] == False):
                    for (vec, direction) in zip(vecs, dirs):
                        (dx, dy) = vec
                        (nextx, nexty) = ((x + dx), (y + dy))
                        while (((nextx + nexty) != (int(nextx) + int(nexty))) or (not self.walls[int(nextx)][int(nexty)])):
                            vis[x][y][direction].add((nextx, nexty))
                            (nextx, nexty) = ((x + dx), (y + dy))
        self.visibility = vis
        VISIBILITY_MATRIX_CACHE[reduce(str.__add__, self.layoutText)] = vis
    else:
        self.visibility = VISIBILITY_MATRIX_CACHE[reduce(str.__add__, self.layoutText)]
def initializeVisibilityMatrix(self):
    global VISIBILITY_MATRIX_CACHE
    if (reduce(str.__add__, self.layoutText) not in VISIBILITY_MATRIX_CACHE):
        from game import Directions
        vecs = [((- 0.5), 0), (0.5, 0), (0, (- 0.5)), (0, 0.5)]
        dirs = [Directions.NORTH, Directions.SOUTH, Directions.WEST, Directions.EAST]
        vis = Grid(self.width, self.height, {Directions.NORTH: set(), Directions.SOUTH: set(), Directions.EAST: set(), Directions.WEST: set(), Directions.STOP: set()})
        for x in range(self.width):
            for y in range(self.height):
                if (self.walls[x][y] == False):
                    for (vec, direction) in zip(vecs, dirs):
                        (dx, dy) = vec
                        (nextx, nexty) = ((x + dx), (y + dy))
                        while (((nextx + nexty) != (int(nextx) + int(nexty))) or (not self.walls[int(nextx)][int(nexty)])):
                            vis[x][y][direction].add((nextx, nexty))
                            (nextx, nexty) = ((x + dx), (y + dy))
        self.visibility = vis
        VISIBILITY_MATRIX_CACHE[reduce(str.__add__, self.layoutText)] = vis
    else:
        self.visibility = VISIBILITY_MATRIX_CACHE[reduce(str.__add__, self.layoutText)]