-- collect all unique vertices from graph
vertices :: Graph -> Vertex -> S.Set Vertex
vertices graph start = execState (visitFrom start) S.empty
  where
    visitFrom start' =
      forM_ (graph start') $ \neighbour ->
        get >>= \v -> unless (neighbour `S.member` v) $ modify (S.insert neighbour) >> visitFrom neighbour

-- path to a goal position
vertices :: Graph -> Vertex -> S.Set Vertex
vertices graph start = execState (visitFrom start) S.empty
  where
    visitFrom start' =
      forM_ (graph start') $ \neighbour ->
        get >>= \v -> unless (neighbour `S.member` v) $ modify (S.insert neighbour) >> visitFrom neighbour

-- path to a goal position
vertices graph start = execState (visitFrom start) S.empty
  where
    visitFrom start' =
      forM_ (graph start') $ \neighbour ->
        get >>= \v -> unless (neighbour `S.member` v) $ modify (S.insert neighbour) >> visitFrom neighbour

-- path to a goal position