let find_unconnected cave seen =
let rec loop (searched, tosearch) =
if IntPairSet.is_empty tosearch
then raise Not_found
else
(IntPairSet.iter
(fun (x,y) ->
if get cave x y = FLOOR &&
not (IntPairSet.exists (fun z -> z = (x,y)) seen)
then raise (IntPairSet.Exception (x,y))) tosearch;
let searched' = IntPairSet.union searched tosearch in
loop (searched', intpairset_neighbours cave searched'))
in
try
loop (seen, intpairset_neighbours cave seen)
with
| IntPairSet.Exception (x,y) -> (x,y)
| Not_found -> raise Not_found