def create_maze():

    def make_holes(col1, row1, col2, row2, vertical, horizontal):
        all_lists = []
        list = []
        for row in range(row1, horizontal):
            if has_horizontal_empty(vertical, row):
                list.append((vertical, row))
        if (len(list) > 0):
            all_lists.append(list)
        list = []
        for row in range((horizontal + 1), row2):
            if has_horizontal_empty(vertical, row):
                list.append((vertical, row))
        if (len(list) > 0):
            all_lists.append(list)
        list = []
        for col in range(col1, vertical):
            if has_vertical_empty(col, horizontal):
                list.append((col, horizontal))
        if (len(list) > 0):
            all_lists.append(list)
        list = []
        for col in range((vertical + 1), col2):
            if has_vertical_empty(col, horizontal):
                list.append((col, horizontal))
        if (len(list) > 0):
            all_lists.append(list)
        if (len(all_lists) == 4):
            item_index_to_remove = random.randint(0, 3)
            del all_lists[item_index_to_remove]
        for sub_list in all_lists:
            (hole_col, hole_row) = sub_list[random.randint(0, (len(sub_list) - 1))]
            draw_cell(EMPTY_CELL_COLOR, hole_col, hole_row)
            grid[(hole_col, hole_row)] = EMPTY

    def divide(col1, row1, col2, row2):
        vertical = col2
        if ((col2 - col1) > 2):
            vertical = int((((col2 - col1) / 2) + col1))
            for row in range(row1, row2):
                draw_cell(WALL_CELL_COLOR, vertical, row)
                grid[(vertical, row)] = WALL
        horizontal = row2
        if ((row2 - row1) > 2):
            horizontal = int((((row2 - row1) / 2) + row1))
            for col in range(col1, col2):
                draw_cell(WALL_CELL_COLOR, col, horizontal)
                grid[(col, horizontal)] = WALL
        new_col1 = col1
        new_row1 = row1
        new_col2 = vertical
        new_row2 = horizontal
        if (((new_col2 - new_col1) > 2) or ((new_row2 - new_row1) > 2)):
            (new_vertical, new_horizontal) = divide(new_col1, new_row1, new_col2, new_row2)
            make_holes(new_col1, new_row1, new_col2, new_row2, new_vertical, new_horizontal)
        new_col1 = (vertical + 1)
        new_row1 = row1
        new_col2 = col2
        new_row2 = horizontal
        if (((new_col2 - new_col1) > 2) or ((new_row2 - new_row1) > 2)):
            (new_vertical, new_horizontal) = divide(new_col1, new_row1, new_col2, new_row2)
            make_holes(new_col1, new_row1, new_col2, new_row2, new_vertical, new_horizontal)
        new_col1 = col1
        new_row1 = (horizontal + 1)
        new_col2 = vertical
        new_row2 = row2
        if (((new_col2 - new_col1) > 2) or ((new_row2 - new_row1) > 2)):
            (new_vertical, new_horizontal) = divide(new_col1, new_row1, new_col2, new_row2)
            make_holes(new_col1, new_row1, new_col2, new_row2, new_vertical, new_horizontal)
        new_col1 = (vertical + 1)
        new_row1 = (horizontal + 1)
        new_col2 = col2
        new_row2 = row2
        if (((new_col2 - new_col1) > 2) or ((new_row2 - new_row1) > 2)):
            (new_vertical, new_horizontal) = divide(new_col1, new_row1, new_col2, new_row2)
            make_holes(new_col1, new_row1, new_col2, new_row2, new_vertical, new_horizontal)
        time.sleep(SMALL_SLEEP)
        pygame.display.update()
        return (vertical, horizontal)
    global processing
    processing = True
    initialise()
    draw_grid()
    (new_vertical, new_horizontal) = divide(0, 0, COLS, ROWS)
    make_holes(0, 0, COLS, ROWS, new_vertical, new_horizontal)
    grid[(initial_cell_col, initial_cell_row)] = INITIAL
    grid[(terminal_cell_col, terminal_cell_row)] = TERMINAL
    processing = False
