let rec connected cave seen =
let rec loop seen =
let seen' = (IntPairSet.filter
(fun (x,y) -> get cave x y != WALL)
(intpairset_neighbours cave seen)) in
if IntPairSet.is_empty seen'
then seen
else loop (IntPairSet.union seen seen')
in
loop seen