From 8ac4194b0cf084ed48058c2e0a56717529755ddb Mon Sep 17 00:00:00 2001 From: Daniel Liu Date: Sun, 2 May 2021 14:00:55 -0400 Subject: [PATCH] randomized water a bit --- Sim.hs | 10 ++++++++-- samples/blocks | 43 +++++++++++++++++++++---------------------- samples/ekitai | 9 --------- 3 files changed, 29 insertions(+), 33 deletions(-) delete mode 100644 samples/ekitai 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] diff --git a/samples/blocks b/samples/blocks index 0ad9644..74ae5fb 100644 --- a/samples/blocks +++ b/samples/blocks @@ -1,30 +1,29 @@ - #~~~~~~~~~~~~~~~~~~@@~~~~~~~~~~~~~~~~~~# - #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~# - #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~# +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~@@~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - ###### - ###### - ###### - - ###### ###### - ###### ###### - ###### ###### - - ###### ###### ###### - ###### ###### ###### - ###### ###### ###### - - ###### ###### ###### ###### - ###### ###### ###### ###### - ###### ###### ###### ###### - - + ###### + ###### + ###### + + ###### ###### + ###### ###### + ###### ###### + + ###### ###### ###### + ###### ###### ###### + ###### ###### ###### + + ###### ###### ###### ###### + ###### ###### ###### ###### + ###### ###### ###### ###### + + -############################################################### +################################################################ diff --git a/samples/ekitai b/samples/ekitai deleted file mode 100644 index 1041334..0000000 --- a/samples/ekitai +++ /dev/null @@ -1,9 +0,0 @@ - ~~~~~~~ ~~  ~~ ~~ ~~~~~~~~  ~~~~~  ~~  - ~~      ~~  ~~  ~~    ~~    ~~   ~~ ~~  - ~~~~~  ~~~~~   ~~  ~~  ~~~~~~~ ~~  - ~~     ~~  ~~  ~~  ~~  ~~   ~~ ~~  - ~~~~~~~ ~~  ~~ ~~  ~~  ~~  ~~ ~~  - - - -####################################################### -- 2.20.1