floodFill :: Position -> TerrainTile -> TerrainMap -> (TerrainMap, [Position])
floodFill start tile tmap =
  let fill [] visited = visited
      fill (pos : rest) visited =
        if Set.member pos visited || ttId (tmapGet tmap pos) /= startId
        then fill rest visited else
          fill (map (pos `plusDir`) cardinalDirections ++ rest)
               (Set.insert pos visited)
      startId = ttId (tmapGet tmap start)
      filled = Set.toList $ fill [start] Set.empty
      cardinalDirections = filter isCardinal allDirections
  in (tmapSet filled tile tmap, filled)
floodFill :: Position -> TerrainTile -> TerrainMap -> (TerrainMap, [Position])
floodFill start tile tmap =
  let fill [] visited = visited
      fill (pos : rest) visited =
        if Set.member pos visited || ttId (tmapGet tmap pos) /= startId
        then fill rest visited else
          fill (map (pos `plusDir`) cardinalDirections ++ rest)
               (Set.insert pos visited)
      startId = ttId (tmapGet tmap start)
      filled = Set.toList $ fill [start] Set.empty
      cardinalDirections = filter isCardinal allDirections
  in (tmapSet filled tile tmap, filled)
floodFill start tile tmap =
  let fill [] visited = visited
      fill (pos : rest) visited =
        if Set.member pos visited || ttId (tmapGet tmap pos) /= startId
        then fill rest visited else
          fill (map (pos `plusDir`) cardinalDirections ++ rest)
               (Set.insert pos visited)
      startId = ttId (tmapGet tmap start)
      filled = Set.toList $ fill [start] Set.empty
      cardinalDirections = filter isCardinal allDirections
  in (tmapSet filled tile tmap, filled)