X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=Sim.hs;h=97456fc1ac96517044dba5eb15e45e4a1b32f0e8;hb=73963404db8d4f3ff8b9b768678b87e981e4f745;hp=8f20343c07e31d08cfe5dcb708a602b0f2f64eb6;hpb=259904bfc4ca2f8b90381dfdb887750b9bdaf368;p=ekitaihs.git diff --git a/Sim.hs b/Sim.hs index 8f20343..97456fc 100644 --- a/Sim.hs +++ b/Sim.hs @@ -95,14 +95,20 @@ insert n y xs = countdown n xs where 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 :: [String] -> Simulation +stringToSim strings = + _stringToSim st grid (initSimSpace w h) + where stripped = strings + w = maximum $ [(length s) | s <- stripped] + h = length stripped + grid = [(a,b) | a <- [0..(length stripped)-1], b <- [0..(length $ stripped !! a)-1]] + st = concat stripped + _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 + where y = fst $ head grid -- not exactly sure why y and x got switched here + x = snd $ head grid next = simSet acc (charToChunk $ head st) x y -- maps each chunktype to an ascii character @@ -110,7 +116,7 @@ chunkToChar :: ChunkData -> Char chunkToChar c = case chunkType c of Water -> '~' - Air -> '.' + Air -> ' ' Wall -> '#' _ -> '?'