def extendBlock(grid, symbol):
    (x, y) = getLeftmosDownCornerPositionOfBlock(grid, symbol)
    (blockX, blockY) = getBlockSize(symbol, grid)
    
    # Check bottom side.
    if x + 1 < len(grid):
        tempBool = True
        for j in range(y, y + blockY):
            if grid[x + 1][j] != 0:
                tempBool = False
                break
        
        if tempBool:
            grid = extendBottom(grid, (x, y), blockY, symbol)
            return grid
                  
    # Check left side.
    if y - 1 >= 0:
        tempBool = True
        for i in range(x - blockX + 1, x + 1):
            if grid[i][y - 1] != 0:
                tempBool = False
                break
            
        if tempBool:
            grid = extendLeft(grid, (x, y), blockX, symbol)
            return grid
        
    # Check top side.
    if x - blockX >= 0:
        tempBool = True
        for j in range(y, y + blockY):
            if grid[x - blockX][j] != 0:
                tempBool = False
                break
            
        if tempBool:
            grid = extendTop(grid, (x, y), blockX, blockY, symbol)
            return grid
        
    
    # Check right side.
    if y + blockY < len(grid[0]):
        tempBool = True
        for i in range(x - blockX + 1, x + 1):
            if grid[i][y + blockY] != 0:
                tempBool = False
                break
    
        if tempBool:
            grid = extendRight(grid, (x, y), blockX, blockY, symbol)
            return grid
            
    
    return grid
Example #2
0
def extendBlock(grid, symbol):
    (x, y) = getLeftmosDownCornerPositionOfBlock(grid, symbol)
    (blockX, blockY) = getBlockSize(symbol, grid)

    # Check bottom side.
    if x + 1 < len(grid):
        tempBool = True
        for j in range(y, y + blockY):
            if grid[x + 1][j] != 0:
                tempBool = False
                break

        if tempBool:
            grid = extendBottom(grid, (x, y), blockY, symbol)
            return grid

    # Check left side.
    if y - 1 >= 0:
        tempBool = True
        for i in range(x - blockX + 1, x + 1):
            if grid[i][y - 1] != 0:
                tempBool = False
                break

        if tempBool:
            grid = extendLeft(grid, (x, y), blockX, symbol)
            return grid

    # Check top side.
    if x - blockX >= 0:
        tempBool = True
        for j in range(y, y + blockY):
            if grid[x - blockX][j] != 0:
                tempBool = False
                break

        if tempBool:
            grid = extendTop(grid, (x, y), blockX, blockY, symbol)
            return grid

    # Check right side.
    if y + blockY < len(grid[0]):
        tempBool = True
        for i in range(x - blockX + 1, x + 1):
            if grid[i][y + blockY] != 0:
                tempBool = False
                break

        if tempBool:
            grid = extendRight(grid, (x, y), blockX, blockY, symbol)
            return grid

    return grid
def getAverageBlockSize(grid):
    totalSizeX = 0
    totalSizeY = 0
    
    totalNo = 0
    for symbol in getBlockSymbolsList(grid):
        totalNo += 1
        (sizeX, sizeY) = (getBlockSize(symbol, grid))  
        totalSizeX += sizeX
        totalSizeY += sizeY
    
    return (totalSizeX/totalNo, totalSizeY/totalNo)
Example #4
0
def getAverageBlockSize(grid):
    totalSizeX = 0
    totalSizeY = 0

    totalNo = 0
    for symbol in getBlockSymbolsList(grid):
        totalNo += 1
        (sizeX, sizeY) = (getBlockSize(symbol, grid))
        totalSizeX += sizeX
        totalSizeY += sizeY

    return (totalSizeX / totalNo, totalSizeY / totalNo)