ID:162286
 
I've written a cavern generation, but there is a problem. Here is an example:
####################################################################################################
############ ################################# ############## ######## ##### ################
########### ########## ################# ########## ###### ## ######## #####
############ ##### ################ ######## ###### ####### ####
############# ############### ######## ##### ######## ###
############## ############### ######### #### ######### ##
############## ## ############### ######### #### ######### #
############# ###### ############## #### #### ######## #
## ##### ######## ## ############# ### #### ##### #
# ### ############## ##### ##### ## ###### #### #
# ## ################ #### ## ###### ##### #
# # ################# ##### #### #### ##### ##
## ## ###### ######## ## ##### #### #### ##### #####
######## ######## #### ##### ## ## ###### #### ######
######### ################### #### ## ###### ## ######
########## ## ################# ##### #### #### #####
################# ############## #### ##### #### ###
### ############# ############## ####### ##### ## ##
## ############# ########## ######## #### ##
## ############# ########## ## ######### ##### ###
# ############# ########## ############## ###### ###
# ############## ############ ################### ######## ##
## ################ ############## #################### ######### #
######################### ######### ###################### ######### #
######################## ################################ ######## #
######################## ############################## ######## ## ##
######################### ######################### ########## #### ####
################# ##### ####################### ############# ###### #####
################ ##### ###################### ############## ####### ######
############### ###### ### ################# ############# ########## #######
############## ####### ################ ############# ###################
############# ######## ################ ############# ##################
############# ####### ##### ################## #################
############## #### ### ################ #################
############### ### #### ############### ###### ###
############### ### #### #### ### ##### ##
### ########## ### ##### #### ##
## ######## ##### ###### ##### ##
## ######## ######## ####### ## ## #### ###
## ####### ############ ####### #### ##### ## ###
## ###### ############# ####### ##### ###### ##
## ###### ############## ###### ##### ## ######## #
# ###### ############### ##### ##### ## ######## #
# ###### ################ ##### ####### ### ####### #
# ##### ############### ################# ##### #
# #### ############# ############### #### #### #
# ## ############ ############## ###### ##### ## #
## ## ############# ############## ############## #### #
######## ## ################ ############### ############### #### #
######## ####################### ############## ################ ### #
####### ############################# ############## ################# ### #
##### ################################## ##### ##### ###################### ##
#### ################################### ## ### ##### ############### ##
### ###################################### ### ##### ############## ##
## ######################## ############# #### #### ############## ##
# ############# ############ ######### ##### ##### ############## #
# ############# ########## ##### ########### ############# #
## ############# ##### ##### ############ ############ #
## ############ #### ##### ############## ########### ##
### ######### ##### ###### ############### ######### ###
#### ################ ### ####### ############## ######## ####
##### ############## ###### ######### #### ###### ######## #####
##### ############ ###### ######### ## ### ######### #####
#### ### ########## ####### ######### ########## ####
### #### ########## ####### ######## ########### ###
### ############### ###### ####### ##### #### ###
### ############## ##### ######## ## ##### #### ####
##### ############ ### ######### #### ### ##########
###### ########### ## ########## ## #### ###########
###### ########### ## ######### #### #### ###########
##### ########### ## ######## #### ## ###########
##### ########### ## ######## #### ##########
##### ########### ### ########### ## #######
#### ########### #### ########## ### ##### ######
### ############ ## #### ## ######### ##### ###### ######
## ##################### #### #### ########## ############# ######
# #################### ### ##### ############## ############## ### #######
# ################### ### ##### ###### ######## ########### ### #############
# ################# # ##### ###### ############### #################
# ############### ###### ##### ############# ################
# ############### ####### ### ############ ## ##########
# ## ################ ########## ### ####### #### #########
# ############## ###### ########### ### ####### ##### ########
# ############# ###### ########### #### ####### ###### #######
# ############## ###### ########### ######### ####### ######## #######
# ###### ####### ##### ############ ######### ####### ############# #######
# ##### #### ##### ############ ######## ###### ############## ########
## ##### #### ####### ############ ## #### ############## ########
## #### ####################### #### ############## ########
# ## ###################### ##### ############# #########
# ######################## # ####### ######### ##########
# ########### ############ ###### ######## ###### ###########
# ########### ############ ####### ######### #### ############
## ######### ############## ###### ######### #### ##### ######
############## ############### ##### ######### #### ##### ######
############# ################# ## ##### ### ########## ##### ##### ######
############# ####################### ###### ############# ############ #######
############# ################################# ############# ############## ########
############## ######################################## ############### ########################
####################################################################################################


You probably already noticed that there are many chunks of cavern that are not connected. I want them to be all connected to form one cavern.

Any idea how I might do this? ;(
I'm using the same algorithim for some maps.

The easiest solution I've found is to take the inverse of that map, and you end up with a fully connected cavern. Then just add walls along the borders randomly. Might not be what you are looking for though.
In response to Obs
That has the same problem as before. The cavern is not always connected.
In response to Koil
One way might be: find the each discrete region, and store their turfs in a list. (Easy enough to do with a flood-fill type of system.) Then find the region with the fewest turfs, and "dilate" it (change all the solid turfs touching the empty turfs in that region into empty). Repeat until you find a turf in a different region touching the 1st region.
Recalculate which regions are connected, and repeat the whole thing until there's only one connected region.

You could also use the "dilate" method, rather than actually making the cavern bigger, to find the closest turfs between one region and one unconnected to it. Then erase a line (maybe a few turfs wide) between those turfs, and you join up two previously unconnected regions.