let rec connect_cave' cave (x,y) seen =
try
let unconnected = find_unconnected cave seen in
let closest_connected = find_connected cave unconnected seen in
let cave' = dig_tunnel cave unconnected closest_connected in
connect_cave' cave' unconnected (connected cave' seen)
with Not_found -> cave