X-Git-Url: https://git.danieliu.xyz/?p=ekitaihs.git;a=blobdiff_plain;f=Sim.hs;fp=Sim.hs;h=beb3d2ca812834b2f46d9c80fb641966f74e831c;hp=f9e382683320c6849936e9351460114e49c8b1a4;hb=8ac4194b0cf084ed48058c2e0a56717529755ddb;hpb=25cfe33daa0d0eb5ebfe9f8fad5d3a25aa098839 diff --git a/Sim.hs b/Sim.hs index f9e3826..beb3d2c 100644 --- a/Sim.hs +++ b/Sim.hs @@ -8,6 +8,7 @@ module Sim ( import Debug.Trace import Data.Vector ((!), (//)) import qualified Data.Vector as V +import Data.List as L data Simulation = Simulation { simSpace :: V.Vector ChunkData @@ -60,7 +61,7 @@ updateScaffolder x y valid sim directs cond exec = else updateScaffolder x y valid sim (tail directs) cond exec updateWaterChunk x y valid sim = updateScaffolder x y valid sim - [(0,1),(-1,1),(1,1),(-1,0),(1,0)] + ((0,1) : (waterRandom [(-1,1),(1,1),(-1,0),(1,0)] x y)) (\qd -> elem qd valid && fromEnum (simGetChunkType sim ((+) x $ fst qd) ((+) y $ snd qd)) == fromEnum Air @@ -72,6 +73,11 @@ updateWaterChunk x y valid sim = updateScaffolder x y valid sim ((+) y $ snd qd) ) +-- really stupid pure psuedorandom +waterRandom d x y = + let perm = L.permutations d + in perm !! ((x^y+x*y^x+x) `mod` (length perm)) + updatePumpChunk x y valid sim = updateScaffolder x y valid sim [(0,1),(-1,0),(1,0)] (\qd -> @@ -97,7 +103,7 @@ validDirects x y w h = filter simToString :: Simulation -> [Char] simToString sim@Simulation{simW=w} = let simStr = V.toList $ V.map chunkToChar $ simSpace sim - in insert w '\n' simStr + in Sim.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]