def floodFindEmpty(grid, tries, goal):
    times_remade = 0
    percentage = 0
    while ((times_remade < tries) and (percentage < goal)):
        copy_grid = [row[:] for row in grid]
        open_count = 0
        times_remade += 1
        unvisited = deque([])
        new_grid = [[1 for x in range(len(grid[0]))] for y in range(len(grid))]
        randx = random.randint(0, (len(grid) - 1))
        randy = random.randint(0, (len(grid[0]) - 1))
        while (grid[randx][randy] == 1):
            randx = random.randint(0, (len(grid) - 1))
            randy = random.randint(0, (len(grid[0]) - 1))
        unvisited.append([randx, randy])
        while (len(unvisited) > 0):
            current = unvisited.popleft()
            new_grid[current[0]][current[1]] = 0
            for k in range((- 1), 2):
                for l in range((- 1), 2):
                    if (((current[0] + k) >= 0) and ((current[0] + k) < len(grid)) and ((current[1] + l) >= 0) and ((current[1] + l) < len(grid[0]))):
                        if (copy_grid[(current[0] + k)][(current[1] + l)] == 0):
                            copy_grid[(current[0] + k)][(current[1] + l)] = 2
                            open_count += 1
                            unvisited.append([(current[0] + k), (current[1] + l)])
        percentage = ((open_count * 100) / (len(grid) * len(grid[0])))
        print('counted {0}, {1}%...'.format(open_count, percentage))
    return (new_grid, percentage)
def floodFindEmpty(grid, tries, goal):
    times_remade = 0
    percentage = 0
    while ((times_remade < tries) and (percentage < goal)):
        copy_grid = [row[:] for row in grid]
        open_count = 0
        times_remade += 1
        unvisited = deque([])
        new_grid = [[1 for x in range(len(grid[0]))] for y in range(len(grid))]
        randx = random.randint(0, (len(grid) - 1))
        randy = random.randint(0, (len(grid[0]) - 1))
        while (grid[randx][randy] == 1):
            randx = random.randint(0, (len(grid) - 1))
            randy = random.randint(0, (len(grid[0]) - 1))
        unvisited.append([randx, randy])
        while (len(unvisited) > 0):
            current = unvisited.popleft()
            new_grid[current[0]][current[1]] = 0
            for k in range((- 1), 2):
                for l in range((- 1), 2):
                    if (((current[0] + k) >= 0) and ((current[0] + k) < len(grid)) and ((current[1] + l) >= 0) and ((current[1] + l) < len(grid[0]))):
                        if (copy_grid[(current[0] + k)][(current[1] + l)] == 0):
                            copy_grid[(current[0] + k)][(current[1] + l)] = 2
                            open_count += 1
                            unvisited.append([(current[0] + k), (current[1] + l)])
        percentage = ((open_count * 100) / (len(grid) * len(grid[0])))
        print('counted {0}, {1}%...'.format(open_count, percentage))
    return (new_grid, percentage)