+ (\q -> 0 <= (fst q)+x && (fst q)+x < w && 0 <= (snd q)+y && (snd q)+y < h)
+ [(a,b) | a <- [-1..1], b <- [-1..1], not (a==0 && b==0)]
+
+simToString :: Simulation -> [Char]
+simToString sim@Simulation{simW=w} =
+ let simStr = V.toList $ V.map chunkToChar $ simSpace sim
+ in insert w '\n' simStr
+
+-- from https://stackoverflow.com/questions/12659562/insert-specific-element-y-after-every-n-elements-in-a-list
+insert :: Int -> a -> [a] -> [a]
+insert n y xs = countdown n xs where
+ countdown 0 xs = y:countdown n xs
+ countdown _ [] = []
+ countdown m (x:xs) = x:countdown (m-1) xs
+
+stringToSim :: Int -> Int -> [Char] -> Simulation
+stringToSim w h st =
+ _stringToSim st [(x, y) | x <- [0..w-1], y <- [0..h-1]] (initSimSpace w h)
+_stringToSim st grid acc =
+ if null grid || null st then acc
+ else _stringToSim (tail st) (tail grid) next
+ where x = fst $ head grid
+ y = snd $ head grid
+ next = simSet acc (charToChunk $ head st) x y
+
+-- maps each chunktype to an ascii character
+chunkToChar :: ChunkData -> Char
+chunkToChar c =
+ case chunkType c of
+ Water -> '~'
+ Air -> '.'
+ Wall -> '#'
+ _ -> '?'
+
+-- this is redundant, fix this somehow
+charToChunk :: Char -> ChunkData
+charToChunk c =
+ ChunkData { chunkType=ctype }
+ where ctype = if c=='~' then Water
+ else if c=='#' then Wall
+ else Air