def create_maze():

    def make_holes(col1, row1, col2, row2, vertical, horizontal):
        all_lists = []
        list = []
        for row in range(row1, horizontal):
            if has_horizontal_empty(vertical, row):
                list.append((vertical, row))
        if (len(list) > 0):
            all_lists.append(list)
        list = []
        for row in range((horizontal + 1), row2):
            if has_horizontal_empty(vertical, row):
                list.append((vertical, row))
        if (len(list) > 0):
            all_lists.append(list)
        list = []
        for col in range(col1, vertical):
            if has_vertical_empty(col, horizontal):
                list.append((col, horizontal))
        if (len(list) > 0):
            all_lists.append(list)
        list = []
        for col in range((vertical + 1), col2):
            if has_vertical_empty(col, horizontal):
                list.append((col, horizontal))
        if (len(list) > 0):
            all_lists.append(list)
        if (len(all_lists) == 4):
            item_index_to_remove = random.randint(0, 3)
            del all_lists[item_index_to_remove]
        for sub_list in all_lists:
            (hole_col, hole_row) = sub_list[random.randint(0, (len(sub_list) - 1))]
            draw_cell(EMPTY_CELL_COLOR, hole_col, hole_row)
            grid[(hole_col, hole_row)] = EMPTY

    def divide(col1, row1, col2, row2):
        vertical = col2
        if ((col2 - col1) > 2):
            vertical = int((((col2 - col1) / 2) + col1))
            for row in range(row1, row2):
                draw_cell(WALL_CELL_COLOR, vertical, row)
                grid[(vertical, row)] = WALL
        horizontal = row2
        if ((row2 - row1) > 2):
            horizontal = int((((row2 - row1) / 2) + row1))
            for col in range(col1, col2):
                draw_cell(WALL_CELL_COLOR, col, horizontal)
                grid[(col, horizontal)] = WALL
        new_col1 = col1
        new_row1 = row1
        new_col2 = vertical
        new_row2 = horizontal
        if (((new_col2 - new_col1) > 2) or ((new_row2 - new_row1) > 2)):
            (new_vertical, new_horizontal) = divide(new_col1, new_row1, new_col2, new_row2)
            make_holes(new_col1, new_row1, new_col2, new_row2, new_vertical, new_horizontal)
        new_col1 = (vertical + 1)
        new_row1 = row1
        new_col2 = col2
        new_row2 = horizontal
        if (((new_col2 - new_col1) > 2) or ((new_row2 - new_row1) > 2)):
            (new_vertical, new_horizontal) = divide(new_col1, new_row1, new_col2, new_row2)
            make_holes(new_col1, new_row1, new_col2, new_row2, new_vertical, new_horizontal)
        new_col1 = col1
        new_row1 = (horizontal + 1)
        new_col2 = vertical
        new_row2 = row2
        if (((new_col2 - new_col1) > 2) or ((new_row2 - new_row1) > 2)):
            (new_vertical, new_horizontal) = divide(new_col1, new_row1, new_col2, new_row2)
            make_holes(new_col1, new_row1, new_col2, new_row2, new_vertical, new_horizontal)
        new_col1 = (vertical + 1)
        new_row1 = (horizontal + 1)
        new_col2 = col2
        new_row2 = row2
        if (((new_col2 - new_col1) > 2) or ((new_row2 - new_row1) > 2)):
            (new_vertical, new_horizontal) = divide(new_col1, new_row1, new_col2, new_row2)
            make_holes(new_col1, new_row1, new_col2, new_row2, new_vertical, new_horizontal)
        time.sleep(SMALL_SLEEP)
        pygame.display.update()
        return (vertical, horizontal)
    global processing
    processing = True
    initialise()
    draw_grid()
    (new_vertical, new_horizontal) = divide(0, 0, COLS, ROWS)
    make_holes(0, 0, COLS, ROWS, new_vertical, new_horizontal)
    grid[(initial_cell_col, initial_cell_row)] = INITIAL
    grid[(terminal_cell_col, terminal_cell_row)] = TERMINAL
    processing = False